Initialize the bot state. This is the base class for all bot states, and run on every tick, whenever a State is created.
Trade information represented as a JSON object
System configuration
Database object
Order object
Same as "System configuration (systemConfig)"
Database object. Used to store and retrieve trade information.
Notifications object. Used to send notifications to Telegram, Slack, Discord, etc.
Order object. Used to place and cancel orders.
Contains the concatinated configuration from the config.yml and strategy.yml files
Taapi object. Used to retrieve indicators and other information from the Taapi API.
Trade information represented as a JSON object
Utilities object. Used to perform various utility functions.
Adds a calculation to the bulk construct. As standard, you may add 20 calculations to a construct, but if your plan supports multiple constructs, you can fetch data accross multiple assets pairs / timeframes in one request.
this.addCalculation("rsi", "BTC/USDT", "1h", "rsi_1h"); // Construct 1
this.addCalculation("ema", "BTC/USDT", "1h", "ema_1h", { period: 20 }); // Construct 1
this.addCalculation("macd", "BTC/USDT", "4h", "macd_4h"); // Construct 2
this.addCalculation("ema", "ETH/USDT", "1d", "ema_1d", { period: 200 }, "bybit"); // Construct 3 + Override default exchange
Name of the indicator to calculate. See https://taapi.io/indicators/ for a list of indicators.
Timeframe to calculate the indicator on. A list of available timeframes can be found at https://taapi.io/exchanges/ for your exchange.
Your own unique ID for this calculation. This is used to retrieve the result later.
Parameters to pass to the indicator. Please see the above link for the indicator you're using to see what parameters are available.
Defaults to the symbol of the current trade, but can be overridden, say if you're trading an altcoin but want to compare it to BTC.
Adds a log entry to the trade.
Title of the log entry
Type of the log entry
Data to store with the log entry, defaults to an empty object
Helper function which first records the trade to the historical trades collection, then deletes it from the active trades collection.
If live trading is enabled, this function will check if in a position.
Finish up this function with live trading enabled.
Changes the state of the trade.
The new state to change to. Must be a valid state matching the filename of a state class, ie. State_state-name.js
Whether or not to add a log entry for this state change
Optional message to include in the log entry
Enters a position on the exchange. The order type, slippage, leverage and time in force are all configurable in the config file.
If live trading is disabled, a trade simulation will be performed instead, simply assuming the order was filled at the current price, and all other orders placed succecssfully.
'LONG', 'SHORT', 'BUY' or 'SELL' in any case
The current price of the asset
The price to exit the position at
The stoploss price
Checks if the entry price has been hit.
If live trading is enabled, it will check if the ENTRY order has been FILLED. Otherwise, it will check if the entry price has been hit using the provided candles.
Array of candles in descending order (aka newest first)
Checks if the stoploss price has been hit.
If live trading is enabled, it will check if the STOPLOSS order has been FILLED. Otherwise, it will check if the stoploss price has been hit using the provided candles.
Array of candles in descending order (aka newest first)
Number of candles to ignore from the beginning of the candles array. Sometimes useful with HFT simulations.
Checks if the target price has been hit.
If live trading is enabled, it will check if the TAKE_PROFIT order has been FILLED. Otherwise, it will check if the target price has been hit using the provided candles.
Array of candles in descending order (aka newest first)
Sets the entry details for the trade.
Entry price
Target price
Stoploss price
Direction of the trade (long or short, default: auto)
This class is the base class for all bot states. It contains the most basic functionality that all states need.