From 6a4d04394a857d50ab33aa974dd95336031ee1eb Mon Sep 17 00:00:00 2001 From: BZ-CO <30245815+BZ-CO@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:50:36 +0300 Subject: [PATCH 1/5] Fix Kucoin PeriodSecondsToString method Fix PeriodSecondsToString returning wrong daily and weekly periods. --- .../API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs b/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs index b918cf9c..95bdb309 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) { From 1ff64cf50d775f96f4a3625363740ee710afc59f Mon Sep 17 00:00:00 2001 From: BZ-CO <30245815+BZ-CO@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:57:02 +0300 Subject: [PATCH 2/5] Remove unnecessary assignment of startDate and endDate --- .../API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs b/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs index 95bdb309..21be87e6 100644 --- a/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs @@ -366,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 ); From c498544ea3e9cc35646dcb081f56a9966f3e0ab4 Mon Sep 17 00:00:00 2001 From: BZ-CO <30245815+BZ-CO@users.noreply.github.com> Date: Fri, 5 Apr 2024 20:59:55 +0300 Subject: [PATCH 3/5] Remove redundant else keywords in CryptoUtility.SecondsToPeriodStringLong --- src/ExchangeSharp/Utility/CryptoUtility.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ExchangeSharp/Utility/CryptoUtility.cs b/src/ExchangeSharp/Utility/CryptoUtility.cs index 545c05bb..44c30254 100644 --- a/src/ExchangeSharp/Utility/CryptoUtility.cs +++ b/src/ExchangeSharp/Utility/CryptoUtility.cs @@ -1366,23 +1366,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"; } From 1e152090b585eb57fc87ba0bd6fd947bb66b6ffc Mon Sep 17 00:00:00 2001 From: BZ-CO <30245815+BZ-CO@users.noreply.github.com> Date: Fri, 5 Apr 2024 21:01:12 +0300 Subject: [PATCH 4/5] Remove redundant else keywords in CryptoUtility.SecondsToPeriodString --- src/ExchangeSharp/Utility/CryptoUtility.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ExchangeSharp/Utility/CryptoUtility.cs b/src/ExchangeSharp/Utility/CryptoUtility.cs index 44c30254..9a6b67c3 100644 --- a/src/ExchangeSharp/Utility/CryptoUtility.cs +++ b/src/ExchangeSharp/Utility/CryptoUtility.cs @@ -1329,19 +1329,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"; } From 2de99fa5b7cc99dd6f2d7a184a0898af63e6c918 Mon Sep 17 00:00:00 2001 From: BZ-CO <30245815+BZ-CO@users.noreply.github.com> Date: Fri, 5 Apr 2024 21:04:09 +0300 Subject: [PATCH 5/5] Remove unnecessary using directives in CryptoUtility --- src/ExchangeSharp/Utility/CryptoUtility.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ExchangeSharp/Utility/CryptoUtility.cs b/src/ExchangeSharp/Utility/CryptoUtility.cs index 9a6b67c3..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;