diff --git a/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs b/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs index b918cf9c..21be87e6 100644 --- a/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs @@ -44,42 +44,7 @@ private ExchangeKuCoinAPI() WebSocketOrderBookType = WebSocketOrderBookType.FullBookFirstThenDeltas; } - public override string PeriodSecondsToString(int seconds) - { - switch (seconds) - { - case 60: - return "1min"; - case 180: - return "3min"; - case 300: - return "5min"; - case 900: - return "15min"; - case 1800: - return "30min"; - case 3600: - return "1hour"; - case 7200: - return "2hour"; - case 14400: - return "4hour"; - case 21600: - return "6hour"; - case 28800: - return "8hour"; - case 43200: - return "12hour"; - case 86400: - return "1D"; - case 604800: - return "1W"; - default: - throw new ArgumentException( - $"{nameof(seconds)} must be 60, 180, 300, 900, 1800, 3600, 7200, 14400, 21600, 28800, 43200, 86400, 604800" - ); - } - } + public override string PeriodSecondsToString(int seconds) => CryptoUtility.SecondsToPeriodStringLong(seconds); protected override JToken CheckJsonResponse(JToken result) { @@ -401,22 +366,25 @@ protected override async Task> OnGetCandlesAsync( List candles = new List(); string periodString = PeriodSecondsToString(periodSeconds); - endDate = endDate ?? CryptoUtility.UtcNow; - startDate = startDate ?? CryptoUtility.UtcNow.AddDays(-1); - var payload = new Dictionary { { "symbol", marketSymbol }, - { "type", periodString }, - { "startAt", (long)startDate.Value.UnixTimestampFromDateTimeSeconds() }, // the nonce is milliseconds, this is seconds without decimal - { "endAt", (long)endDate.Value.UnixTimestampFromDateTimeSeconds() } // the nonce is milliseconds, this is seconds without decimal + { "type", periodString } }; - var addPayload = CryptoUtility.GetFormForPayload(payload, false); + + if (startDate != null) + { + payload.Add("startAt", (long)startDate.Value.UnixTimestampFromDateTimeSeconds()); + } + if (endDate != null) + { + payload.Add("endAt", (long)endDate.Value.UnixTimestampFromDateTimeSeconds()); + } // The results of this Kucoin API call are also a mess. 6 different arrays (c,t,v,h,l,o) with the index of each shared for the candle values // It doesn't use their standard error format... JToken token = await MakeJsonRequestAsync( - "/market/candles?" + addPayload, + "/market/candles?" + payload.GetFormForPayload(false), null, payload ); diff --git a/src/ExchangeSharp/Utility/CryptoUtility.cs b/src/ExchangeSharp/Utility/CryptoUtility.cs index 545c05bb..cdc5a05a 100644 --- a/src/ExchangeSharp/Utility/CryptoUtility.cs +++ b/src/ExchangeSharp/Utility/CryptoUtility.cs @@ -12,13 +12,11 @@ The above copyright notice and this permission notice shall be included in all c #nullable enable using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Net; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security; using System.Security.Cryptography; @@ -1329,19 +1327,23 @@ public static string SecondsToPeriodString(int seconds, bool capitalAfterMinute { return seconds / monthThreshold + "M"; } - else if (seconds >= weekThreshold) + + if (seconds >= weekThreshold) { return seconds / weekThreshold + (capitalAfterMinute ? "W" : "w"); } - else if (seconds >= dayThreshold) + + if (seconds >= dayThreshold) { return seconds / dayThreshold + (capitalAfterMinute ? "D" : "d"); } - else if (seconds >= hourThreshold) + + if (seconds >= hourThreshold) { return seconds / hourThreshold + (capitalAfterMinute ? "H" : "h"); } - else if (seconds >= minuteThreshold) + + if (seconds >= minuteThreshold) { return seconds / minuteThreshold + "m"; } @@ -1366,23 +1368,28 @@ public static string SecondsToPeriodStringLong(int seconds) { return seconds / yearThreshold + "year"; } - else if (seconds >= monthThreshold) + + if (seconds >= monthThreshold) { return seconds / monthThreshold + "mon"; } - else if (seconds >= weekThreshold) + + if (seconds >= weekThreshold) { return seconds / weekThreshold + "week"; } - else if (seconds >= dayThreshold) + + if (seconds >= dayThreshold) { return seconds / dayThreshold + "day"; } - else if (seconds >= hourThreshold) + + if (seconds >= hourThreshold) { return seconds / hourThreshold + "hour"; } - else if (seconds >= minuteThreshold) + + if (seconds >= minuteThreshold) { return seconds / minuteThreshold + "min"; }