roq-binance-futures

$ conda install \
      --channel https://roq-trading.com/conda/unstable \
      roq-binance-futures
$ conda install \
      --channel https://roq-trading.com/conda/stable \
      roq-binance-futures

Supports

Products

Spot

❌

Futures

✅

Swap

✅

Option

❌

Orders & Quotes
Account

Funds

✅

Position

✅

Note

✅ = Available.

❎ = Not implemented.

❌ = Unavailable.

❶ The exchange protocol does not support streaming updates for reference data and market status.

❷ The PAPI protocol does not support order modifications.

Using

$ roq-binance-futures [FLAGS]

Flags

$ roq-binance-futures --help
--exchange (binance-futures)

Exchange identifier

--api (fapi)

API (fapi or dapi)

--ws_api (true)

Use WebSocket API?

--rest_uri

Exchange end-point

--rest_host

Host (when URI is an IP address)

--rest_pm_uri

Exchange end-point (portfolio margin)

--rest_pm_host

Host (when URI is an IP address)

--rest_proxy

Proxy end-point

--rest_ping_freq (5s)

Ping frequency

--rest_ping_path (/v1/time)

Ping path

--rest_request_timeout (30s)

Request timeout

--rest_listen_key_refresh (1800s)

Listen key refresh period

--rest_order_recv_window (5000ms)

Receive window (please refer to exchange documentation)

--rest_cancel_on_disconnect (false)

Auto-cancel orders on disconnect?

--rest_order_countdown (30s)

Auto-cancel countdown period

--rest_terminate_on_403 (false)

(TEST) Trigger program termination after receiving a 403 response code?

--rest_back_off_delay (300s)

(TEST) Time to wait before retrying a rejected request

--rest_drop_order_update (false)

(TEST) Drop order updates from REST?

--ws_uri

Exchange end-point

--ws_market_uri

Exchange end-point

--ws_user_uri

Exchange end-point

--ws_host

Host (when URI is an IP address)

--ws_pm_uri

Exchange end-point (portfolio margin)

--ws_pm_host

Host (when URI is an IP address)

--ws_ping_freq (5s)

Ping frequency

--ws_max_subscriptions_per_stream (40)

Maximum number of symbols per connection

--ws_subscribe_depth_levels (1000)

Depth levels to subscribe

--ws_subscribe_depth_freq (100ms)

Depth update frequency

--ws_subscribe_trade_details (false)

Should trade summary reports include individual matches?

--ws_mbp_request_delay (10s)

Delay before requesting depth snapshot

--ws_mbp_request_max_retries (0)

Maximum number of retries before giving up

--ws_enable_secondary (false)

Create secondary market data connection?

--ws_trade_lite (false)

Prefer the trade-lite feed (to the order-trade-update feed)?

--ws_mark_price_freq (0s)

MarkPrice frequency (allowed values: 0s or 1s)

--ws_api_network_interfaces

Network interfaces

--ws_api_uri

Exchange end-point

--ws_api_host

Host (when URI is an IP address)

--ws_api_ping_freq (5s)

Ping frequency

--ws_api_allow_order_update (false)

Allow OrderUpdate (with OrderAck)

--mbp_max_depth

Maximum depth

--mbp_sequencer_timeout (120s)

Sequencer timeout

--mbp_allow_price_inversion (false)

Allow price inversion?

--request_limit (8)

Maximum number of requests per interval

--request_limit_interval (5s)

Monitor interval

--encode_buffer_size (1048576)

Encode buffer size

--decode_buffer_size (10485760)

Decode buffer size

--poll_balance_freq (0s)

Polling frequency for balance

--continue_with_unknown_event_type (false)

Continue when receiving updates for unexpected event-types?

--test_alt_funds_update (false)

Test alternative FundsUpdate?

--self_trade_prevention_mode

Self-trade prevention (STP) mode, one of NONE, EXPIRE_MAKER, EXPIRE_TAKER, EXPIRE_BOTH

--subscribe_asset_index (false)

Subscribe asset-index?

--subscribe_force_order (false)

Subscribe force-order?

Environments

$ --flagfile $CONDA_PREFIX/share/roq-binance-futures/flags/prod/flags-fapi.cfg
# flagfile for the roq-binance-futures gateway
# exchange servers are located in AWS, Tokyo, Japan

--api=fapi
--rest_uri=https://fapi.binance.com
--ws_uri=wss://fstream.binance.com/public/ws
--ws_market_uri=wss://fstream.binance.com/market/ws
--ws_user_uri=wss://fstream.binance.com/private/ws
--rest_pm_uri=https://papi.binance.com
--ws_pm_uri=wss://fstream.binance.com/pm/ws
--ws_api_uri=wss://ws-fapi.binance.com/ws-fapi/v1
$ --flagfile $CONDA_PREFIX/share/roq-binance-futures/flags/prod/flags-dapi.cfg
# flagfile for the roq-binance-futures gateway
# exchange servers are located in AWS, Tokyo, Japan

