Skip to main content

Available methods and modules

In a custom strategy, you can place or cancel orders and fetch additional OHLCV data using various methods. These methods can be called as functions without waiting for a return value. Alternatively, you can wait for the Promise to resolve when calling a method. This allows you to create a promise chain using the then() method.

The require module allow you to use additional javascript modules, like those freely available on NPM. With tulind you can easily calculate your own indicator values.

Overview of all common methods and built-in modules

MethodReturnsExtra info
gb.method.buyMarket(amount, pair, exchange)PromisePlaces a market buy order, amount in quote. Exchange is optional.
gb.method.sellMarket(amount, pair, exchange)PromisePlaces a market sell order, amount in quote. Exchange is optional.
gb.method.buyLimit(amount, price, pair, exchange)PromisePlaces a limit buy order, amount in quote. Exchange is optional.
gb.method.sellLimit(amount, price, pair, exchange)PromisePlaces a limit sell order, amount in quote
gb.method.buyLimitPostOnly(amount, price, pair, exchange)PromisePlaces a limit buy order, amount in quote
gb.method.sellLimitPostOnly(amount, price, pair, exchange)PromisePlaces a limit sell order, amount in quote
gb.method.closeMarket(pair, amount, exchange)PromisePlaces a market close order, for futures. Amount in quote.
gb.method.closeLimit(price, pair, amount, exchange)Promise

Places a limit close order, for futures.

Amount in quote.

gb.method.cancelOrder(orderId, pair, exchange)PromiseCancels a specified open order. It is discouraged to await the promise for this method to resolve, because it can take a very long time before the exchange confirms a cancellation.
gb.method.getLedger(pair, exchange)Object

Get pair state for other pairs

Use this to retrieve Gunbot pair state data from other active trading pairs, the returned is largely the same as what you'd find in pair state json files.

gb.method.getCandles(interval, period, pair, exchange)Promise

Get additional OHLCV data.

Easiest to call using await, see usage example in the example strategies.

Beware: frequent usage can quickly lead to exceeding exchange API rate limits.

gb.method.getTrend(pair, exchange, version)Promise

Returns an object with the same trend data as used in stepgridhybrid/stepgridhedge. Can only be called for pairs actively cycling.

Calling this method leads to significant additional API usage, because candle data in 15m, 1h and 4h timeframes gets requested. Trend and candle data additionally gets stored to Gunbot pair state.

The version prop is optional and defaults to v2, using v3 returns the same trend data as the stepgridscalp strategy uses. To use this, define the timeframes for analysis with PERIOD (or alternatively PERIOD_SHORT), PERIOD_MEDIUM and PERIOD_LONG

gb.method.setTimeScaleMark(pair, exchange, message)Mark on chart

Timescale marks are the marks on the chart x axis, that by default show details for filled orders. With this method you can display any string in a mark on a specific bar.

When multiple messages get stored for the same candle, they will be shown together in one mark. Timestamp is set automatically, no need to include it in the message text.

gb.method.tulind [#parameters#]array

Get 100+ different indicators. You can use the available OHLCV data, or use your own inputs.

See the example strategies for a usage example.

gunbot.method.require(module)function

Bring your own modules using require.

See the example strategies for a usage example.

To use an external module, first place it in a folder called 'user_modules' in the Gunbot root folder. Then require it in your strategy code, like this:

On Linux (and likely macOS): const cryptopanic = gb.method.require(gb.modulesPath + '/cryptopanic')

On Windows:
const cryptopanic = gb.method.require(gb.modulesPath + '\cryptopanic')

The above assumes you have a module in a folder called cryptopanic in the user_modules folder. gb.modulesPath returns the path to whereever your gunbot folder is on your filesystem.

An example of a chart timescale mark, which you can set with gb.method.setTimeScaleMark()

Methods specific for Binance / Binance Futures / Mex Gunthy / Futures Gunthy

STOP_LOSS_Buy

  • Syntax: STOP_LOSS_Buy(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Places a stop-loss buy order. The order is executed when the market price reaches the stop price.

STOP_LOSS_LIMIT_Buy

  • Syntax: STOP_LOSS_LIMIT_Buy(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Places a stop-loss limit buy order. This order sets a limit on the maximum possible loss by specifying a stop price at which the order triggers.

TAKE_PROFIT_Buy

  • Syntax: TAKE_PROFIT_Buy(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Executes a take-profit buy order. The order is fulfilled when a specified profit level is reached.

TAKE_PROFIT_LIMIT_Buy

  • Syntax: TAKE_PROFIT_LIMIT_Buy(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Places a take-profit limit buy order. It allows setting a profit target and limits the order execution to when the price reaches the target.

TRAILING_STOP_MARKET_Buy

  • Syntax: TRAILING_STOP_MARKET_Buy(symbol, volume, price, callbackRate, userExchange, activationPrice)
  • Returns: Promise
  • Description: Sets a trailing stop-market buy order. This order type allows for dynamic adjustment of stop price based on market movements.

STOP_LOSS_Sell

  • Syntax: STOP_LOSS_Sell(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Places a stop-loss sell order. The order triggers a sell when the market price drops to the stop price.

STOP_LOSS_LIMIT_Sell

  • Syntax: STOP_LOSS_LIMIT_Sell(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Executes a stop-loss limit sell order. It sets a stop price to limit potential losses on a position.

TAKE_PROFIT_Sell

  • Syntax: TAKE_PROFIT_Sell(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Places a take-profit sell order. This order aims to secure profits by selling when the price reaches a predetermined level.

TAKE_PROFIT_LIMIT_Sell

  • Syntax: TAKE_PROFIT_LIMIT_Sell(symbol, volume, price, stopPrice, userExchange)
  • Returns: Promise
  • Description: Sets a take-profit limit sell order. It allows for specifying a profit target for a sell order and limits the execution to the target price.

TRAILING_STOP_MARKET_Sell

  • Syntax: TRAILING_STOP_MARKET_Sell(symbol, volume, price, callbackRate, userExchange, activationPrice)
  • Returns: Promise
  • Description: Places a trailing stop-market sell order. This order adjusts the stop price dynamically based on market conditions.

createOCOBuyOrder

  • Syntax: createOCOBuyOrder(symbol, volume, price, stopPrice, tpPrice, userExchange)
  • Returns: Promise
  • Description: Creates an OCO (One-Cancels-the-Other) buy order. It combines a stop-loss order with a take-profit order.

createOCOSellOrder

  • Syntax: createOCOSellOrder(symbol, volume, price, stopPrice, tpPrice, userExchange)
  • Returns: Promise
  • Description: Executes an OCO sell order. This method combines a stop-loss order with a take-profit order in a sell operation.