Let’s get you started with the Bot SDK. Our SDK consists of a set of classes & functions that allow you to build trading signals via code. It’s designed to be easy to use and flexible, so you can create bots that suit your trading style.
What you need
- Basic knowledge of programming. Almost any programming language will do to get started with our SDK. If you understand PHP, C#, JavaScript or similar, you’re good to go.
- A code editor or your choice. We recommend Visual Studio Code, IntelliJ IDEA or Sublime Text. But also Notepad++ will do.
- Our Bot SDK. You can download it here.
What you can code
Buy / Sell signals
Here’s an example of a barebone buy/sell signal. Please refer to the other sections of the SDK documentation for more information on how to extend the class and use the various features of the SDK.
The getSignalInfo function is the most important function in your signal. It’s called based on the frequency you set in the bot configuration and is responsible for generating buy/sell signals.
It also offers you access to realtime OHLCV data and other utility classes/functions to help you define your signal.
class BuySellSignalExample extends UserTradeSignalBase
{
protected function init(?ParamValues $params = null)
{
// initialize utility signals/classes here
}
protected function registerParams()
{
parent::registerParams();
// register your parameters here (see "Parameters" section)
}
public function getId():string
{
return "BuySellSignalExample";
}
public function getName():string
{
return "BuySellSignalExample";
}
function getSupportedTradeSides():int
{
return TradeSide::Both; // or TradeSide::Buy or TradeSide::Sell
}
function getSupportedEnvironments():array
{
return [TradeEnvironment::Test]; // and/or [TradeEnvironment::Live]
}
function getSignalInfo(TradeContext $tradeContext):TradeSignalInfo
{
// implement your signal strategy here
// return a TradeSignalInfo object if you want to trade
if (iWantToTrade)
{
// pass the strength of the signal. everything >= 1 is considered a valid signal and will trigger a trade. you can also pass values below 1 to indicate a weaker signal that you could use in combination with other signals
// pass any metadata you want to store with the trade
return new TradeSignalInfo(1, ["myMetaKey1" => "myMetaValue1", ...]);
}
return null; // return null if no signal
}
}
Investment strategies
Investment strategies are different from buy/sell strategies in that they don’t generate buy/sell signals. Instead, they define the trade order information (i.e. how much to invest in a particular asset, what order type [Market, Limit, StopLoss etc.]) based on the buy/sell strategies.
Here’s an example of a barebone investment strategy. Please refer to the other sections of the SDK documentation for more information on how to extend the class and use the various features of the SDK.
class InvestmentStrategyExample extends UserInvestmentStrategyBase
{
protected function init(?ParamValues $params = null)
{
// initialize class parameters here
}
protected function registerParams()
{
parent::registerParams();
// register your parameters here (see "Parameters" section)
}
public function getId():string
{
return "InvestmentStrategyExample";
}
public function getName():string
{
return "InvestmentStrategyExample";
}
// This function is called when a a new buy signal is generated. It can be used to decide if we should sell or not
public function getStartTradeOrder(TradeContext $tradeContext, ITradeStrategy $startStrategy, TradeStrategyTradeInfo $tradeInfo):TradeOrder
{
// do something with the data from tradeContext, startStrategy and tradeInfo to decide what to do
// as an example, we will create a market order
$marketOrder = new TradeMarketOrder();
$marketOrder->marketAssetQuantity = 100; // quantity of market asset to buy or sell, depending on the side. If the market asset is USD, this is the amount of USD to buy or sell
$marketOrder->allowedSlippagePercentage = 0.05; // allowed slippage in percentage (0.05 = 5%)
return $marketOrder;
}
// This function is called when a a new sell signal is generated. It can be used to decide if we should sell or not
public function getEndTradeOrder(TradeContext $tradeContext, ITradeStrategy $endStrategy, TradeStrategyTradeInfo $tradeInfo):TradeOrder
{
// do something with the data from tradeContext, endStrategy and tradeInfo to decide what to do
...
}
// This function is called when a pending trade is active (e.g. a limit order). It can be used to cancel the pending trade and enter via market or do something else
public function handlePendingTrade(TradeContext $tradeContext):?HandlePendingTradeInfo
{
$cancelActiveTrade = false;
$enterViaMarket = false;
if (yourCondition)
{
$cancelActiveTrade = true;
$enterViaMarket = true;
return new HandlePendingTradeInfo($cancelActiveTrade, $enterViaMarket);
}
return null;
}
}
Patterns
(Candlestick) Patterns are a set of predefined conditions that need to be met in order to generate a buy/sell signal.
Here’s an example of a barebone pattern.
class PatternExample extends OHLCPatternContent
{
protected function registerParams()
{
parent::registerParams();
// register your parameters here (see "Parameters" section)
}
function getSupportedTradeSides():int
{
return TradeSide::Both; // or TradeSide::Buy or TradeSide::Sell
}
function getSupportedEnvironments():array
{
return [TradeEnvironment::Test]; // and/or [TradeEnvironment::Live]
}
protected function initContent()
{
// define your candle pattern logic here. Use parameters to make it customizable.
// examples:
$this->isBuyCandle(0); // current candle needs to be green
$this->isSellCandle(1); // previous candle needs to be red
$this->checkCandleChangePercentage(0, 10, "close", 0.1, null); // current close > 10% of close 10 candles ago
$this->compareCandles(0, "close", ">", 1, "close"); // current close > previous close
$this->compareCandles(0, "close", "<=", 1, "open"); // current close <= previous open
$this->checkCandlesRange(10, 20, "close", 1000, 1100); // close of candles 10 to 20 candles ago needs to be between 1000 and 1100 (in market price)
// ... and many more functions
}
}
Limitations
Even you use a programming language like PHP or C# to code your bot, there are some limitations you should be aware of:
Due to security restrictions you can only use the most native functions or system classes of the programming language. This means you can’t use any external libraries or APIs or functions that access system resources like files, databases or access the internet.
Internally, once you upload your code to our platform, we will parse it and convert it to our own internal code. All code that is not supported will be discarded and you’ll receive errors which lines of your code are not supported.That means your code will never directly run on our servers. Instead, we will run the converted code in a secure sandbox environment that has no access to the internet or any system resources. This is to ensure the security of our platform and your data.