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#
Spot |
✓ |
Futures |
✓ |
Options |
✓ |
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 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
--exchange
(okx
)Exchange identifier (string)
--test_margin_currency
Testing
--request_limit
(80
)Request limit per interval
--request_limit_interval
(10s
)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?
--include_bad_subscriptions
(false
)TEST
--trade_mode
(cross
)Trade mode (string)
--download_trades_lookback
(300s
)Download trades lookback period
--download_trades_lookback_on_restart
Download trades lookback period
--download_trades_limit
(100
)Exchange limit
--rest_uri
(https://www.okx.com
)REST end-point (URI)
--rest_host
Host (http header) in case uri uses an IP address
--rest_proxy
Proxy end-point (URI)
--rest_ping_freq
(10s
)Ping frequency
--rest_ping_path
(/api/v5/public/time
)URI path used for REST connection keep-alive messages
--rest_request_timeout
(30s
)Request: timeout
--ws_public_uri
(wss://ws.okx.com:8443/ws/v5/public
)WS end-point (URI)
--ws_public_host
Host (http header) in case uri uses an IP address
--ws_private_uri
(wss://ws.okx.com:8443/ws/v5/private
)WS end-point (URI)
--ws_private_host
Host (http header) in case uri uses an IP address
--ws_ping_freq
(5s
)Ping frequency
--ws_max_subscriptions_per_stream
(32
)Max symbols per connection (count)
--ws_books_depth
(400
)Defines what ‘books’ channel to subscribe to (some require authentication)
--ws_books_use_public
(false
)Opt-out from the real-time feeds requiring VIP membership
--ws_disconnect_timeout
(10s
)Disconnect timeout
Environments#
$ $CONDA_PREFIX/share/roq-oks/flags
# flagfile for the roq-okx gateway
--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.