Skip to content

Commit

Permalink
Ignore invalid symbol statistics trade counts
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvister committed Jan 2, 2018
1 parent 4dca58e commit 80dcb6e
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions src/Binance/Market/SymbolStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,53 +175,55 @@ public sealed class SymbolStatistics
Throw.IfNullOrWhiteSpace(symbol, nameof(symbol));

if (weightedAveragePrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(weightedAveragePrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(weightedAveragePrice));
if (previousClosePrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(previousClosePrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(previousClosePrice));
if (lastPrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(lastPrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(lastPrice));
if (lastQuantity < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} quantity must not be less than 0.", nameof(lastQuantity));
throw new ArgumentException($"{nameof(SymbolStatistics)}: quantity must not be less than 0.", nameof(lastQuantity));
if (bidPrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(bidPrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(bidPrice));
if (bidQuantity < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} quantity must not be less than 0.", nameof(bidQuantity));
throw new ArgumentException($"{nameof(SymbolStatistics)}: quantity must not be less than 0.", nameof(bidQuantity));
if (askPrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(askPrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(askPrice));
if (askQuantity < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} quantity must not be less than 0.", nameof(askQuantity));
throw new ArgumentException($"{nameof(SymbolStatistics)}: quantity must not be less than 0.", nameof(askQuantity));
if (openPrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(openPrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(openPrice));
if (highPrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(highPrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(highPrice));
if (lowPrice < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} price must not be less than 0.", nameof(lowPrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: price must not be less than 0.", nameof(lowPrice));
if (lowPrice > highPrice)
throw new ArgumentException($"{nameof(SymbolStatistics)} low price must be less than or equal to high price.", nameof(lowPrice));
throw new ArgumentException($"{nameof(SymbolStatistics)}: low price must be less than or equal to high price.", nameof(lowPrice));

if (volume < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} volume must be greater than or equal to 0.", nameof(volume));
throw new ArgumentException($"{nameof(SymbolStatistics)}: volume must be greater than or equal to 0.", nameof(volume));
if (quoteVolume < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} volume must be greater than or equal to 0.", nameof(quoteVolume));
throw new ArgumentException($"{nameof(SymbolStatistics)}: volume must be greater than or equal to 0.", nameof(quoteVolume));

if (openTime <= 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} time must be greater than 0.", nameof(openTime));
throw new ArgumentException($"{nameof(SymbolStatistics)}: time must be greater than 0.", nameof(openTime));
if (closeTime <= 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} time must be greater than 0.", nameof(closeTime));
throw new ArgumentException($"{nameof(SymbolStatistics)}: time must be greater than 0.", nameof(closeTime));
if (openTime >= closeTime)
throw new ArgumentException($"{nameof(SymbolStatistics)} open time must be less than close time.", nameof(openTime));
throw new ArgumentException($"{nameof(SymbolStatistics)}: open time must be less than close time.", nameof(openTime));

//if (firstTradeId < 0) // ...fails due to symbol 'ETC' (?) with -1 trade ID.
// throw new ArgumentException($"{nameof(Symbol24hrStats)} trade ID must be greater than 0.", nameof(firstTradeId));
//if (lastTradeId < 0) // ...fails due to symbol 'ETC' (?) with -1 trade ID.
// throw new ArgumentException($"{nameof(Symbol24hrStats)} trade ID must be greater than 0.", nameof(lastTradeId));
if (lastTradeId < firstTradeId)
throw new ArgumentException($"{nameof(SymbolStatistics)} last trade ID must be greater than or equal to first trade ID.", nameof(lastTradeId));
throw new ArgumentException($"{nameof(SymbolStatistics)}: last trade ID must be greater than or equal to first trade ID.", nameof(lastTradeId));

if (tradeCount < 0)
throw new ArgumentException($"{nameof(SymbolStatistics)} trade count must be greater than or equal to 0.", nameof(tradeCount));
if (tradeCount != 0 && tradeCount != lastTradeId - firstTradeId + 1)
throw new ArgumentException($"{nameof(SymbolStatistics)} trade count must be equal to last trade ID - first trade ID + 1.", nameof(tradeCount));
throw new ArgumentException($"{nameof(SymbolStatistics)}: trade count must be greater than or equal to 0.", nameof(tradeCount));

// TODO: Binance API stream occasionally returns invalid trade counts...
//if (tradeCount != 0 && tradeCount != lastTradeId - firstTradeId + 1)
// throw new ArgumentException($"{nameof(SymbolStatistics)}: trade count must be equal to last trade ID - first trade ID + 1.", nameof(tradeCount));

Symbol = symbol;
Period = period;
Expand Down

0 comments on commit 80dcb6e

Please sign in to comment.