roq-bitmex

Purpose

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

Conda

1
2
3
conda install \
  --channel https://roq-trading.com/conda/stable \
  roq-bitmex
1
2
3
cp $CONDA_PREFIX/share/roq-bitmex/config.toml $CONFIG_FILE_PATH

# Then modify $CONFIG_FILE_PATH to match your specific configuration
1
2
3
4
5
6
roq-bitmex \
      --name "bitmex" \
      --config_file "$CONFIG_FILE_PATH" \
      --client_listen_address "$UNIX_SOCKET_PATH" \
      --metrics_listen_address "$TCP_LISTEN_PORT" \
      --flagfile "$FLAG_FILE"

Flags

1
roq-bitmex --help

--cancel_on_disconnect

The cancelAllAfter WebSocket message can be used to instruct the exchange to automatically cancel all orders if exchange detects a disconnect.

Warning

Do not rely on this feature: we have not been able to verify it works correctly!

--cancel_all_after_secs

Only used when --cancel_on_disconnect is true.

--rest_allow_order_updates

Support fastest possible order updates by including any order response received on the REST connection.

Warning

You may see inconsistent order updates. This is especially true for partial fills and order modifications/cancelations.

Environments

1
2
3
4
# flagfile

--rest_uri=https://www.bitmex.com
--ws_uri=wss://www.bitmex.com/realtime
1
2
3
4
# flagfile

--rest_uri=https://testnet.bitmex.com
--ws_uri=wss://testnet.bitmex.com/realtime

Market Data

Event

Stream

Messages

Comments

roq::ReferenceData

MarketData

instrument

roq::MarketStatus

MarketData

instrument

roq::TopOfBook

MarketData

quote

roq::MarketByPriceUpdate

MarketData

orderBookL2

roq::MarketByOrderUpdate

Unavailable

roq::TradeSummary

MarketData

trade

roq::StatisticsUpdate

MarketData

instrument

Statistics

Type

Comments

SETTLEMENT_PRICE

(instrument) markPrice

OPEN_INTEREST

(instrument) openInterest

PRE_SETTLEMENT_PRICE

(instrument) indicativeSettlePrice

UPPER_LIMIT_PRICE

(instrument) limitUpPrice

LOWER_LIMIT_PRICE

(instrument) limitDownPrice

INDEX_VALUE

(instrument) fairPrice

FUNDING_RATE

(funding) fundingRate

DAILY_FUNDING_RATE

(funding) fundingRateDaily

Order Management

Event

Stream

Messages

Comments

roq::OrderUpdate

DropCopy

execution

roq::TradeUpdate

DropCopy

execution

Event

Stream

Messages

Comments

roq::OrderUpdate

OrderEntry

GET /api/v1/order

roq::TradeUpdate

OrderEntry

GET /api/v1/trade

Event

Stream

Messages

Comments

roq::CreateOrder

OrderEntry

POST /api/v1/order

roq::ModifyOrder

OrderEntry

PUT /api/v1/order

roq::CancelOrder

OrderEntry

DELETE /api/v1/order

roq::CancelAllOrders

OrderEntry

DELETE /api/v1/order/all

Event

Stream

Messages

Comments

roq::OrderAck

OrderEntry

/api/v1/order

Errors, only

Order Types

Type

Comments

MARKET

Mapped to Market (JSON)

LIMIT

Mapped to Limit (JSON)

Time in Force

Type

Comments

GTC

Mapped to GoodTillCancel (JSON)

Position Effect

Note

Not supported

Execution Instructions

Type

Comments

PARTICIPATE_DO_NOT_INITIATE

Mapped to ParticipateDoNotInitiate (JSON)

DO_NOT_INCREASE

Mapped to ReduceOnly (JSON)

Account Management

Event

Stream

Messages

Comments

roq::PositionUpdate

DropCopy

position

roq::FundsUpdate

Unavailable

Event

Stream

Messages

Comments

roq::PositionUpdate

OrderEntry

GET /api/v1/position

roq::FundsUpdate

Unavailable

Streams

Type

Comments

REST

Primary purpose

  • support order management

Each connection

  • supports a single account

Rate-limit avoidance is implemented by

  • not using HTTP pipelining

  • monitoring the following HTTP headers

  • x-ratelimit-limit

  • x-ratelimit-remaining

  • x-ratelimit-reset

  • blocking new requests for --rest_rate_limit_interval_secs seconds after receiving HTTP status 429 (too many requests)

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

A single connection

Constraints

  • The field clOrdID is a string and can not exceed 36 characters

  • It is very hard to guarantee proper sequential processing if we were to allow order acks/updates from REST response as well as either of the two WebSocket channels execution and order. The choice is to prefer the execution channel for normal updates and error response (and timeout) for REST requests. Unfortunately, consistency appears to come at the cost of added latency.

    • Better latency can be enabled by allowing processing of REST response and the order channel. See Flags.

Comments

  • The exchange API’s do not appear particularly suitable for low latency trading:

    • Order action requests must be signed (which is expensive) and then sent over REST

    • REST response (order ack) could be lost possibly leaving the client in a situation where it must trigger timeout logic and/or issue operational alerts

    • Several WebSocket channels are used communicate order state possibly allowing for inconsistent order management by client