Skip to content

Commit

Permalink
Change volume data type in MarketCandle (#837)
Browse files Browse the repository at this point in the history
Change volume data type in MarketCandle from double to decimal.
  • Loading branch information
BZ-CO authored Jul 2, 2024
1 parent 1729aaf commit 40fac2f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(
HighPrice = data[1].ConvertInvariant<decimal>(),
LowPrice = data[2].ConvertInvariant<decimal>(),
ClosePrice = data[3].ConvertInvariant<decimal>(),
BaseCurrencyVolume = data[4].ConvertInvariant<double>(),
BaseCurrencyVolume = data[4].ConvertInvariant<decimal>(),
Timestamp = timestamp,
};
result.Add(candle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(
Timestamp = CryptoUtility.UnixTimeStampToDateTimeSeconds(
x[0].ConvertInvariant<long>()
),
BaseCurrencyVolume = x[1].ConvertInvariant<double>(),
BaseCurrencyVolume = x[1].ConvertInvariant<decimal>(),
ClosePrice = x[2].ConvertInvariant<decimal>(),
HighPrice = x[3].ConvertInvariant<decimal>(),
LowPrice = x[4].ConvertInvariant<decimal>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(
candleToken[0],
TimestampType.UnixSeconds
),
BaseCurrencyVolume = candleToken[1].ConvertInvariant<double>(),
BaseCurrencyVolume = candleToken[1].ConvertInvariant<decimal>(),
ClosePrice = candleToken[2].ConvertInvariant<decimal>(),
ExchangeName = Name,
HighPrice = candleToken[3].ConvertInvariant<decimal>(),
Expand Down
6 changes: 3 additions & 3 deletions src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(
{ "symbol", marketSymbol },
{ "type", periodString }
};

if (startDate != null)
{
payload.Add("startAt", (long)startDate.Value.UnixTimestampFromDateTimeSeconds());
Expand Down Expand Up @@ -406,8 +406,8 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(
ClosePrice = token[i][2].ConvertInvariant<decimal>(),
HighPrice = token[i][3].ConvertInvariant<decimal>(),
LowPrice = token[i][4].ConvertInvariant<decimal>(),
BaseCurrencyVolume = token[i][5].ConvertInvariant<double>(),
QuoteCurrencyVolume = token[i][6].ConvertInvariant<double>()
BaseCurrencyVolume = token[i][5].ConvertInvariant<decimal>(),
QuoteCurrencyVolume = token[i][6].ConvertInvariant<decimal>()
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Exchanges/LBank/ExchangeLBankAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private List<MarketCandle> ParseMarketCandle(JToken array)
HighPrice = item[2].ConvertInvariant<decimal>(),
LowPrice = item[3].ConvertInvariant<decimal>(),
ClosePrice = item[4].ConvertInvariant<decimal>(),
BaseCurrencyVolume = item[5].ConvertInvariant<double>()
BaseCurrencyVolume = item[5].ConvertInvariant<decimal>()
};

candles.Add(candle);
Expand Down
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Exchanges/NDAX/ExchangeNDAXAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(
LowPrice = enumerable.ElementAt(2).Value<decimal>(),
OpenPrice = enumerable.ElementAt(3).Value<decimal>(),
ClosePrice = enumerable.ElementAt(4).Value<decimal>(),
BaseCurrencyVolume = enumerable.ElementAt(5).Value<double>(),
BaseCurrencyVolume = enumerable.ElementAt(5).Value<decimal>(),
}
)
.Where(candle => !endDate.HasValue || candle.Timestamp <= endDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,8 @@ internal static MarketCandle ParseCandle(
out decimal baseVolume,
out decimal convertVolume
);
candle.BaseCurrencyVolume = (double)baseVolume;
candle.QuoteCurrencyVolume = (double)convertVolume;
candle.BaseCurrencyVolume = baseVolume;
candle.QuoteCurrencyVolume = convertVolume;
if (weightedAverageKey != null)
{
candle.WeightedAverage = token[weightedAverageKey].ConvertInvariant<decimal>();
Expand Down
4 changes: 2 additions & 2 deletions src/ExchangeSharp/Model/MarketCandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public class MarketCandle
/// <summary>
/// Base currency volume (i.e. in BTC-USD, this would be BTC volume)
/// </summary>
public double BaseCurrencyVolume { get; set; }
public decimal BaseCurrencyVolume { get; set; }

/// <summary>
/// Quote currency volume (i.e. in BTC-USD, this would be USD volume)
/// </summary>
public double QuoteCurrencyVolume { get; set; }
public decimal QuoteCurrencyVolume { get; set; }

/// <summary>
/// The weighted average price if provided
Expand Down
6 changes: 3 additions & 3 deletions src/ExchangeSharpConsole/Options/TestOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ await api.GetCandlesAsync(
&& !string.IsNullOrWhiteSpace(candles[0].Name)
&& candles[0].ExchangeName == api.Name
&& candles[0].PeriodSeconds == 86400
&& candles[0].BaseCurrencyVolume > 0.0
&& candles[0].QuoteCurrencyVolume > 0.0
&& candles[0].WeightedAverage >= 0m
&& candles[0].BaseCurrencyVolume > 0
&& candles[0].QuoteCurrencyVolume > 0
&& candles[0].WeightedAverage >= 0
);

Console.WriteLine($"OK ({candles.Length})");
Expand Down
2 changes: 1 addition & 1 deletion tests/ExchangeSharpTests/ExchangeBitBankTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task ShouldGetCandleStick()
candle.HighPrice.Should().Be(1665719m);
candle.LowPrice.Should().Be(1612861m);
candle.ClosePrice.Should().Be(1629941);
candle.BaseCurrencyVolume.Should().Be(5.8362);
candle.BaseCurrencyVolume.Should().Be(5.8362m);
candle.Timestamp
.Should()
.Be(DateTimeOffset.FromUnixTimeMilliseconds(1514160000000).DateTime);
Expand Down

0 comments on commit 40fac2f

Please sign in to comment.