Skip to content

Commit

Permalink
Filter out old trade data and don't emit invalid quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero committed Feb 1, 2024
1 parent 7550d79 commit 5914b6b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion QuantConnect.CoinbaseBrokerage/CoinbaseBrokerage.Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ private void Level2Snapshot(CoinbaseLevel2Event snapshotData)

orderBook.BestBidAskUpdated += OnBestBidAskUpdated;

if (orderBook.BestBidPrice == 0 && orderBook.BestAskPrice == 0)
{
// nothing to emit, can happen with illiquid assets
return;
}
EmitQuoteTick(orderBook.Symbol, orderBook.BestBidPrice, orderBook.BestBidSize, orderBook.BestAskPrice, orderBook.BestAskSize);
}
}
Expand Down Expand Up @@ -325,7 +330,10 @@ private void Level2Update(CoinbaseLevel2Event updateData)

private void EmitTradeTick(CoinbaseMarketTradesEvent tradeUpdates)
{
foreach (var trade in tradeUpdates.Trades)
// coinbase sends older data, as an update, seems they send the last 100 trades, so let's filter it out
// also order by time since they return in descending time and we want ascending
var dataFrontier = DateTime.UtcNow - TimeSpan.FromMinutes(5);
foreach (var trade in tradeUpdates.Trades.Where(x => x.Time.UtcDateTime > dataFrontier).OrderBy(x => x.Time))
{
var symbol = _symbolMapper.GetLeanSymbol(trade.ProductId, SecurityType.Crypto, MarketName);

Expand Down

0 comments on commit 5914b6b

Please sign in to comment.