Skip to content

Commit 164377d

Browse files
author
Ariel Silahian
committed
Refactor order count checks for asks and bids
Store asks and bids counts in variables to avoid repeated enumeration and improve readability. Updated null and count checks to use these variables throughout the order imbalance calculation logic.
1 parent 259e081 commit 164377d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

VisualHFT.Commons/Studies/OrderFlowAnalysis.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,18 @@ It can provide insights into the supply and demand dynamics in the market.
107107
A positive order imbalance (more buy orders than sell orders) can indicate upward pressure on prices, while a negative order imbalance (more sell orders than buy orders) can indicate downward pressure on prices.
108108
*/
109109

110-
if (asks != null && bids != null && asks.Count() > 0 && bids.Count() > 0)
110+
int asksCount = asks?.Count() ?? 0;
111+
int bidsCount = bids?.Count() ?? 0;
112+
if (asksCount > 0 && bidsCount > 0)
111113
{
112114
double totalAskSize = 0;
113115
double totalBidSize = 0;
114116

115117
for (int i = 0; i < _bookDepth; i++)
116118
{
117-
if (i < asks.Count())
119+
if (i < asksCount)
118120
totalAskSize += asks[i].Size.Value;
119-
if (i < bids.Count())
121+
if (i < bidsCount)
120122
totalBidSize += bids[i].Size.Value;
121123
}
122124

0 commit comments

Comments
 (0)