跳转至

Start Market Server

This document will show you how to start market server to listen subscribed symbols and exchanges.

For different deploy method, the correspond mode should be chosen, P2P is for cloud user, BROADCAST is for docker user, MULTIBROAD is for native user when you setup network configuration.

  • When the transmission type is P2P, the parameters ip and port correspond to the ip address and port that the market data server listens to.

  • When the transmission type is BROADCAST, the parameters ip (255.255.255.255) and port correspond to the broadcast ip and the port of the receiver

  • When the transmission type is MULTIBROAD, the parameters ip (224.0.0.0 to 239.255.255.255) and port correspond to the MULTIBROAD ip and the port of the receiver

Below workflow uses cloud deploy method with P2P transmission as an example.

Click here to run directly

import time
from aats.market_service import MarketService
from aats.market_service import NetWorkType

# maintain your unique cid symbol mapping table which needs to be consistent in both market server and trade server
sym_cid_map = {
    1001: "BTCUSDT.BINANCE",
    1002: "ETHUSDT.BINANCE",
    1003: "DOGEUSDT.BINANCE",
    1004: "BTCUSDTSWAP.BINANCE_SWAP"
    }

# setup control server IP and market data port
control_server_ip = '54.199.162.238'
md_port = 15033

# start market engine
mkt_service = MarketService(sym_cid_map)
mkt_service.set_control_server(ip=control_server_ip, port=8060)  # default setting
mkt_service.set_network_cfg(ip=control_server_ip, port=md_port, send_type=NetWorkType.P2P, netcard_name = '')
mkt_service.add_exchange('BINANCE','Exchange_Setting','bookTicker')
mkt_service.add_listen_symbol('BTCUSDT', 'BINANCE', 5)
mkt_service.add_listen_symbol('ETHUSDT', 'BINANCE', 5)
# mkt_service.open_l2_data()

mkt_service.run()

If the message returns "Failed to start the market data server. Please try another port.", it means the port is occupied and you could try another port between 10000-20000 when you call set_network_cfg function.

If the message returns "require_market_data_state: ok", it means the market server starts successfully and you can start trade server and run your strategy below.