Keyboard Shortcuts
Likes
Search
fine-grained timestamps for reconstruction of market events around a trade execution?
I (programmatically, via TWS) place a limit order for a stock at an exchange that I designate. I then update the limit price of the order as often as a few times per second while I wait for the trade to execute. Meanwhile I am also subscribed to level 2 and market data for the stock, and to the various callbacks related to the order. I would like to log data so that, after the trade executes, I can reconstruct as precisely as possible the timeline of events over a several-second period around the execution. Relevant events include:
My own order may be hidden, in which case it will not appear in the order book. I would like to use TWS to obtain a precise timestamp for each such event, for the time when the event occurs at the exchange. To what extent is that possible? How should I go about finding out? Is there accurate documentation of available timestamps? Thanks, -Neal |
All time stamps for events outside of your computer reported by TWS API currently have a precision of 1 second. There is nothing you can do to get a higher precision. What you can do (and I do) is:
You tag and timestamp everything: major high-level events in your client, your TWS API requests, data you receive from any callbacks, all market data, ... That way can accurately replay any sequence of events and have the relative timing from your client's point of view. For certain events, such as the first TickByTick Last or BidAsk after market open, you can get a pretty good estimate of the actual lag between when the event took place at the exchange and when your client became aware of it. The same is true for the first TickByTick event for very busy seconds. Hope that helps,
´³¨¹°ù²µ±ð²Ô
?
?
On Tue, May 6, 2025 at 10:41 AM, Neal Young wrote:
.. |
On Tue, May 6, 2025 at 12:19 PM, ´³¨¹°ù²µ±ð²Ô Reinold wrote:
´³¨¹°ù²µ±ð²Ô, thanks. Can you clarify what the meaning of the 1-second timestamp is? Does it mean that the event happened within the absolute 1-second interval starting at the timestamp? So (assuming the exchange clock and my computer's clock are exactly accurate) I can know which absolute 1-second interval the event happened in? By "absolute" here I mean with respect to global / world time. -Neal |
That is my understanding, Neal. I work under the assumption that fields such as "time" returned by all TickByTick data feeds as well as? "Last Timestamp" tick #45 represent the epoch time with 1 second resolution for those events at the exchange. The RtVolume ticks #48 and #77 provide time with 1 milli-second resolution, but it has been suggested that those time stamps are actually generated by TWS and do not represent the time at the exchanges. I have not done that much work with them but that feels correct. My server is NTP synchronized against a high-quality time source in the data center and nudges time by a few micro-seconds (usually less than 5us) every 16 seconds. We cannot guarantee that the order of event arrivals at your client is the exact order of the events at the exchanges. Especially if you look at data/events from several exchanges, IBKR market data farms, and IBKR order processing. But the arrival of data for any given stream (say TickByTick Last and TickByTick BidAsk for the same instrument) looks to me as if they are "in order". Even streams for multiple instruments from the same exchange feel like they are substantially in order. The order will likely not be exact if you compare data from sources with very different latencies (say Europe, Asia, US East, US Central). It was always good enough for what I am doing (even at the sub-second level. If you need more you'd have to co-locate with IBKR or the exchanges, switch to FIX without TWS/IBGW, and have dedicated hardware time synchronization. ´³¨¹°ù²µ±ð²Ô ?
On Wed, May 7, 2025 at 08:09 AM, Neal Young wrote:
|