A collection of utility functions to help make life easier when developing strategies

Hierarchy

  • default

Constructors

  • Constructor. Takes no arguments.

    Returns default

Methods

  • Calculates the gain for a given trade

    Parameters

    • trade: {}

      trade to calculate gain for

      • priceField: string = "exitPrice"

        field to use for price, default is exitPrice

      Returns number

    • Calculates the stoploss percent for a given stoploss price and current price

      Parameters

      • stoplossPrice: number

        stoploss price

      • currentPrice: number

        current price

      Returns number

    • Calculates the target percent for a given target price and current price

      Parameters

      • targetPrice: number

        target price

      • currentPrice: number

        current price

      Returns number

    • Capitalize a string - first letter uppercase, rest lowercase

      Parameters

      • string: string

        string to capitalize

      Returns string

    • Splits up an array into chunks of a given size

      Parameters

      • array: []

        array to chunkize

      • chunkSize: number

        size of chunks

      Returns []

    • Converts common representations of true/false to boolean

      Parameters

      • value: any

        value to check

      Returns boolean

    • Counts the number of decimals for a given number

      Parameters

      • number: any

        number to count decimals for

      Returns number

    • Parameters

      • signature: string

      Returns {
          exchangeId: string;
          interval: string;
          symbol: string;
      }

      • exchangeId: string
      • interval: string
      • symbol: string
    • Ensure no gaps (aka missing candles). This method assumes candles supplied in ascending order with UNIX based second timestamps.

      Parameters

      • candles: any

        candles array to ensure no gaps for

      • interval: string

        interval to ensure no gaps for

      • latestCandleTimestamp: number = ...

        latest candle timestamp, default is now

      Returns any

    • Gets the number of candles since a given timestamp

      Parameters

      • timestamp: number

        Unix timestamp (in seconds)

      • interval: string

        interval to use

      Returns number

    • The creation timestamp is embedded in the mongoId

      Parameters

      • _id: ObjectId

        mongoId

      Returns number

      • Unix timestamp (in seconds)
    • Gets the direction for a given trade, returns either "long" or "short"

      Parameters

      • trade: any

        trade to get direction for

      Returns string

    • Gets the interval start timestamp for a given timestamp and timeframe, and returns it as a UNIX timestamp

      Parameters

      • timestamp: number

        timestamp to get interval start for

      • timeframe: string

        timeframe to get interval start for

      Returns number

    • Parameters

      • interval: string
      • candlesCount: number

      Returns number

    • Split up the symbol into base and quote asset

      Parameters

      • symbol: string

        symbol to split up, e.g. BTC/USDT

      Returns {
          baseAsset: string;
          quoteAsset: string;
      }

      • baseAsset: string
      • quoteAsset: string
    • Creates a trade signature from an exchange id, symbol and interval Format: exchangeId_symbol_interval. Use decodeTradeSignature() to decode

      Parameters

      • exchangeId: string

        exchange id

      • symbol: string

        symbol

      • interval: string

        interval

      Returns string

    • Converts an interval to seconds

      Parameters

      • interval: string

        interval to convert

      Returns number

    • Parameters

      • n: any

        number to check

      Returns boolean

    • Rounds a decimal value to a given precision

      Parameters

      • value: number

        value to round

      • precision: number = 0

        precision to use, default is 0, e.g. 2 decimal places

      Returns number

    • Sleep for a given amount of time

      Parameters

      • waitingTime: number

        in milliseconds

      Returns Promise<void>

    • Converts a unix timestamp to a human readable format

      Parameters

      • timestamp: number

        Unix timestamp (in seconds)

      • format: any = "YYYY-MM-DD HH:mm:ss (dddd) UTC"

        format to use for the output, defaults to "YYYY-MM-DD HH:mm:ss (dddd) UTC"

      Returns string