Description
Result
Getting a results that on first glance looks textually correct, however the timestamps must be quoted, as json converts #s to double under the covers.
{"results":[{
"t":1262812349394000000, <- note the lack of quotes in the original
"q":2737306,
"i":"",
"x":4,
"r":12,
"s":100,
"c":[10,12,2],
"p":30.8668,
"z":1}],
...
}
This causes a timestamp like: 1262812349394000000 to be converted to a double, where the mantissa is such that does not have full resolution on the #. The stamp becomes: 1262812349393999878 once it goes through the double conversion (close but not exact).
For better or worse, the time stamp must be quoted. So instead should be:
{"results":[{
"t":"1262812349394000000", <- note the quotes
"q":2737306,
"i":"",
"x":4,
"r":12,
"s":100,
"c":[10,12,2],
"p":30.8668,
"z":1}],
...
}
Expected Result
Timestamps must be quoted for proper json parsing.
Additional Notes
Javascript and many JSON parsers represent the numeric type as a double. This means that most parsers will return the wrong timestamp value (out to some resolution) due to the reduced resolution of 52 bits in the IEEE floating point representation. By convention most market data providers streaming JSON will either:
- quote the epoch timestamp (be it in ms or ns) OR
- use ISO 8601 style timestamps
I think the most compact form would be to continue to use the epoch time in nanoseconds, but quote it so that Javascript, Java-based JSON parsers, and other parsers following the Javascript convention of holding numeric in a double do not lose resolution when parsing. This would present a minor format change and might break some code, however. APIs that expect a numeric value rather than a string-based-long might fail to parse the messages without a minor adjustment to convert the string to a long.