跳转至

C++ API for Apifiny Algo Trading System

Apifiny Algo Trading System is a trading library that supports mulitple cryptocurrency exchanges. The core value of AATS is light weight and low latency since the low-level system is optimized and encapsulated by C++, such as exchange connectivity, order book management and order placement. It extremely decreases the learning curve for users. With AATS, users can seamlessly deploy your strategy and ready to live trade without any pain. Below is the introduction of AATS C++ API.

Package structure

At C++ API level, AATS utilizes the event driven framework and consists of the below components:

  • Base Strategy: it is a base strategy class and you can develop your strategy based on it
  • Trade Service: it is the core trading module that is used to load configuration, start trade server and add strategy and start running for live trading
  • Market Service: it is used to start market server and subscribe symbols and exchanges you want to listen
  • Control Service: it is related to server management, such as show running market/trade servers, kill servers and etc

Base Strategy

Once your strategy inherits from base strategy, you can overwrite the below functions/callbacks and add your own logic:

Functions/Callbacks Description
place_order function to send order
cancel_order function to send cancel order
on_book callbacks once orderbook data update
on_trade callbacks once trade data update
on_notify combination of on_book and on_trade
onOrderCreated callbacks once new order created
onOrderAcked callbacks once new order is acknowledged from exchange
onOrderRejected callbacks once new order is rejected from exchange
onOrderCancelCreated callbacks once cancel order created
onOrderCancelAcked callbacks once cancel order is acknowledged from exchange
onOrderCancelRejected callbacks once cancel order is rejected from exchange
onOrderExec callbacks once order is executed (include partially executed) from exchange
onOrderCanceled callbacks once order is canceled from exchange
onOrderClosed callbacks once order is closed from exchange

place_order

place_order needs to construct an order object with the following field:

Field Description Mandatory
exchange exchange you want to trade Yes
symbol symbol you want to trade Yes
price trade price Yes
size trade size Yes
side trade direction Yes
tif order type, currently support IOC and POS Yes

cancel_order

Field Description Mandatory
order_id internal order id Yes

on_book

callbacks once orderbook data update, message contains the below fields:

{
    'type': 'on_book', 
    'cid': 1001, 
    'depth': 5,                    # order book depth level
    'value': LEVEL_BOOK            # level book is a book structure containing px and qty for the each level of bids and asks
    }

on_trade

callbacks once trade data update, message contains the below fields:

{
    'type': 'on_trade', 
    'cid': 1002, 
    'tradeType': 1,    # aggresive trade side, 1 for buy, -1 for sell
    'qty': 0.0249, 
    'px': 1638.93
    }

on_notify

Callbacks once onTrade or onQuote is fired, parameter "type" represents notify type, 1 for book update, 0 for trade update

onOrder**

onOrder callbacks with different order status, message contains the below fields:

{
    "order":{
        "exchange":"BINANCE",
        "fill_notional":"0",
        "fill_price":"19318.88",
        "fill_size":"0.001",
        "margin":false,
        "margin_source":"spot",
        "order_id":1,                     # internal order id
        "price":"19318.88",
        "remote_id":"",                   # exchange order id
        "side":"buy",
        "size":"0.001",
        "symbol":"BTCUSDT",
        "msg":""                         # the order be rejected reson
        },
    "type":"onOrderCreated"               # order status
    }