--api=dapi
--rest_uri=https://dapi.binance.com
--ws_uri=wss://dstream.binance.com/ws
--ws_market_uri=wss://dstream.binance.com/market/ws
--ws_user_uri=wss://dstream.binance.com/private/ws
--rest_pm_uri=https://papi.binance.com
--ws_pm_uri=wss://fstream.binance.com/pm/ws
--ws_api_uri=wss://ws-dapi.binance.com/ws-dapi/v1
$ --flagfile $CONDA_PREFIX/share/roq-binance-futures/flags/test/flags-fapi.cfg
# flagfile for the roq-binance-futures gateway
# exchange servers are located in AWS, Tokyo, Japan

--api=fapi
--rest_uri=https://testnet.binancefuture.com
--ws_uri=wss://fstream.binancefuture.com
--rest_pm_uri=TESTNET_DOES_NOT_EXIST
--ws_pm_uri=TESTNET_DOES_NOT_EXIST
--ws_api_uri=wss://testnet.binancefuture.com/ws-fapi/v1
$ --flagfile $CONDA_PREFIX/share/roq-binance-futures/flags/test/flags-dapi.cfg
# flagfile for the roq-binance-futures gateway
# exchange servers are located in AWS, Tokyo, Japan

--api=dapi
--rest_uri=https://testnet.binancefuture.com
--ws_uri=wss://dstream.binancefuture.com/ws
--rest_pm_uri=TESTNET_DOES_NOT_EXIST
--ws_pm_uri=TESTNET_DOES_NOT_EXIST
--ws_api_uri=wss://testnet.binancefuture.com/ws-dapi/v1

Configuration

$ --config_file $CONDA_PREFIX/share/roq-binance-futures/config.toml

Important

This template will be replaced when the software is upgraded. Make a copy and modify to your own needs.

# config template for the roq-binance-futures gateway

symbols = [
  "^BTCUSD[A-Z]?(_[0-9]{6})?$",
  "^ETHUSD[A-Z]?(_[0-9]{6})?$"
]

[accounts]

  [accounts.A1]
  master = true
  login = "YOUR_BINANCE_FUTURES_API_KEY_GOES_HERE"
  secret = "YOUR_BINANCE_FUTURES_SECRET_GOES_HERE"
  symbols = [ ".*" ]

[users]

  [users.test]
  password = "1234"
  symbols = ".*"

  [users.trader]
  password = "secret"
  accounts = [ "A1" ]
  symbols = [ ".*BTC.*", ".*ETH.*" ]

[rate_limits]

  [rate_limits.global]
    type = "ORDER_ACTION"
    aggregate = true
    request_limit = 100
    monitor_period = "10s"
    ban_period = "5m"

Market Data

Inbound

Enum

TRADING

⇒

OPEN

HALT

⇒

HALT

BREAK

⇒

CLOSE

END_OF_DAY

⇒

END_OF_DAY

PRE_TRADING

⇒

PRE_TRADING

AUCTION_MATCH

⇒

PRE_OPEN

POST_TRADING

⇒

CLOSE

SETTLING

⇒

PRE_CLOSE

PENDING_TRADING

⇒

PRE_OPEN

DELIVERING

⇒

UNDEFINED

Event

Field

Comment

MarkPriceUpdate

p

Mark price

⇒

SETTLEMENT_PRICE

MarkPriceUpdate

P

Est. mark price

⇒

PRE_SETTLEMENT_PRICE

MarkPriceUpdate

i

Index price

⇒

INDEX_VALUE

MarkPriceUpdate

r

Funding rate

⇒

FUNDING_RATE

MiniTicker

o

Open price

⇒

OPEN_PRICE

MiniTicker

h

High price

⇒

HIGHEST_TRADED_PRICE

MiniTicker

l

Low price

⇒

LOWEST_TRADED_PRICE

MiniTicker

c

Close price

⇒

CLOSE_PRICE

MiniTicker

v

Total volume (base)

⇒

TRADE_VOLUME

Order Management

Inbound

Enum

MARKET

⇒

MARKET

LIMIT

⇒

LIMIT

Enum

GTC

⇒

GTC

IOC

⇒

IOC

FOK

⇒

FOK

GTX

⇒

GTX

Enum

NEW

⇒

WORKING

PARTIALLY_FILLED

⇒

WORKING

FILLED

⇒

COMPLETED

CANCELED

⇒

CANCELED

EXPIRED

⇒

EXPIRED

NEW_INSURANCE

⇒

UNDEFINED

NEW_ADL

⇒

UNDEFINED

Outbound

order_type

execution_instructions

price

stop_price

type

price

stopPrice

reduceOnly

MARKET

NaN

NaN

⇒

MARKET

❌

❌

MARKET

NaN

✅

⇒

MARKET

❌

✅

LIMIT

✅

NaN

⇒

LIMIT

✅

❌

LIMIT

✅

✅

⇒

LIMIT

✅

✅

TBD

TBD

TBD

Comments

  • 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.

  • 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.

  • PAPI has a race between order matching an trade reporting

    • A modify or cancel request may be rejected with the Order does not exist. text message if the order has already been matched but the completion has not yet been reported.

    • This is indicative that Binance’s implementation has matching engine logic separated from PAPI / trade reporting. The matching engine will not report fills directly, rather it will hand the update off to centralized logic that will udpate and validate portfolio margin.

  • The PARTICIPATE_DO_NOT_INITIATE execution instruction is mapped to Binance’s GTX time in force when Roq’s time in force is GTC

References

Common

GitHub

Exchange