roq-binance

Purpose

  • Maintain network connectivity with the Binance exchange

  • Route exchange updates to connected clients

  • Route client requests to the relevant exchange accounts

  • Stream all messages to an event-log

Overview

Products

Spot

Futures

Options

Market Data

Reference Data

Market Status

Top of Book

Market by Price (L2)

Market by Order (L3)

Trade Summary

Statistics

Order Management

Create

Modify

Cancel

Cancel All

Auto Cancellation

Account Management

Positions

Funds

  • Data center located in Japan (to be confirmed)

  • No test environment

Conda

1conda install \
2  --channel https://roq-trading.com/conda/stable \
3  roq-binance
1cp $CONDA_PREFIX/share/roq-binance/config.toml $CONFIG_FILE_PATH
2
3# Then modify $CONFIG_FILE_PATH to match your specific configuration
1roq-binance \
2      --name "binance" \
3      --config_file "$CONFIG_FILE_PATH" \
4      --client_listen_address "$UNIX_SOCKET_PATH" \
5      --metrics_listen_address "$TCP_LISTEN_PORT" \
6      --flagfile "$FLAG_FILE"

Config

Flags

1roq-binance --help

--rest_uri

URI

--rest_depth_limit

Depth limit. This choice has influence on request limits, please refer to exchange documentation.

--rest_listen_key_refresh

Time between listen key refresh.

--ws_uri

URI

--ws_depth_levels

Max levels for snapshots.

--ws_depth_freq

Conflated depth updates are published at a frequency of either 100ms or 1000ms.

--ws_trade_details

Report individual matches for trade summary?

--ws_max_subscriptions

Subscription limit per web-socket connection

Environments

1# flagfile
2
3--rest_uri=https://api.binance.com
4--ws_uri=wss://stream.binance.com:9443/stream
1# flagfile
2
3--rest_uri=https://api.binance.us
4--ws_uri=wss://stream.binance.us:9443/stream

Market Data

Event

Stream

Messages

Comments

roq::ReferenceData

Unavailable

roq::MarketStatus

Unavailable

roq::TopOfBook

MarketData

<symbol>@bookTicker

roq::MarketByPriceUpdate

MarketData

<symbol>@depth@<freq>

See Flags

roq::MarketByOrderUpdate

Unavailable

roq::TradeSummary

MarketData

<symbol>@trade, <symbol>@aggTrade

See Flags

roq::StatisticsUpdate

MarketData

<symbol>@miniTicker

Event

Stream

Messages

Comments

roq::ReferenceData

OrderEntry

GET /api/v3/exchangeInfo

roq::MarketStatus

OrderEntry

GET /api/v3/exchangeInfo

roq::TopOfBook

roq::MarketByPriceUpdate

OrderEntry

GET /api/v3/depth

See Flags

roq::MarketByOrderUpdate

roq::TradeSummary

roq::StatisticsUpdate

Statistics

Type

Comments

HIGHEST_TRADED_PRICE

(miniTicker) high_price

LOWEST_TRADED_PRICE

(miniTicker) low_price

OPEN_PRICE

(miniTicker) open_price

CLOSE_PRICE

(miniTicker) close_price

Order Management

Event

Stream

Messages

Comments

roq::OrderUpdate

DropCopy

executionReport

roq::TradeUpdate

DropCopy

executionReport

Event

Stream

Messages

Comments

roq::OrderUpdate

OrderEntry

GET /api/v3/openOrders

It is only possible to download open orders

roq::TradeUpdate

Event

Stream

Messages

Comments

roq::CreateOrder

OrderEntry

POST /api/v3/order

roq::ModifyOrder

Unavailable

roq::CancelOrder

OrderEntry

DELETE /api/v3/order

roq::CancelAllOrders

OrderEntry

DELETE /api/v3/openOrders

This request is per-symbol! Only executed for those symbols where the gateway has seen order actions or download.

Event

Stream

Messages

Comments

roq::OrderAck

OrderEntry

/api/v3/order

Order Types

Type

Comments

MARKET

Mapped to 'MARKET' (JSON)

LIMIT

Mapped to 'LIMIT' (JSON)

Time in Force

Type

Comments

GTC

Mapped to 'GTC' (JSON)

IOC

Mapped to 'IOC' (JSON)

FOK

Mapped to 'FOK' (JSON)

Position Effect

Note

Not supported

Execution Instructions

TBD

Account Management

Event

Stream

Messages

Comments

roq::PositionUpdate

Unavailable

roq::FundsUpdate

DropCopy

outboundAccountInfo, outboundAccountPosition

Event

Stream

Messages

Comments

roq::PositionUpdate

Unavailable

roq::FundsUpdate

OrderEntry

GET /api/v3/account

Streams

Type

Comments

REST

Primary purpose

  • support order management

Each connection

  • supports a single account

  • maintains a listen key (used by the DropCopy stream)

Type

Comments

WebSocket

Primary purpose

  • live account updates, including orders and fills

Each connection

  • supports a single account

Type

Comments

WebSocket

Primary purpose

  • live market data

Each connection

  • supports a slice of the symbols

Type

Comments

REST

Primary purpose

  • download reference data

One connection

Constraints

  • It is only possible to download current order status for open orders. The implication is that backup procedures must be implemented to reoncile positions in the scenario where orders are completely filled during a disconnect.

  • The newClientOrderId field (used by CreateOrder) must conform to the ^[\.A-Z\:/a-z0-9_-]{1,36}$ regular expression (ECMAScript). This restricts length and character used when supplying the routing_id field.

  • The exchange will monitor rate-limit usage per IP address.

  • Rate-limit usage is quite strict when downloading full order books. Due to this constraint, it may take a very long time to initialize all symbols. It is therefore STRONGLY recommended to reduce the configured number of symbols, e.g. symbols=".*BTC.*", or even more specific by using lists.

Comments

  • It is possible to see gateway warnings about dropped messages caused by order status reversal, e.g. seeing WORKING after COMPLETED. This is partly due to REST vs WebSocket and partly due to exchange publishing both NEW and FILLED order update messages for taker orders.

  • The online documentation has a note about rejected messages never ping pushed into the user data stream. This effectively means that there’s the risk that you will have to wait for the gateway to detect timeout if the REST connection is disconnected right after an order request has been sent.