Tick Charts

Using Tick Charts

Requesting Tick Charts

To get Tick Chart data, we can use the same process described in the Market Data section. Just like with Market Data, we need to open and authorize a WebSocket first. If you’re following the comprehensive JavaScript tutorial, you can find tick chart examples here.

Just like requesting regular chart data, we must construct a request body with the symbol, chartDescription, and timeRange fields. However, we need to lock elementSize to 1 and set underlyingType to “Tick”. For example:

1{
2 "symbol": "ESU9",
3 "chartDescription": {
4 "underlyingType": "Tick",
5 "elementSize": 1,
6 "elementSizeUnit": "UnderlyingUnits"
7 },
8 "timeRange": {
9 ...
10 }
11}

The client calls the standard md/getChart endpoint and passes the request to it. The Tradovate server responds with the standard JSON object schema for chart data. Because an unsubscription request requires the real-time subscription ID sent with this response, the client should store the ID of each subscription that they create so that they can properly unsubscribe later.

Data stream messages A typical data stream message has the following structure:

1{
2 "charts": [ // Array of packets.
3 {
4 "id": 16335, // Subscription ID, the same as historical/real-time subscription IDs from request response.
5 "s": "db", // Source of packet data.
6 "td": 20210718, // Trade date YYYYMMDD.
7 "bp": 11917, // Base price of the packet (integer number of contract tick sizes).
8 // Tick prices are calculated as relative from this one.
9 "bt": 1563421179735, // Base timestamp of the packet.
10 // Tick timestamps are calculated as relative from this value.
11 "ts": 0.25, // Tick size of the contract for which the tick chart is requested.
12 "tks": [ // Array of ticks of this packet.
13 {
14 "t": 0, // Tick relative timestamp.
15 // Actual tick timestamp is packet.bt + tick.t
16 "p": 0, // Tick relative price (in contract tick sizes).
17 // Actual tick price is packet.bp + tick.p
18 "s": 3, // Tick size (seems more proper name should be tick volume).
19 // Please don't confuse with contract tick size (packet.ts).
20 "b": -1, // Bid relative price (optional).
21 // Actual bid price is packet.bp + tick.b
22 "a": 0, // Ask relative price (optional).
23 // Actual ask price is packet.bp + tick.a
24 "bs": 122.21, // Bid size (optional).
25 "as": 28.35, // Ask size (optional).
26 "id": 11768401 // Tick ID
27 },
28 ...
29 ]
30 },
31 // Multiple packets are possible...
32 {
33 "id": 16335,
34 eoh: true // End of history flag.
35 // If the request time range assumes historical data,
36 // this flag indicates that historical ticks are loaded and
37 // further packets will contain real-time ticks.
38 }
39 ]
40};

Using the Tick Stream

The following code snippet is an example of how to process tick chart data stream messages and calculate actual ticks for client consumption.

The function takes a data stream message and converts its packets into a list of actual ticks. Usage of this function assumes that you’ll be passing it the message data retrieved from the WebSocket. Because tick stream data can arrive out of chronological order, it is the client’s responsibility to store and sort pertinent portions of this data.

1function processTickChartMessage(msg) {
2 const result = [];
3 if (msg.charts && msg.charts.length) {
4 for (let i = 0; i < msg.charts.length; ++i) {
5 const packet = msg.charts[i];
6 if (packet.eoh) {
7 //end-of-history,
8 // Historical ticks are loaded.
9 } else if (packet.tks && packet.tks.length) {
10 for (let j = 0; j < packet.tks.length; ++j) {
11 const tick = packet.tks[j];
12
13 const timestamp = packet.bt + tick.t; // Actual tick timestamp
14 const price = packet.bp + tick.p; // Actual tick price
15
16 const bid = tick.bs && packet.bp + tick.b; // Actual bid price (if bid size defined)
17 const ask = tick.as && packet.bp + tick.a; // Actual ask price (if ask size defined)
18
19 result.push({
20 id: tick.id,
21 timestamp: new Date(timestamp),
22
23 price: price * packet.ts, // Tick price as contract price
24 size: tick.s, // Tick size (tick volume)
25
26 bidPrice: bid && bid * packet.ts, // Bid price as contract price
27 bidSize: tick.bs,
28
29 askPrice: ask && ask * packet.ts, // Ask price as contract price
30 askSize: tick.as,
31 });
32 }
33 }
34 }
35 }
36 return result;
37}