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")    

Metadata

Release files for aats 0.0.4

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.0.4
File Size Uploaded
aats-0.0.4.tar.gz 13.5 kB Details

Built distribution (wheel)

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

Total release size: 27.7 kB

Release files / aats-0.0.4.tar.gz

Download URL aats-0.0.4.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
63d66b17d4d6dc313441f580aaa13726820061f70fd424f03ea0c1c238903403
BLAKE2b-256 checksum
How to use checksums
d98914ccb02b1c8178a2bfbc4ee6c5cf7519576304f03fb0604decf8011ae7f4
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.0.4-py3-none-any.whl

Download URL aats-0.0.4-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
018379007563e6ada9c41120199d1fa6490a3e8e292c5f491d4bd3ce293146a1
BLAKE2b-256 checksum
How to use checksums
666d42ca5fbf9f9a35031279ce97be96a0606aa3f06d6f21285cb65b88bfa171
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

0.1.2

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

This release

0.0.4 This release

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