roq-deribit#

Purpose#

  • Maintain network connectivity with the Deribit 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

Conda#

$ mamba install \
  --channel https://roq-trading.com/conda/stable \
  roq-deribit
$ cp $CONDA_PREFIX/share/roq-deribit/config.toml $CONFIG_FILE_PATH

# Then modify $CONFIG_FILE_PATH to match your specific configuration
$ roq-deribit \
      --name "deribit" \
      --config_file "$CONFIG_FILE_PATH" \
      --client_listen_address "$UNIX_SOCKET_PATH" \
      --service_listen_address "$TCP_LISTEN_PORT" \
      --flagfile "$FLAG_FILE"

Config#

Flags#

$ roq-deribit --help
--exchange (deribit)

Exchange identifier (string)

--request_limit (20)

Request limit per interval

--request_limit_interval (1s)

Request limit monitor interval

--encode_buffer_size (1048576)

Encode buffer size

--decode_buffer_size (10485760)

Decode buffer size

--disable_deribit_143 (false)

Disable #143

--disable_master_account_check (false)

Disable requirement for master account

--mbp_allow_price_inversion (true)

Allow price inversion?

--local_interface

Multicast local interface

--download_trades_lookback (300s)

Download trades lookback period

--download_trades_lookback_on_restart

Download trades lookback period

