roq-kucoin#

Supports#

Products

Spot

Futures

Options

Combos

Market Data

Reference Data

Market Status

Top of Book

Market by Price

Market by Order

Trade Summary

Statistics

Order Management

Create

Modify

Cancel

Cancel All

Auto-Cancel

Account Management

Positions

Funds

Installing#

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

Using#

$ roq-kucoin \
      --name "kucoin" \
      --config_file $CONFIG_FILE_PATH \
      --client_listen_address $UNIX_SOCKET_PATH \
      --flagfile $ENVIRONMENT_FLAGFILE

Flags#

$ roq-kucoin --help
--exchange (kucoin)

Exchange identifier

--rest_uri (https://openapi-sandbox.kucoin.com)

Exchange end-point

--rest_proxy

Proxy end-point

--rest_ping_freq (5s)

Ping frequency

--rest_ping_path (/api/v1/status)

Ping path

--rest_request_timeout (30s)

Request timeout

--rest_download_delay (333ms)

Download throttling

--rest_download_orders_page_size (500)

Page size used when downloading orders

--rest_download_orders_begin (24h)

Download orders since (now - begin)

--rest_download_orders_inactive (false)

Download inactive orders?

--rest_download_fills_page_size (500)

Page size used when downloading fills

--rest_download_fills_begin (24h)

download fills since (now - begin)

--rest_token_refresh_freq (8h)

Token refresh frequency

--ws_ping_freq (5s)

Ping frequency

--ws_request_timeout (15s)

Request timeout

--ws_max_subscriptions_per_stream (100)

Maximum number of symbols per connection

--ws_mbp_request_delay (500ms)

Request delay

--ws_mbp_request_max_retries (0)

Request max retries

--mbp_allow_price_inversion (false)

Allow price inversion?

--request_limit (80)

Maximum number of requests per interval

--request_limit_interval (10s)

Monitor interval

--self_trade_prevention (CN)

Self-trade prevention: CN, CO, CB, DC

--encode_buffer_size (1048576)

Encode buffer size

--decode_buffer_size (10485760)

Decode buffer size

Environments#

$ $CONDA_PREFIX/share/roq-kucoin/flags/prod/flags.cfg
# flagfile for the roq-kucoin gateway

--rest_uri=https://api.kucoin.com
$ $CONDA_PREFIX/share/roq-kucoin/flags/test/flags.cfg
# flagfile for the roq-kucoin gateway

--rest_uri=https://openapi-sandbox.kucoin.com

Configuration#

$ $CONDA_PREFIX/share/roq-kucoin/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]$"
  "^ETH-USD[A-Z]$",
]

[accounts]

  [accounts.A1]
  master = true
  login = "YOUR_KUCOIN_API_KEY_GOES_HERE"
  password = "YOUR_KUCOIN_PASSPHRASE_GOES_HERE"
  secret = "YOUR_KUCOIN_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

roq::ReferenceData

roq::MarketStatus

MarketData

/market/snapshot

roq::TopOfBook

MarketData

/market/ticker

roq::MarketByPriceUpdate

MarketData

/market/level2

roq::MarketByOrderUpdate

roq::TradeSummary

MarketData

/market/match

roq::StatisticsUpdate

MarketData

/market/snapshot

Event

Stream

Messages

Comments

roq::ReferenceData

Rest

/api/v1/symbols

roq::MarketStatus

Rest

/api/v1/symbols

roq::TopOfBook

roq::MarketByPriceUpdate

Rest

/api/v3/market/orderbook/level2

roq::MarketByOrderUpdate

roq::TradeSummary

roq::StatisticsUpdate

Statistics#

Type

Comments

OPEN_PRICE

(snapshot) open

HIGHEST_TRADED_PRICE

(instrument) high

LOWEST_TRADED_PRICE

(instrument) low

CLOSE_PRICE

(instrument) close

OPEN_PRICE

(instrument) open

Order Management#

Event

Stream

Messages

Comments

roq::OrderUpdate

DropCopy

/spotMarket/tradeOrders

roq::TradeUpdate

Event

Stream

Messages

Comments

roq::OrderUpdate

roq::TradeUpdate

Event

Stream

Messages

Comments

roq::CreateOrder

OrderEntry

POST /api/v1/orders

roq::ModifyOrder

roq::CancelOrder

OrderEntry

DELETE /api/v1/orders/{order-id}

roq::CancelAllOrders

OrderEntry

DELETE /api/v1/orders

Event

Stream

Messages

Comments

roq::OrderAck

Order Types#

Type

Comments

MARKET

Mapped to market (JSON)

LIMIT

Mapped to limit (JSON)

Time in Force#

Type

Comments

GTC

Mapped to GTC (JSON)

IOC

Mapped to IOC (JSON)

FOK

Mapped to FOK (JSON)

Position Effect#

Note

Not supported

Execution Instructions#

Type

Comments

PARTICIPATE_DO_NOT_INITIATE

Mapped to postOnly (JSON). Requires GTC

Account Management#

Event

Stream

Messages

Comments

roq::PositionUpdate

roq::FundsUpdate

DropCopy

/account/balance

Event

Stream

Messages

Comments

roq::PositionUpdate

roq::FundsUpdate

OrderEntry

GET /api/v1/accounts

Streams#

Type

Comments

REST

Primary purpose

  • download reference data and L2 snapshot

Type

Comments

WebSocket

Primary purpose

  • live market data

  • market status

Each connection

  • supports a slice of the symbols

Type

Comments

REST

Primary purpose

  • download account data

  • order requests

Type

Comments

WebSocket

Primary purpose

  • live account data

  • order updates

  • fills

Constraints#

  • The gateway requires a master account definition (API key) to be functional. The reason is that requesting L2 snapshots will require authentication.

  • The exchange API does not allow order cancelation prior to an ack or update being received by the client. (Other exchanges normally allow cancelation using a client order id.) An roq::OrderAck with roq::Error::UNKNOWN_EXTERNAL_ORDER_ID is the response if a roq::CancelOrder request is sent “too early”.

  • There are no options to instruct the exchange to auto-cancel orders on disconnect.

Comments#

  • There is currently no implementation to refresh the token for the private connection. A received token should be valid for 24 hours and dialy restarts should therefore be planned.

  • The KuCoin sandbox environment does not work with IP restriction. This was confirmed by KuCoin support.