Skip to content

Commit 17be097

Browse files
committed
Minot refactor event buffer checks
1 parent cd93137 commit 17be097

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/BinanceBot.Market/MarketDepthManager.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,15 @@ public async Task BuildAsync(MarketDepth marketDepth, short orderBookDepth = 10,
130130

131131
lock (_eventBuffer)
132132
{
133-
if (_eventBuffer.Count > 0)
134-
firstEvent = _eventBuffer.Peek() as BinanceEventOrderBook;
135-
else
136-
firstEvent = null;
133+
firstEvent = _eventBuffer.Any() ? _eventBuffer.Peek() as BinanceEventOrderBook : null;
137134
}
138135
}
139136

140137
lock (_eventBuffer)
141138
{
142139
// Step 5: Discard buffered events where u <= lastUpdateId
143140
int discardedCount = 0;
144-
while (_eventBuffer.Count > 0 && _eventBuffer.Peek().LastUpdateId <= snapshot.LastUpdateId)
141+
while (_eventBuffer.Any() && _eventBuffer.Peek().LastUpdateId <= snapshot.LastUpdateId)
145142
{
146143
_eventBuffer.Dequeue();
147144
discardedCount++;
@@ -156,7 +153,7 @@ public async Task BuildAsync(MarketDepth marketDepth, short orderBookDepth = 10,
156153

157154
// Step 7: Apply buffered updates
158155
int appliedCount = 0;
159-
while (_eventBuffer.Count > 0)
156+
while (_eventBuffer.Any())
160157
{
161158
var bufferedEvent = _eventBuffer.Peek() as BinanceEventOrderBook;
162159
if (bufferedEvent != null)

0 commit comments

Comments
 (0)