roq-okx¶
Important
The account must be configured for the “net” position mode (futures and swaps).
$ mamba install \
--channel https://roq-trading.com/conda/stable \
roq-okx
$ mamba install \
--channel https://roq-trading.com/conda/unstable \
roq-okx
roq-okx
¶
$ roq-okx [FLAGS]
Description¶
roq-okx
is a gateway
Supports¶
Spot |
✓ |
Futures |
✓ |
Options |
✓ |
Combos |
Reference Data |
✓ |
Market Status |
|
Top of Book |
✓ |
Market by Price |
✓ |
Market by Order |
|
Trade Summary |
✓ |
Statistics |
✓ |
Create |
✓ |
Modify |
✓ |
Cancel |
✓ |
Cancel All |
✓ |
Auto-Cancel |
Positions |
✓ |
Funds |
✓ |
Flags¶
$ roq-okx --help
--exchange
(okx
)Exchange identifier
--trade_mode
(cross
)Trade mode (
cross
,isolated
orcash
)--test_margin_currency
TEST Margin currency used when placing new orders
--rest_uri
(https://www.okx.com
)Exchange end-point
--rest_host
Host (when URI is an IP address)
--rest_proxy
Proxy end-point
--rest_ping_freq
(10s
)Ping frequency
--rest_ping_path
(/api/v5/public/time
)Ping path
--rest_request_timeout
(30s
)Request timeout
--ws_public_uri
(wss://ws.okx.com:8443/ws/v5/public
)Exchange end-point
--ws_public_host
Host (when URI is an IP address)
--ws_private_uri
(wss://ws.okx.com:8443/ws/v5/private
)Exchange end-point
--ws_private_host
Host (when URI is an IP address)
--ws_ping_freq
(5s
)Ping frequency
--ws_max_subscriptions_per_stream
(32
)Maximum number of symbols per connection
--ws_books_depth
(400
)Depth defines what ‘books’ channel to subscribe to (some require authentication)
--ws_books_use_public
(false
)Only use publicly available data sources (not requiring VIP membership)?
--ws_disconnect_timeout
(10s
)Disconnect if connection has been silent for this period
--download_trades_lookback
(300s
)Lookback period when downloading trades (following a disconnect)
--download_trades_lookback_on_restart
Lookback period when downloading trades (initial download)
--download_trades_limit
(100
)Maximum number of trades per response (exchange limit)
--mbp_allow_price_inversion
(false
)Allow price inversion?
--request_limit
(80
)Maximum number of requests per interval
--request_limit_interval
(10s
)Monitor interval
--encode_buffer_size
(1048576
)Encode buffer size
--decode_buffer_size
(10485760
)Decode buffer size
--include_bad_subscriptions
(false
)TEST
--test_local_interface
Local interface
Environments¶
$ $CONDA_PREFIX/share/roq-okx/flags/prod/flags.cfg
# flagfile for the roq-okx gateway
# exchange servers are located in Alibaba, Hong Kong, China
--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
$ $CONDA_PREFIX/share/roq-okx/flags/test/flags.cfg
# flagfile for the roq-okx gateway
# exchange servers are located in Alibaba, Hong Kong, China
--rest_uri=https://www.okx.com
--ws_public_uri=wss://wspap.okx.com:8443/ws/v5/public?brokerId=9999
--ws_private_uri=wss://wspap.okx.com:8443/ws/v5/private?brokerId=9999
Configuration¶
$ $CONDA_PREFIX/share/roq-okx/config.toml
Important
The template will be replaced when the software is upgraded. Make a copy and modify to your needs.
symbols = [
"^BTC-USD[A-Z]$", # spot
"^BTC-USD[A-Z]-SWAP$" # swap
]
[accounts]
[accounts.A1]
master = true
login = "YOUR_OKX_API_KEY_GOES_HERE"
password = "YOUR_OKX_PASSPHRASE_GOES_HERE"
secret = "YOUR_OKX_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¶
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.