--fix_uri (tcp://test.deribit.com:9881)

FIX end-point (URI)

--fix_ping_freq (5s)

Ping frequency

--fix_request_timeout (15s)

Request timeout

--fix_cancel_on_disconnect (true)

Cancel orders on disconnect? (bool)

--fix_market_data_max_subscriptions_per_stream (256)

Max subscriptions per connection (count)

--fix_market_data_request_max_size (56)

Max batch size (it appears there is a limit)

--fix_market_data_market_depth (20)

Market depth (see deribit documentation)

--fix_debug (false)

Log fix messages?

--fix_continue_from_parse_exception (false)

Continue if message can’t be parsed?

--fix_terminate_on_market_data_request_reject (false)

Terminate if market data request has been rejected?

--fix_test_order_disconnect

TEST disconnect order stream after this period

--fix_test_order_logon

TEST logon order stream after this period

--fix_test_market_data_disconnect

TEST disconnect market data stream after this period

--multicast_address (std::vector<std::string>(239.111.111.1,239.111.111.3))

List of multicast addresses (comma-separated)

--multicast_port_events (6100)

Multicast port used for events

--multicast_port_snapshot (6101)

Multicast port for snapshot

--multicast_disable_top_of_book (false)

Default is to consume TopOfBook from the multicast feed

--multicast_disable_trade_summary (false)

Default is to consume TradeSummary from the multicast feed

--multicast_disable_market_by_price (false)

Default is to consume MarketByPrice from the multicast feed

--multicast_timeout (90s)

Timeout when waiting for snapshot

--ws_uri (wss://test.deribit.com/ws/api/v2)

WebSocket end-point (URI)

--ws_host

Host (http header) in case uri uses an IP address

--ws_ping_freq (5s)

Ping frequency

--ws_request_timeout (15s)

Request timeout

--ws_market_data_max_subscriptions_per_stream (256)

Max subscriptions per connection (count)

--ws_ticker_interval (100ms)

Ticker interval

--ws_allow_errors (false)

Allow errors (debug)

--ws_disable_quote (false)

Disable quote subscription

Environments#

$ $CONDA_PREFIX/share/roq-deribit/flags
# flagfile for the roq-deribit gateway

--fix_uri=tcp://www.deribit.com:9881
--ws_uri=wss://www.deribit.com/ws/api/v2
# flagfile for the roq-deribit gateway

--fix_uri=tcp://test.deribit.com:9881
--ws_uri=wss://test.deribit.com/ws/api/v2

Market Data#

Event

Stream

Messages

Comments

roq::ReferenceData

MarketData

SecurityList (y)

roq::MarketStatus

WebSocket

ticker

roq::TopOfBook

WebSocket

quote

roq::MarketByPriceUpdate

MarketData

MarketDataSnapshotFullRefresh (W), MarketDataIncrementalRefresh (X)

roq::MarketByOrderUpdate

Unavailable

roq::TradeSummary

MarketData

MarketDataIncrementalRefresh (X)

roq::StatisticsUpdate

MarketData

MarketDataIncrementalRefresh (X)

Statistics#

Type

Comments

INDEX_VALUE

Value of Index for INDEX instruments like BTC-DERIBIT-INDEX. MarketDataIncrementalRefresh (X) / MDEntryType (269) / Index Value (3).

SETTLEMENT_PRICE

Estimated Delivery Price for INDEX instruments like BTC-DERIBIT-INDEX MarketDataIncrementalRefresh (X) / MDEntryType (269) / Settlement Price (6).

PRE_OPEN_INTEREST

Open interest for the symbol. MarketDataIncrementalRefresh (X) / OpenInterest (790)

PRE_SETTLEMENT_PRICE

Mark price for the symbol. MarketDataIncrementalRefresh (X) / MarkPrice (100090)

Order Management#

Event

Stream

Messages

Comments

roq::OrderUpdate

OrderEntry

ExecutionReport (8)

roq::TradeUpdate

OrderEntry

ExecutionReport (8)

Event

Stream

Messages

Comments

roq::OrderUpdate

roq::TradeUpdate

DropCopy

private/get_user_trades_by_currency

Event

Stream

Messages

Comments

roq::CreateOrder

OrderEntry

NewOrderSingle (D)

roq::ModifyOrder

OrderEntry

OrderCancelReplaceRequest (G)

roq::CancelOrder

OrderEntry

OrderCancelRequest (F)

roq::CancelAllOrders

OrderEntry

OrderMassCancelRequest (q)

Event

Stream

Messages

Comments

roq::OrderAck

OrderEntry

ExecutionReport (8), OrderCancelReject (9), Reject (3)

Order Types#

Type

Comments

MARKET

Mapped to '1' (FIX)

LIMIT

Mapped to '2' (FIX)

Time in Force#

Type

Comments

GTC

Mapped to '1' (FIX)

IOC

Mapped to '3' (FIX)

FOK

Mapped to '4' (FIX)

Position Effect#

Note

Not supported

Execution Instructions#

Type

Comments

PARTICIPATE_DO_NOT_INITIATE

Mapped to '6' (FIX)

DO_NOT_INCREASE

Mapped to 'E' (FIX)

Account Management#

Event

Stream

Messages

Comments

roq::PositionUpdate

OrderEntry

RequestForPositions (AN) / PositionReport(AP)

roq::FundsUpdate

Unavailable

Event

Stream

Messages

Comments

roq::PositionUpdate

OrderEntry

RequestForPositions (AN) / PositionReport(AP)

roq::FundsUpdate

DropCopy

private/get_account_summary

Streams#

Type

Comments

FIX

Primary purpose

  • support order management

Each connection

  • supports a single account

Type

Comments

WebSocket

Primary purpose

  • live account updates, including positions and funds

Each connection

  • supports a single account

Type

Comments

FIX

Primary purpose

  • live market data (everything else)

Each connection

  • supports a slice of the symbols

The master account is used to

  • authenticate, only

Type

Comments

WebSocket

Primary purpose

  • live market data (top of book + market status)

Each connection

  • supports a slice of the symbols

The first connection is used to

  • download currencies and symbols

Type

Comments

UDP

Primary purpose

  • live market data (level 2 + top of book + market status)

Constraints#

  • The gateway requires a master account definition to be functional. This is needed by the FIX protocol, even for the market data connection.

  • The field DeribitLabel (FIX tag 100010) is limited to 64 characters

  • The multicast feed can only be used by a single effective user id. This is a Linux restriction.

  • The multicast protocol is flawed due to the snapshot channel containing no more than 10k levels (on either side) and the events channel including book updates for all levels.

    Note

    There are currently no work-arounds implemented to deal with this.

Comments#

  • The gateway must be restarted at least daily if you use the multicast feed. The reason is the snapshot vs events inconsistency mentioned under the constraints. The book effectively becomes more and more wrong for big market moves.