Skip to content

Start Trade Service

The below workflow shows you how to start trade server and run your strategy. Kindly note that before start trade service, you need to ensure the market service is running properly.

#include <unistd.h>
#include "MarketDataService.h"
#include "ControlService.h"
#include "TradeService.h"
#include "Common.h"
#include "SimpleTakerStrategy.h"
#include "SimpleDataPrinterStrategy.h"
#include "SimpleMakerStrategy.h"

using namespace std;
using namespace aats;


int main(int argc, char **argv)
{

    CControlService control("54.199.162.238",8060);


    int port,pin;   
    control.createTradeServer(port,pin);
    cout << "port: " << port << " pin: " << pin << endl;
    sleep(3);

    CTradeService trade;
    trade.set_marketdata_network(MARKETDATA_SEND_P2P,"54.199.162.238",15031);
    trade.add_md_symbol(1001, "BTCUSDT", "BINANCE");
    trade.add_md_symbol(1002, "ETHUSDT", "BINANCE");

    trade.set_trade_network("54.199.162.238", port, pin);
    trade.config_exchange("BINANCE", "sandbox");

    trade.set_apikey(
        "BINANCE", 
        "02SvhZEYG1p92JWdekP75XQKayqfLxmjHWNEfWU1KrCPjJ5xrLcOU1YHZ5SUBVFA", 
        "iKnZvDKMGQuEINhjDX8gbIVJDLl48fV6GFLL5gcFT8Sfj9yxGrnP7uFm7AAVWeFP", 
        "", "");

    trade.add_trade_symbol(1001, "BTCUSDT", "BINANCE");
    trade.set_fee("BINANCE", 0.0003, 0);

    // // Taker strategy
    // SimpleTakerStrategy *strat = new SimpleTakerStrategy();
    // strat->init(5000);
    // trade.add_strategy(strat);

    // // Data printer strategy
    // SimpleDataPrinterStrategy *strat = new SimpleDataPrinterStrategy();
    // strat->init(1000);
    // trade.add_strategy(strat);

    // Maker strategy
    SimpleMakerStrategy *strat = new SimpleMakerStrategy();
    strat->init();
    trade.add_strategy(strat);

    trade.start();
}