ProtoOAGetTickDataReq returns significantly less ticks than specified in FromTimestamp - ToTimestamp range.
ProtoOAGetTickDataReq returns significantly less ticks than specified in FromTimestamp - ToTimestamp range.
21 Jan 2022, 00:02
Hello,
I'm not sure what I'm doing wrong, but if I pass 1 hour range in ProtoOAGetTickDataReq I only get ticks for a bit more than 1 minute in response and certainly not the 1 hour range I expect.
If I request the exact same 1 minute of ticks (that I got when asking 1 hour) I get less ticks than I already know it should return for the whole minute.
Results are sorted in descending order by timestamp after converting relative price / timestamp to the actual price/timestamp.
If I ask 1 minute range with this code:
var fromDateTime = new DateTime(2022, 1, 20, 21, 2, 26, DateTimeKind.Utc);
var toDateTime = new DateTime(2022, 1, 20, 21, 3, 26, DateTimeKind.Utc);
logger.LogInformation($"fromDateTime: {fromDateTime}, toDateTime: {toDateTime}");
var fromDateTimeOffset = new DateTimeOffset(fromDateTime);
var toDateTimeOffset = new DateTimeOffset(toDateTime);
logger.LogInformation($"fromDateTimeOffset: {fromDateTimeOffset}, toDateTimeOffset: {toDateTimeOffset}");
var fromTimestamp = fromDateTimeOffset.ToUnixTimeMilliseconds();
var toTimestamp = toDateTimeOffset.ToUnixTimeMilliseconds();
logger.LogInformation($"fromTimestamp: {fromTimestamp}, toTimestamp: {toTimestamp}");
var checkFromDateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(fromTimestamp);
var checkToDateTimeOffset = DateTimeOffset.FromUnixTimeMilliseconds(toTimestamp);
logger.LogInformation($"checkFromDateTimeOffset: {checkFromDateTimeOffset}, checkToDateTimeOffset: {checkToDateTimeOffset}");
var message = new ProtoMessage
{
Payload = new ProtoOAGetTickDataReq
{
CtidTraderAccountId = openApiOptions.AccountId,
SymbolId = symbolId,
Type = clientMessageDto.QuoteType,
FromTimestamp = fromTimestamp,
ToTimestamp = toTimestamp
}.ToByteString(),
PayloadType = (int)ProtoOAPayloadType.ProtoOaGetTickdataReq,
ClientMsgId = JsonSerializer.Serialize(clientMessageDto)
};
await openApiClient.SendMessage(message);
Output:
[2022-01-20 22:20:39.715 +01:00 INF] fromDateTime: 20/1/2022 9:02:26 PM, toDateTime: 20/1/2022 9:03:26 PM
[2022-01-20 22:20:39.715 +01:00 INF] fromDateTimeOffset: 20/1/2022 9:02:26 PM +00:00, toDateTimeOffset: 20/1/2022 9:03:26 PM +00:00
[2022-01-20 22:20:39.715 +01:00 INF] fromTimestamp: 1642712546000, toTimestamp: 1642712606000
[2022-01-20 22:20:39.716 +01:00 INF] checkFromDateTimeOffset: 20/1/2022 9:02:26 PM +00:00, checkToDateTimeOffset: 20/1/2022 9:03:26 PM +00:00
[2022-01-20 22:20:39.825 +01:00 INF] Message is ProtoOAGetTickDataRes
[2022-01-20 22:20:39.830 +01:00 INF] EURUSD - Bid TickData Response:
QuoteType, Price, TimestampInMilliseconds, TimestampDateTime
Bid, 1.13052, 1642712603146, 2022-01-20T21:03:23.1460000
Bid, 1.13051, 1642712602941, 2022-01-20T21:03:22.9410000
Bid, 1.13054, 1642712602937, 2022-01-20T21:03:22.9370000
Bid, 1.13053, 1642712602885, 2022-01-20T21:03:22.8850000
Bid, 1.13051, 1642712602873, 2022-01-20T21:03:22.8730000
Bid, 1.13051, 1642712602645, 2022-01-20T21:03:22.6450000
Bid, 1.13051, 1642712602441, 2022-01-20T21:03:22.4410000
Bid, 1.13051, 1642712602409, 2022-01-20T21:03:22.4090000
Bid, 1.13051, 1642712602285, 2022-01-20T21:03:22.2850000
Bid, 1.13051, 1642712602224, 2022-01-20T21:03:22.2240000
Bid, 1.13051, 1642712602125, 2022-01-20T21:03:22.1250000
Bid, 1.13053, 1642712601440, 2022-01-20T21:03:21.4400000
Bid, 1.13051, 1642712601118, 2022-01-20T21:03:21.1180000
Bid, 1.13053, 1642712601012, 2022-01-20T21:03:21.0120000
Bid, 1.13054, 1642712599580, 2022-01-20T21:03:19.5800000
Bid, 1.13049, 1642712599084, 2022-01-20T21:03:19.0840000
Bid, 1.13053, 1642712595235, 2022-01-20T21:03:15.2350000
Bid, 1.13053, 1642712593697, 2022-01-20T21:03:13.6970000
Bid, 1.13054, 1642712586853, 2022-01-20T21:03:06.8530000
As you can see above, it didn't return ticks for the 02 minute and they do exist (see below).
I know that because if I ask 1 hour of data, I get all the ticks for that particular minute as shown below.
If I request 1 hour range:
var fromDateTime = new DateTime(2022, 1, 20, 20, 3, 26, DateTimeKind.Utc);
var toDateTime = new DateTime(2022, 1, 20, 21, 3, 26, DateTimeKind.Utc);
Output:
[2022-01-20 22:44:31.917 +01:00 INF] fromDateTime: 20/1/2022 8:03:26 PM, toDateTime: 20/1/2022 9:03:26 PM
[2022-01-20 22:44:31.917 +01:00 INF] fromDateTimeOffset: 20/1/2022 8:03:26 PM +00:00, toDateTimeOffset: 20/1/2022 9:03:26 PM +00:00
[2022-01-20 22:44:31.917 +01:00 INF] fromTimestamp: 1642709006000, toTimestamp: 1642712606000
[2022-01-20 22:44:31.918 +01:00 INF] checkFromDateTimeOffset: 20/1/2022 8:03:26 PM +00:00, checkToDateTimeOffset: 20/1/2022 9:03:26 PM +00:00
[2022-01-20 22:44:32.111 +01:00 INF] Message is ProtoOAGetTickDataRes
[2022-01-20 22:44:32.120 +01:00 INF] EURUSD - Bid TickData Response:
QuoteType, Price, TimestampInMilliseconds, TimestampDateTime
Bid, 1.13052, 1642712603146, 2022-01-20T21:03:23.1460000
Bid, 1.13054, 1642712602996, 2022-01-20T21:03:22.9960000
Bid, 1.13051, 1642712602995, 2022-01-20T21:03:22.9950000
Bid, 1.13051, 1642712602995, 2022-01-20T21:03:22.9950000
...
Bid, 1.13048, 1642712578774, 2022-01-20T21:02:58.7740000
Bid, 1.13051, 1642712578394, 2022-01-20T21:02:58.3940000
Bid, 1.13053, 1642712577859, 2022-01-20T21:02:57.8590000
Bid, 1.13058, 1642712576671, 2022-01-20T21:02:56.6710000
Bid, 1.13053, 1642712542903, 2022-01-20T21:02:22.9030000
I skipped the records in between, but the last 5 ticks in the output are still hour 21 and not 20 (the ticks are sorted in descending order by timestamp). However, you can see that there are ticks for 21:02:56 and later which it did not return when I asked for the range 21:02:26 - 21:03:26.
Why is this happening and how can I get the expected range?
amusleh
21 Jan 2022, 09:39 ( Updated at: 21 Jan 2022, 09:40 )
Hi,
The ProtoOATickData timestamp is in Unix milliseconds, and it's in descending order.
You have to add the current tick time stamp to previous tick time stamp to get the time, ex in C#:
long previousTickTime = 0; var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Tick,Time"); foreach (var tick in response.TickData) { previousTickTime += tick.Timestamp; stringBuilder.AppendLine($"{tick.Tick},{DateTimeOffset.FromUnixTimeMilliseconds(previousTickTime)}"); } System.Diagnostics.Trace.WriteLine(stringBuilder.ToString());
I sent a request for getting ticks from 20/1/2022 8:03:26 PM to 20/1/2022 9:03:26 PM, here is the response:
Tick,Time 113052,1/20/2022 9:03:25 PM +00:00 1,1/20/2022 9:03:25 PM +00:00 1,1/20/2022 9:03:24 PM +00:00 -1,1/20/2022 9:03:23 PM +00:00 -1,1/20/2022 9:03:22 PM +00:00 1,1/20/2022 9:03:22 PM +00:00 1,1/20/2022 9:03:15 PM +00:00 1,1/20/2022 9:03:15 PM +00:00 -1,1/20/2022 9:03:14 PM +00:00 1,1/20/2022 9:03:12 PM +00:00 -2,1/20/2022 9:03:11 PM +00:00 -1,1/20/2022 9:03:10 PM +00:00 1,1/20/2022 9:03:09 PM +00:00 // Omitted for brevity 4,1/20/2022 8:03:57 PM +00:00 1,1/20/2022 8:03:56 PM +00:00 2,1/20/2022 8:03:56 PM +00:00 2,1/20/2022 8:03:55 PM +00:00 -1,1/20/2022 8:03:33 PM +00:00 1,1/20/2022 8:03:30 PM +00:00 1,1/20/2022 8:03:26 PM +00:00
We will update the ProtoOATickData documentation to describe this.
@amusleh