roq-okx

Important

The account must be configured for the “net” position mode (futures and swaps).

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

Supports

Products

Spot

Futures

Swap

Option

Orders & Quotes
Account

Funds

Position

Note

✅ = Available.

❎ = Not implemented.

❌ = Unavailable.

Using

$ roq-okx [FLAGS]

Flags

$ roq-okx --help
--exchange (okx)

Exchange identifier

--trade_mode (cross)

Trade mode (cross, isolated or cash)

--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_business_uri (wss://ws.okx.com:8443/ws/v5/market)

Exchange end-point

--ws_business_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

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

$ --flagfile $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
--ws_business_uri=wss://ws.okx.com:8443/ws/v5/business
$ --flagfile $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
--ws_public_uri=wss://wspap.okx.com:8443/ws/v5/business

Configuration

$ --config_file $CONDA_PREFIX/share/roq-okx/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-okx gateway

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

Inbound

state

live

OPEN

suspended

HALT

preopen

PRE_OPEN

settlement

UNDEFINED

expired

UNDEFINED

test

UNDEFINED

Event

Field

tickers

open24h

OPEN_PRICE

tickers

high24h

HIGHEST_TRADED_PRICE

tickers

low24h

LOWEST_TRADED_PRICE

tickers

vol24h

TRADE_VOLUME

index-tickers

idxPx

INDEX_VALUE

funding-rate

fundingRate

FUNDING_RATE

funding-rate

nextFundingRate

FUNDING_RATE_PREDICTION

    • LIMIT

    • GTC

    • limit

    • false

    • LIMIT

    • GTC

    • DO_NOT_INCREASE

    • limit

    • true

    • LIMIT

    • GTC

    • PARTICIPATE_DO_NOT_INITIATE

    • post_only

    • false

    • LIMIT

    • FOK

    • fok

    • false

    • LIMIT

    • IOC

    • ioc

    • false

Outbound

order_type

time_in_force

execution_instructions

type

reduceOnly

MARKET

market

false

LIMIT

GTC

limit

false

LIMIT

GTC

DO_NOT_INCREASE

limit

true

LIMIT

GTC

PARTICIPATE_DO_NOT_INITIATE

post_only

false

LIMIT

FOK

fok

false

LIMIT

IOC

ioc

false

TBD

TBD

TBD

Comments

  • Only VIP members can access the L2 tick-by-tick market data feed.

  • TopOfBook is throttled at 100ms (by exchange)

  • The index-tickers and funding-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 feed

      • 50 will use the books50-l2-tbt realtime incremental feed

      • 400 will use either the books-l2-tbt realtime incremental feed or the books 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.

References

Common

Exchange