Skip to main content

Apifiny Algo Trading System

AATS is a light weight trading system with low-latency and high-scalability for Live trading on multi-crypto exchanges.

Key Features

  • Light weight: you only need to take care of your strategy component and you can trade alive!
  • Low latency: the low-level system is optimizied by C++, such as exchange connectivity, order book management and order placement
  • High flexibility: with raw tick data and quote data, you can freely build samplers, pricing models, variables and signals on your own into your strategy
  • Distributed broadcast: You can only start one market instance and connect to multiple trading instances

Quick Start

This quick start gives you all the steps that you need to do before start trading.

Install docker

Please download and install Docker CE or Docker Desktop for your computer/server if it isn't installed:

Get and run the Algo SDK docker image using the following command:

docker run -it apifinyalgo/algo-sdk:1.1.0

his step will automatically run control server which will be used to start market/trading instance later. Depending on system, you may need to run this with sudo.

TBA: how to check if it is running, i.e. ps command

Install aats package

# install stable version from pip (support python version >=3.7)
pip install aats (TBA: currently pip install -i https://test.pypi.org/simple/ aats)

# clone the repository with latest version
git clone http://git.ddesk.io/exone-plus/algo-client-api.git (TBA: replace with public repo link)

Maintain your unique cid symbol mapping table

It requires to be consistent in both market engine and trade engine

sym_cid_map = {
    1001: "BTCUSDT.BINANCE",
    1002: "ETHUSDT.BINANCE",
    1003: "DOGEUSDT.BINANCE",
    1004: "BTCUSDTSWAP.BINANCE_SWAP"
    }

Start market instance to listen subscribed symbols and exchanges

TBA: change the below to one command line to start market instance

from aats.market_engine import MarketEngine

# start market engine
mkt_engine = MarketEngine(sym_cid_map)
mkt_engine.set_control_server(6000)  # default control server port
mkt_engine.set_multicast_cfg('239.0.0.4', 4141)
# mkt_engine.add_listen_symbol('BTCUSDT', 'BINANCE', 5)
# mkt_engine.add_listen_symbol('ETHUSDT', 'BINANCE', 5)
mkt_engine.add_listen_symbol('DOGEUSDT', 'BINANCE', 5)
mkt_engine.add_listen_symbol('BTCUSDTSWAP', 'BINANCE_SWAP', 5)
mkt_engine.run()

Once console returns the following message, it means market instance is running successfully

{'result': 'ok', 'type': 'market_instance'}

Write your strategy and ready to trade

In the examples folder, we provide two sample strategies and demo_main.py script which illustrates how to setup config and run strategy

  • SimpleTakerStrategy: it is a naive taker strategy, place order on a fixed time interval
  • SimpleMakerStrategy: it is a bit complicated maker strategy with order management system
##############################################
#               Demo strategy                #
##############################################
import time
from aats.trade_engine import TradeEngine
from simple_maker_strategy import SimpleMakerStrategy
from simple_taker_strategy import SimpleTakerStrategy



sym_cid_map = {
    1001: "BTCUSDT.BINANCE",
    1002: "DOGEUSDT.BINANCE"
    }

# init trade engine
trade_engine = TradeEngine(sym_cid_map)

# setup public config
trade_engine.set_md_multicast_cfg(send_to_ip='239.0.0.3', send_to_port=4141)
trade_engine.add_md_symbol(symbol='BTCUSDT', exchange='BINANCE')
# trade_engine.add_md_symbol(symbol='DOGEUSDT', exchange='BINANCE')

# setup private config
trade_engine.set_control_server(server_port=6000)
trade_engine.config_exchange(exchange='BINANCE', trade_type='sandbox')
trade_engine.set_apikey(exchange="BINANCE", 
                        key="02SvhZEYG1p92JWdekP75XQKayqfLxmjHWNEfWU1KrCPjJ5xrLcOU1YHZ5SUBVFA", 
                        secret="iKnZvDKMGQuEINhjDX8gbIVJDLl48fV6GFLL5gcFT8Sfj9yxGrnP7uFm7AAVWeFP", 
                        password="",
                        subaccount="")
trade_engine.set_fee('BINANCE', 0.0003, 0)
trade_engine.add_trade_symbol(symbol='BTCUSDT', exchange='BINANCE')

# setup your strategy
# my_strategy = SimpleMakerStrategy()
my_strategy = SimpleTakerStrategy(msecs=10000)
trade_engine.add_strategy(my_strategy)

# start run
try:
    trade_engine.run()
except KeyboardInterrupt as err:
    # trade_engine.stop()
    print("close strategy and close open orders")
    # trade_engine.manager.stop()
    my_strategy.close()
    time.sleep(1)
    print("trade closed")    

Release files for aats 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aats 0.1.2
File Size Uploaded
aats-0.1.2.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aats 0.1.2
File Interpreter ABI Platform
aats-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 28.8 kB

Release files / aats-0.1.2.tar.gz

Download URL aats-0.1.2.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c8f9b8a26b0474f4a1a092cbdca80d8f369c2b249ffe02a33d1df1cccc373c90
BLAKE2b-256 checksum
How to use checksums
d90eedae502bae8a721340a19984eb238a07236bde5416cb4d64e18a4d505213
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release files / aats-0.1.2-py3-none-any.whl

Download URL aats-0.1.2-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8ed253f0a7cad398a6be791f598b41d235ca418d52d551619cebfb2e9076305
BLAKE2b-256 checksum
How to use checksums
c68f12b5c97f6ca25808c6e7bedfe3e39c55cbe37da0176c5be961f18784e660
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page