Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static long getlag(List<MarketTrade> trades, double secondsPerTrade)
- {
- var from = trades.Min(t => t.TimestampUnix);
- var to = trades.Max(t => t.TimestampUnix);
- var queue = new Queue<MarketTrade>();
- long worstLag = 0;
- double nextTradeExecutableAt = from;
- for (var now = from; now < to; now++)
- {
- if (queue.Count == 0)
- nextTradeExecutableAt = now;
- // queue up new trades arriving this second
- queue.EnqueueRange(trades.Where(t => t.TimestampUnix == now));
- // execute some trades
- while (nextTradeExecutableAt < now + 1 && queue.Count > 0)
- {
- var trade = queue.Dequeue();
- worstLag = Math.Max(worstLag, now - trade.TimestampUnix);
- nextTradeExecutableAt += secondsPerTrade;
- }
- }
- return worstLag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement