npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pfalcon/falbit-utils

v0.0.5

Published

TypeScript utils for Falcon Arbitrage Strategy

Downloads

6

Readme

Falbit Utils

Utility functions for universal pure arbitrage strategy using TypeScript. This package supports both order book and amm systems, allowing flexible usage for different types of exchanges.

Installation

Include the SDK in your project by adding it to your dependencies:

npm install --save @pfalcon/falbit-utils

Usage

  1. Pure arbitrage usage
import { ArbitrageEngine } from "@pfalcon/falbit-utils";

// Initialize the engine
const arbEngine = new ArbitrageEngine();

// Initialize exchange connection API (with your options)
const binanceAPI = new BinanceAPI();
const krakenAPI = new KrakenAPI();

// Subscribe to order book and update data on engine
binanceAPI.getOrderBook("BTC_USDT").then((orderBook) => {
  arbEngine.updateOrderBook("BTC_USDT", "binance", orderBook);
});
krakenAPI.getOrderBook("BTC_USDT").then((orderBook) => {
  arbEngine.updateOrderBook("BTC_USDT", "kraken", orderBook);
});

// Interval check arbitrage opportunity
setInterval(() => {
  try {
    const result = arbEngine.calculatePureArb({
      exchange0: "binance",
      exchange1: "kraken",
      token0: "BTC",
      token1: "USDT",
      amountIn: 100,
      fee0: 0,
      fee1: 0,
    });
    console.log("No fee: ", result);
    /*
        Output:
        No fee:  {
            route: {
                route: [ 'USDT', 'BTC', 'USDT' ],
                exchanges: [ '', 'binance', 'kraken'],
                fees: [ 0, 0, 0 ],
                amountIn: 100
            },
            amountsOut: [ 100, 0.0033, 101 ]
        }
    */

    const resultWithFee = arbEngine.calculatePureArb({
      exchange0: "binance",
      exchange1: "kraken",
      token0: "BTC",
      token1: "USDT",
      amountIn: 100,
      fee0: 0.001,
      fee1: 0.001,
    });
    console.log("With fee: ", resultWithFee);
    /*
        Output:
        With fee:  {
            route: {
                route: [ 'USDT', 'BTC', 'USDT' ],
                exchanges: [ '', 'kraken', 'binance'],
                fees: [ 0, 0.001, 0.001 ],
                amountIn: 100
            },
            amountsOut: [ 100, 0.0029, 99.97 ]
        }
    */
  } catch (e) {
    console.error(e);
  }
}, 1000);

Important Notes

  1. The symbols used in the engine should conform this format: {BASE}_{QUOTE}, e.g. BTC_USDT, ETH_BTC, etc.
  2. When calculating getAmountOut function, the engine will determine trade direction by considering the symbol format regarding the initilize symbol that is updated in the engine. For example, if the engine is initialized with symbol BTC_USDT, then using getAmountOut('BTC_USDT') means selling BTC to USDT (BTC -> USDT). In contrast, using getAmountOut('USDT_BTC') means buying BTC using USDT (USDT -> BTC).
  3. Order book data must be in this format:
type OrderBook = {
  bids: { size: number, price: number }[];
  asks: { size: number, price: number }[];
}

Support

For issues and feature requests, please open an issue on GitHub.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.