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.
Links#
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#
Spot |
|
Futures |
✓ |
Options |
Note
Crypto and USDT margined products are NOT supported by the same API.
Reference Data |
✓ |
Market Status |
✓ |
Top of Book |
✓ |
Market by Price (L2) |
✓ |
Market by Order (L3) |
|
Trade Summary |
✓ |
Statistics |
✓ |
Create |
✓ |
Modify |
|
Cancel |
✓ |
Cancel All |
✓ |
Auto Cancellation |
✓ (*) |
Positions |
✓ |
Funds |
✓ |
Data center located in Japan (to be confirmed)
No test environment
Auto-cancel is not possible with PAPI
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
--exchange
(binance-futures
)Exchange identifier (string)
--api
(fapi
)What api to use (fapi, dapi)
--request_limit
(8
)Request limit per interval
--request_limit_interval
(5s
)Request limit monitor interval
--encode_buffer_size
(1048576
)Encode buffer size
--decode_buffer_size
(10485760
)Decode buffer size
--mbp_allow_price_inversion
(false
)Allow price inversion?
--mbp_max_depth
Max depth levels (count)
--mbp_sequencer_timeout
(120s
)MbP sequencer timeout
--continue_with_unknown_event_type
(false
)Continue when getting updates for unknown event-types?
--download_symbols
Comma-separated list of symbols
--download_trades_lookback
(300s
)Download trades lookback period
--download_trades_lookback_on_restart
Download trades lookback period
--download_trades_limit
(1000
)Download trades limit
--rest_uri
(https://testnet.binancefuture.com
)REST end-point (URI)
--rest_host
Host (http header) in case uri uses an IP address
--rest_pm_uri
REST end-point for portfolio margin (URI)
--rest_pm_host
Host (http header) in case uri uses an IP address
--rest_proxy
Proxy end-point (URI)
--rest_ping_freq
(5s
)Ping frequency
--rest_ping_path
(/v1/time
)URI path used for REST connection keep-alive messages (without the api prefix)
--rest_request_timeout
(30s
)Request: timeout
--rest_terminate_on_403
(false
)Terminate when getting a 403 response code
--rest_back_off_delay
(300s
)Time to wait before retrying a rejected request
--rest_listen_key_refresh
(1800s
)Listen key refresh period
--rest_order_countdown
(30s
)Auto-cancel countdown time
--rest_order_recv_window
(5000ms
)Receive window, please refer to Binance documentation!
--rest_cancel_on_disconnect
(false
)Cancel orders on disconnect? (bool)
--ws_uri
(wss://stream.binancefuture.com
)WebSocket end-point (URI)
--ws_host
Host (http header) in case uri uses an IP address
--ws_pm_uri
WebSocket end-point (URI)
--ws_pm_host
Host (http header) in case uri uses an IP address
--ws_ping_freq
(5s
)Ping frequency
--ws_max_subscriptions_per_stream
(40
)Max symbols per connection (count)
--ws_subscribe_depth_levels
(1000
)Depth levels (count)
--ws_subscribe_depth_freq
(100ms
)Depth update frequency
--ws_mbp_request_delay
(10s
)Request delay
--ws_mbp_request_max_retries
(0
)Request max retries
--ws_enable_secondary
(false
)Create secondary market data connection? (bool)
Environments#
$ $CONDA_PREFIX/share/roq-binance-futures/flags
USD-M Futures#
# flagfile for the roq-binance-futures gateway
--api=fapi
--rest_uri=https://fapi.binance.com
--ws_uri=wss://fstream.binance.com/ws
--rest_pm_uri=https://papi.binance.com
--ws_pm_uri=wss://fstream.binance.com/pm/ws
# flagfile for the roq-binance-futures gateway
--api=fapi
--rest_uri=https://testnet.binancefuture.com
--ws_uri=wss://stream.binancefuture.com/ws
COIN-M Futures#
# flagfile for the roq-binance-futures gateway
--api=dapi
--rest_uri=https://dapi.binance.com
--ws_uri=wss://dstream.binance.com/ws
--rest_pm_uri=https://papi.binance.com
--ws_pm_uri=wss://fstream.binance.com/pm/ws
# flagfile for the roq-binance-futures gateway
--api=dapi
--rest_uri=https://testnet.binancefuture.com
--ws_uri=wss://dstream.binancefuture.com/ws
Market Data#
Event |
Stream |
Messages |
Comments |
---|---|---|---|
Unavailable |
|||
Unavailable |
|||
MarketData |
<symbol>@bookTicker |
||
MarketData |
<symbol>@depth@<freq> |
||
Unavailable |
|||
MarketData |
<symbol>@aggTrade |
||
MarketData |
<symbol>@miniTicker, <symbol>@markPrice |
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
GET /fapi/v1/exchangeInfo |
There is no live feed |
|
OrderEntry |
GET /fapi/v1/exchangeInfo |
There is no live feed |
|
OrderEntry |
GET /fapi/v1/depth |
See Flags |
|
Statistics#
Type |
Comments |
---|---|
|
(miniTicker) |
|
(miniTicker) |
|
(miniTicker) |
|
(miniTicker) |
|
(markPrice) |
|
(markPrice) |
|
(markPrice) |
|
(markPrice) |
Order Management#
Event |
Stream |
Messages |
Comments |
---|---|---|---|
DropCopy |
ORDER_TRADE_UPDATE |
||
DropCopy |
ORDER_TRADE_UPDATE |
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
GET /fapi/v1/openOrders |
It is only possible to download open orders |
|
OrderEntry |
GET /fapi/v1/userTrades |
There is a limit of 1000 trades |
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
POST /fapi/v1/order |
||
Unavailable |
|||
OrderEntry |
DELETE /fapi/v1/order |
||
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 |
---|---|---|---|
OrderEntry |
/fapi/v1/order |
Order Types#
Type |
Comments |
---|---|
|
Mapped to |
|
Mapped to |
Time in Force#
Type |
Comments |
---|---|
|
Mapped to |
|
Mapped to |
|
Mapped to |
|
Mapped to |
Position Effect#
Note
Not supported
Execution Instructions#
TBD
Account Management#
Event |
Stream |
Messages |
Comments |
---|---|---|---|
DropCopy |
ACCOUNT_UPDATE |
||
DropCopy |
ACCOUNT_UPDATE |
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
GET /fapi/v2/account |
||
OrderEntry |
GET /fapi/v2/balance |
Streams#
Type |
Comments |
---|---|
REST |
Primary purpose
Each connection
|
Type |
Comments |
---|---|
WebSocket |
Primary purpose
Each connection
|
Type |
Comments |
---|---|
WebSocket |
Primary purpose
Each connection
|
Type |
Comments |
---|---|
REST |
Primary purpose
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 byCreateOrder
) must conform to the^[.A-Z:/a-z0-9_-]{1,36}$
regular expression (ECMAScript). This restricts length and character used when supplying therouting_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.There are different end-points depending on the margin-mode.
If nothing is specified, the classic margin-mode is selected. The end-points are then taken from
--rest_uri
and--ws_uri
.The new end-points are selected if the toml config has
margin_mode = "portfolio"
. The end-points are then taken from--rest_pm_uri
and--ws_pm_uri
.