跳转至

快速上手

Apifiny Algo is a c++ based cryptocurrency trading library. This document gives you quick information on how to install the SDK, and how to create, build and run your trading applications on top of it.

Note

Apifiny Algo SDK is natively built on Ubuntu 20.04. It can be used on other linux distributions, Windows and MacOS via docker image. Please contact us if you need native implementation on those platforms.

Install Algo SDK via docker (for all operating systems)

Install Algo SDK natively (on Ubuntu 20.04)

  • Download the SDK:

    Download and get license key here

  • Unzip the file:

    tar -zxvf algo_sdk_1.0.0.tar.gz
    

  • SDK contents

    +algo_sdk   
        -bin: libraries and binaries
            -xlibs: directory to place your extension libraries
        -build: directory for the build process
        -include: Apfiny Algo SDK header files
        -examples: 
            -alpha01: extension library example 1
            -alpha02: extension library example 2
            -ccc_executor: trading application example 1
            -ccc_simple_taker: trading application example 2
            -ccc_signal_taker: trading application example 3
    

  • Install dependencies:

    sudo apt update
    sudo apt-get install -y libhiredis-dev libcurl4-openssl-dev libboost-all-dev build-essential premake4 redis python3-pip
    pip3 install pandas numpy tabulate redis
    

    The above installation process should bring up redis server in most machines. If you do not see a running redis server (this may happen in docker environments), you can start it manually:

    nohup /usr/bin/redis-server &
    

Build the example application

The release contains example applications and the premake files used to build them. You can following the steps below to build:

cd algo_sdk/examples/ccc_executor/build_scripts
premake4 gmake
make -j 10 config=release
Binaries will be generated and copied to algo_sdk/bin/.

Run the example application

Apfiny Algo depends on several shared libraries, so you need setup some environment variables first.

Set environment variable ALGO_HOME using the path of your algo_sdk. e.g. /data/cc/algo_sdk:

export ALGO_HOME=YOUR_ALGO_SDK_PATH

Setup other environment variables:

export TZ=UTC
export LD_LIBRARY_PATH=${ALGO_HOME}/bin:$LD_LIBRARY_PATH
export PATH=${ALGO_HOME}/bin:$PATH
You can start the application now. It takes one command line argument, which is the path to a json configuration file.
ccc_executor ${ALGO_HOME}/examples/ccc_executor/cfg/executor_cfg.json

About configuration files

We use json files to configure trading applications. These files contain information about api keys, log path, and strategy components. If you are using the SDK for exchange connectivity only, you may leave most of nodes empty. Otherwise you need create instances of your components and link them together in these json files.

{
    "instance": {
        "license_id":"",
        "license_key":"",
        "log_path": "./ccc_executor_test_01",        
        "name": "ccc_executor_test_01"
    },      
    "servers":{
        "redis_server":"127.0.0.1"                           
    }, 
    "exchanges":[
        {"exchange":"BINANCE_SWAP","trade_type":"Direct","market_data_type":"None"}
    ],
    "apikeys": {
        "BINANCE_SWAP": {
            "key": "enter your api key",
            "secret": "enter your api secert",
            "pass": "enter your api passphrase"
            }       
    },
    "fees": {
        "BINANCE_SWAP": {
            "make": 0.0,
            "take": 0.0002
        }
    },        
    "symbol_info": {
    }, 
    "symbols": [
    ],
    "samplers": [
    ],
    "pricing_models": [
    ],
    "variables": [      
    ],
    "models": [
    ],
    "strategies": [                                 
    ]
}

About Test Net

Algo now supports Binance's Spot test network! For details, please refer to: https://testnet.binance.vision/

An example test network configuration file is at ${ALGO_HOME}/examples/ccc_signal_taker/cfg/signal_taker_cfg_test.json

{
    "instance": {
        "license_id":"TRAIL001",
        "license_key":"apifiny123456",
        "log_path": "./signal_taker_test_01",        
        "name": "signal_taker_test_01"
    },      
    "servers":{
        "redis_server":"127.0.0.1"                           
    }, 
    "exchanges":[
        {"exchange":"BINANCE","trade_type":"Test","market_data_type":"Direct"}
    ],
    "apikeys": {
     "BINANCE": {
        "key": "02SvhZEYG1p92JWdekP75XQKayqfLxmjHWNEfWU1KrCPjJ5xrLcOU1YHZ5SUBVFA",
        "secret": "iKnZvDKMGQuEINhjDX8gbIVJDLl48fV6GFLL5gcFT8Sfj9yxGrnP7uFm7AAVWeFP",
        "pass": ""
        }       
    },
    "fees": {
        "BINANCE": {
            "make": 0.0,
            "take": 0.0002
        }
    },    
    "symbol_info": {
    }, 
    "symbols": [
        {"cid": 1001, "port": ["BTCUSDT", "BINANCE"]}        
    ],
    "samplers": [
    ],
    "pricing_models": [
    ],
    "variables": [
        ["BTCUSDT.BINANCE_trend30", ["TrendVar", {"port": ["BTCUSDT", "BINANCE"], "dur": 1800}]]    
    ],
    "models": [
    ],
    "strategies": [                                 
        ["BTCUSDT.BINANCE", [
            "SignalTakeStrategy", {
                "symbol": "BTCUSDT",
                "trade_market": "BINANCE",
                "order_size": 0.0001,
                "signal": "BTCUSDT.BINANCE_trend30"
            }]]                          
    ]
}

Develop on top of Apfiny Algo SDK

Apfiny Algo is both an application and a library, so you have a few options to use it:

  • Use it as a library and you build trading application on top of it. You write your own main() function and call Apfiny Algo library in this case.
  • Use it as an application and implements components only. Apfiny Algo provides a complete trading application, ccc_fast_trader. The application takes a json configration file as command line argument. You can specify your components in the file to implement trading strategies.
  • A combination of the above two approaches. You develop components, use json file to load them, and implement your own main() functions to add additional functionalities.