roq-binance-futures#

Important

There are different network end-points required for USD-M and COIN-M futures. The API’s are different but sufficiently similar to allow this gateway to support both. (The --api flag controls which API will be used.) The implication of this is that you will need more instances of this gateway if you need support for both product groups.

Purpose#

  • Maintain network connectivity with the Binance Futures 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

Note

Crypto and USDT margined products are NOT supported by the same API.

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#

$ mamba install \
  --channel https://roq-trading.com/conda/stable \
  roq-binance-futures
$ cp $CONDA_PREFIX/share/roq-binance-futures/config.toml $CONFIG_FILE_PATH

# Then modify $CONFIG_FILE_PATH to match your specific configuration
$ roq-binance-futures \
      --name "binance-futures" \
      --config_file "$CONFIG_FILE_PATH" \
      --client_listen_address "$UNIX_SOCKET_PATH" \
      --service_listen_address "$TCP_LISTEN_PORT" \
      --flagfile "$FLAG_FILE"

Config#

Flags#

$ roq-binance-futures --help

--api

The API URI name (fapi for USD-M and dapi for COIN-M)

--mbp_max_depth

Max depth. Unbounded is the default.

--continue_with_unknown_event_type

Default is to fail when receiving unknown event-types.

--rest_listen_key_refresh

Time between listen key refresh.

--ws_depth_levels

Max levels for snapshots.

--ws_depth_freq

Select frequency of depth stream: 100ms, 250ms or 500ms

--ws_max_subscriptions

Subscription limit per web-socket connection

--download_symbols

Comma-separated list of symbols to download, e.g. "BTCUSDT,ETHUSDT"

--download_trades_lookback

Downloading trades using lookback period. Optional.

--download_trades_limit

Exchange limit (1000).

Environments#

USD-M Futures#

# flagfile

--api=fapi
--rest_uri=https://fapi.binance.com
--ws_uri=wss://fstream.binance.com/ws
# flagfile

--api=fapi
--rest_uri=https://testnet.binancefuture.com
--ws_uri=wss://stream.binancefuture.com/ws

COIN-M Futures#

# flagfile

--api=dapi
--rest_uri=https://dapi.binance.com
--ws_uri=wss://dstream.binance.com/ws
# flagfile

--api=dapi
--rest_uri=https://testnet.binancefuture.com
--ws_uri=wss://dstream.binancefuture.com/ws

Market Data#

Event

Stream

Messages

Comments

roq::ReferenceData

Unavailable

roq::MarketStatus

Unavailable

roq::TopOfBook

MarketData

<symbol>@bookTicker

roq::MarketByPriceUpdate

MarketData

<symbol>@depth@<freq>

roq::MarketByOrderUpdate

Unavailable

roq::TradeSummary

MarketData

<symbol>@aggTrade

roq::StatisticsUpdate

MarketData

<symbol>@miniTicker, <symbol>@markPrice

Event

Stream

Messages

Comments

roq::ReferenceData

OrderEntry

GET /fapi/v1/exchangeInfo

There is no live feed

roq::MarketStatus

OrderEntry

GET /fapi/v1/exchangeInfo

There is no live feed

roq::TopOfBook

roq::MarketByPriceUpdate

OrderEntry

GET /fapi/v1/depth

See Flags

roq::MarketByOrderUpdate

roq::TradeSummary

roq::StatisticsUpdate

Statistics#

Type

Comments

HIGHEST_TRADED_PRICE

(miniTicker) highPrice

LOWEST_TRADED_PRICE

(miniTicker) lowPrice

OPEN_PRICE

(miniTicker) openPrice

CLOSE_PRICE

(miniTicker) closePrice

SETTLEMENT_PRICE

(markPrice) markPrice

PRE_SETTLEMENT_PRICE

(markPrice) estSettlePrice

INDEX_VALUE

(markPrice) indexPrice

FUNDING_RATE

(markPrice) fundingRate

Order Management#

Event

Stream

Messages

Comments

roq::OrderUpdate

DropCopy

ORDER_TRADE_UPDATE

roq::TradeUpdate

DropCopy

ORDER_TRADE_UPDATE

Event

Stream

Messages

Comments

roq::OrderUpdate

OrderEntry

GET /fapi/v1/openOrders

It is only possible to download open orders

roq::TradeUpdate

OrderEntry

GET /fapi/v1/userTrades

There is a limit of 1000 trades

Event

Stream

Messages

Comments

roq::CreateOrder

OrderEntry

POST /fapi/v1/order

roq::ModifyOrder

Unavailable

roq::CancelOrder

OrderEntry

DELETE /fapi/v1/order

roq::CancelAllOrders

OrderEntry

DELETE /fapi/v1/allOpenOrders

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

/fapi/v1/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)

GTX

Mapped to 'GTX' (JSON)

Position Effect#

Note

Not supported

Execution Instructions#

TBD

Account Management#

Event

Stream

Messages

Comments

roq::PositionUpdate

DropCopy

ACCOUNT_UPDATE

roq::FundsUpdate

DropCopy

ACCOUNT_UPDATE

Event

Stream

Messages

Comments

roq::PositionUpdate

OrderEntry

GET /fapi/v2/account

roq::FundsUpdate

OrderEntry

GET /fapi/v2/balance

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#

  • External trades can optionally be captured into the event log.

    Note

    These messages will not be routed to any client.

  • Trades can optionally be downloaded. This is a very expensive operation and the list of symbols to download must therefore be explicitly controlled by the --download_symbols flag.