Skip to content
QuantLabTickDirect

DocsProtocol

Implementation notes

Things to watch out for when you implement a client.

Socket

  • Keep using one UDP socket from authentication to receiving ticks. If the source port changes, the client is treated as a different subscriber.
  • Use a large receive buffer (several MB). If you subscribe to every symbol, thousands of datagrams can arrive per second. On Linux, the upper limit of SO_RCVBUF is set by net.core.rmem_max.
  • Ticks reach you even from behind a firewall or NAT, as long as you receive on the same socket you sent to the Tick server from. The Heartbeat every second keeps the NAT mapping alive.

Receiving

  • In your receive loop, tell message types apart by templateId. Ticks keep arriving while you are waiting for replies to authentication or subscription requests.
  • Process the entries of Ticks from first to last. One datagram can contain more than one tick for the same symbol.
  • In a language that is slow per message, such as Python, use a separate receive thread when you receive every symbol, and move received datagrams to a queue right away.

Detecting loss

  • sequence is the per-subscriber datagram sequence number and starts at 1. If it is 2 or more greater than the previous value you received, the datagrams in between were lost.
  • When you authenticate again and become a new subscriber, sequence starts over at 1.
  • Lost ticks are not resent. The symbol's value becomes current again with its next tick.

Timestamps and prices

  • All timestamps are UTC, in nanoseconds since 1970-01-01. The Tick server removes each LP's time zone before sending.
  • Prices are fixed-point values × 10⁸ (int64). You can compare them or take differences as integers, before converting to floating point.

Measuring delivery time

The difference between the receive time (receiveTime) and the time your client received the datagram approximates the time from the Tick server to your client. It includes the clock difference between the two machines, so keep your client's clock in sync with NTP (on AWS, Amazon Time Sync Service).

Stopping

  • Send an empty Subscribe before stopping your process. The IP address slot is freed immediately.
  • If you stop without sending it, the slot is freed 5 seconds after Heartbeat stops. If you try to connect from another IP address before then, you may get IpLimitReached.