roq-okx#
Important
The account must be configured for the “net” position mode (futures and swaps).
Links#
Purpose#
Maintain network connectivity with the OKX 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 AWS, Hong Kong
No test environment
Conda#
$ mamba install \
--channel https://roq-trading.com/conda/stable \
roq-okx
$ cp $CONDA_PREFIX/share/roq-okx/config.toml $CONFIG_FILE_PATH
# Then modify $CONFIG_FILE_PATH to match your specific configuration
$ roq-okx \
--name "okx" \
--config_file "$CONFIG_FILE_PATH" \
--client_listen_address "$UNIX_SOCKET_PATH" \
--service_listen_address "$TCP_LISTEN_PORT" \
--flagfile "$FLAG_FILE"
Config#
Flags#
$ roq-okx --help
|
Number of updates between validating order-book checksum (0 means never validate). |
|
Depth used for L2 subscription. Currently supported values: 5, 50, 400. More details in the comments section. |
|
Required to opt-out from using the real-time feeds when an account has been configured. More details in the comments section. |
|
Trade mode, e.g. “cross”, “isolated” or “cash” |
Environments#
# flagfile
--rest_uri=https://www.okx.com/
--ws_public_uri=wss://ws.okx.com:8443/ws/v5/public
--ws_private_uri=wss://ws.okx.com:8443/ws/v5/private
Market Data#
Event |
Stream |
Messages |
Comments |
---|---|---|---|
MarketData |
instruments |
||
MarketData |
instruments |
||
MarketData |
bbo-tbt |
||
MarketData |
books5, books, books50-l2-tbt, or books-l2-tbt |
||
MarketData |
trades |
||
MarketData |
tickers, index-tickers, funding-rate |
Event |
Stream |
Messages |
Comments |
---|---|---|---|
Statistics#
Type |
Comments |
---|---|
|
(tickers) |
|
(tickers) |
|
(tickers) |
|
(tickers) |
|
(funding-rate) |
|
(funding-rate) |
|
(index-tickers) |
Order Management#
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
orders |
||
Event |
Stream |
Messages |
Comments |
---|---|---|---|
DropCopy |
/api/v5/trade/orders-pending |
||
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
batch-orders |
||
OrderEntry |
batch-amend-orders |
||
OrderEntry |
batch-cancel-orders |
||
OrderEntry |
batch-cancel-orders |
The exchange API does not support this atomically |
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
order, amend-order, cancel-order |
Mapping#
OrderType |
TimeInForce |
ExecutionInstruction |
ordType |
reduceOnly |
|
---|---|---|---|---|---|
|
→ |
|
|
||
|
|
→ |
|
|
|
|
|
|
→ |
|
|
|
|
|
→ |
|
|
|
|
→ |
|
|
|
|
|
→ |
|
|
Account Management#
Event |
Stream |
Messages |
Comments |
---|---|---|---|
Event |
Stream |
Messages |
Comments |
---|---|---|---|
OrderEntry |
/api/spot/v3/accounts |
Streams#
Type |
Comments |
---|---|
REST |
Primary purpose
Each connection
|
Type |
Comments |
---|---|
WebSocket |
Primary purpose
Each connection
|
Type |
Comments |
---|---|
WebSocket |
Primary purpose
Each connection
The first stream is used to
|
Constraints#
Only VIP members can access the L2 tick-by-tick market data feed.
Comments#
TopOfBook is throttled at 100ms (by exchange)
The
index-tickers
andfunding-rate
channels are subscribed for all swaps and futures. This may generate some false subscriptions caused by non-existing channels. Unfortunately, there doesn’t seem to be any way to detect if a symbol has these channels available. The error messages are therefore only logged as warnings.Using the “batch-” version of the order operations due to 5x higher rate limit allowance.
There is no exchange API to support CancelAllOrders. This is therefore implemented by sending batch cancel requests for all known non-finished orders.
There are a number of different “books” channels which can be used as source for MarketByPrice. Some of these require authentication and VIP membership. The gateway will by default choose the most detailed lowest latency feed. This is however not always correct. In particular, the gateway has no knowledge of the VIP membership status. These are the flags you can use to override default behaviour
--ws_books_depth
5 will use the
books5
throttled snapshot feed50 will use the
books50-l2-tbt
realtime incremental feed400 will use either the
books-l2-tbt
realtime incremental feed or thebooks
throttled incremental feed.--ws_books_use_public
is an opt-out flag because the gateway will by default use a realtime feed if an account has been configured.