Skip to content

Commit 9bb12d3

Browse files
authored
Add trade count to MarketCandle, and scrape from Kraken Exchange (#628)
1 parent 6bdffbd commit 9bb12d3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ protected override async Task<IEnumerable<MarketCandle>> OnGetCandlesAsync(strin
720720
JProperty prop = json.Children().First() as JProperty;
721721
foreach (JToken jsonCandle in prop.Value)
722722
{
723-
MarketCandle candle = this.ParseCandle(jsonCandle, marketSymbol, periodSeconds, 1, 2, 3, 4, 0, TimestampType.UnixSeconds, 6, null, 5);
723+
MarketCandle candle = this.ParseCandle(jsonCandle, marketSymbol, periodSeconds, 1, 2, 3, 4, 0, TimestampType.UnixSeconds, 6, null, 5, 7);
724724
if (candle.Timestamp >= startDate.Value && candle.Timestamp <= endDate.Value)
725725
{
726726
candles.Add(candle);
@@ -950,7 +950,7 @@ [3]pair string Asset pair
950950
string marketSymbol = token[3].ToStringInvariant();
951951
//Kraken updates the candle open time to the current time, but we want it as open-time i.e. close-time - interval
952952
token[1][0] = token[1][1].ConvertInvariant<long>() - interval * 60;
953-
var candle = this.ParseCandle(token[1], marketSymbol, interval * 60, 2, 3, 4, 5, 0, TimestampType.UnixSeconds, 7, null, 6);
953+
var candle = this.ParseCandle(token[1], marketSymbol, interval * 60, 2, 3, 4, 5, 0, TimestampType.UnixSeconds, 7, null, 6,8);
954954
await callbackAsync(candle);
955955
}
956956
}, connectCallback: async (_socket) =>

src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ internal static void ParseVolumes(this JToken token, object baseVolumeKey, objec
721721
/// <param name="weightedAverageKey">Weighted average key</param>
722722
/// <returns>MarketCandle</returns>
723723
internal static MarketCandle ParseCandle(this INamed named, JToken token, string marketSymbol, int periodSeconds, object openKey, object highKey, object lowKey,
724-
object closeKey, object timestampKey, TimestampType timestampType, object baseVolumeKey, object? quoteVolumeKey = null, object? weightedAverageKey = null)
724+
object closeKey, object timestampKey, TimestampType timestampType, object baseVolumeKey, object? quoteVolumeKey = null, object? weightedAverageKey = null, object? countKey = null)
725725
{
726726
MarketCandle candle = new MarketCandle
727727
{
@@ -742,6 +742,10 @@ internal static MarketCandle ParseCandle(this INamed named, JToken token, string
742742
{
743743
candle.WeightedAverage = token[weightedAverageKey].ConvertInvariant<decimal>();
744744
}
745+
if( countKey != null)
746+
{
747+
candle.Count = token[countKey].ConvertInvariant<int>();
748+
}
745749
return candle;
746750
}
747751
}

src/ExchangeSharp/Model/MarketCandle.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,18 @@ public class MarketCandle
7878
/// </summary>
7979
public decimal WeightedAverage { get; set; }
8080

81+
/// <summary>
82+
/// The number of trades if provided.
83+
/// </summary>
84+
public int Count { get; set; }
85+
8186
/// <summary>
8287
/// ToString
8388
/// </summary>
8489
/// <returns>String</returns>
8590
public override string ToString()
8691
{
87-
return string.Format("{0}/{1}: {2}, {3}, {4}, {5}, {6}, {7}, {8}", Timestamp, PeriodSeconds, OpenPrice, HighPrice, LowPrice, ClosePrice, BaseCurrencyVolume, QuoteCurrencyVolume, WeightedAverage);
92+
return string.Format("{0}/{1}: {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}", Timestamp, PeriodSeconds, OpenPrice, HighPrice, LowPrice, ClosePrice, BaseCurrencyVolume, QuoteCurrencyVolume, WeightedAverage, Count);
8893
}
8994
}
9095
}

0 commit comments

Comments
 (0)