diff --git a/Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApiAccount.cs b/Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApiAccount.cs index 9acbba99..4bd880d1 100644 --- a/Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApiAccount.cs +++ b/Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApiAccount.cs @@ -13,6 +13,7 @@ using Huobi.Net.Objects.Models; using CryptoExchange.Net.Converters; using Huobi.Net.Interfaces.Clients.SpotApi; +using Huobi.Net.ExtensionMethods; namespace Huobi.Net.Clients.SpotApi { diff --git a/Huobi.Net/ExtensionMethods/HuobiExtensionMethods.cs b/Huobi.Net/ExtensionMethods/HuobiExtensionMethods.cs index 609bdfe8..dc3eb1ba 100644 --- a/Huobi.Net/ExtensionMethods/HuobiExtensionMethods.cs +++ b/Huobi.Net/ExtensionMethods/HuobiExtensionMethods.cs @@ -20,5 +20,25 @@ public static string ValidateHuobiSymbol(this string symbolString) symbolString = symbolString.ToLower(CultureInfo.InvariantCulture); return symbolString; } + + /// + /// Fill parameters in a path. Parameters are specified by '{}' and should be specified in occuring sequence + /// + /// The total path string + /// The values to fill + /// + public static string FillPathParameters(this string path, params string[] values) + { + foreach (var value in values) + { + var index = path.IndexOf("{}", StringComparison.Ordinal); + if (index >= 0) + { + path = path.Remove(index, 2); + path = path.Insert(index, value); + } + } + return path; + } } } diff --git a/Huobi.Net/Huobi.Net.csproj b/Huobi.Net/Huobi.Net.csproj index 536522fb..78d9f73d 100644 --- a/Huobi.Net/Huobi.Net.csproj +++ b/Huobi.Net/Huobi.Net.csproj @@ -52,6 +52,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + \ No newline at end of file diff --git a/Huobi.Net/Huobi.Net.xml b/Huobi.Net/Huobi.Net.xml index 1758e6ae..77ee4466 100644 --- a/Huobi.Net/Huobi.Net.xml +++ b/Huobi.Net/Huobi.Net.xml @@ -2237,6 +2237,14 @@ string to validate + + + Fill parameters in a path. Parameters are specified by '{}' and should be specified in occuring sequence + + The total path string + The values to fill + + Huobi environments diff --git a/Huobi.Net/HuobiAuthenticationProvider.cs b/Huobi.Net/HuobiAuthenticationProvider.cs index 58e4b81d..d18bb263 100644 --- a/Huobi.Net/HuobiAuthenticationProvider.cs +++ b/Huobi.Net/HuobiAuthenticationProvider.cs @@ -30,9 +30,9 @@ public override void AuthenticateRequest( RestApiClient apiClient, Uri uri, HttpMethod method, - IDictionary uriParameters, - IDictionary bodyParameters, - Dictionary headers, + ref IDictionary? uriParameters, + ref IDictionary? bodyParameters, + ref Dictionary? headers, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, @@ -42,7 +42,8 @@ public override void AuthenticateRequest( return; // These are always in the uri - uriParameters.Add("AccessKeyId", _credentials.Key!.GetString()); + uriParameters ??= new Dictionary(); + uriParameters.Add("AccessKeyId", _credentials.Key); uriParameters.Add("SignatureMethod", "HmacSHA256"); uriParameters.Add("SignatureVersion", 2); uriParameters.Add("Timestamp", GetTimestamp(apiClient).ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture)); @@ -62,7 +63,7 @@ public override void AuthenticateRequest( public HuobiAuthParams GetWebsocketAuthentication(Uri uri) { var parameters = new Dictionary(); - parameters.Add("accessKey", _credentials.Key!.GetString()); + parameters.Add("accessKey", _credentials.Key); parameters.Add("signatureMethod", "HmacSHA256"); parameters.Add("signatureVersion", 2.1); parameters.Add("timestamp", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture)); @@ -73,13 +74,13 @@ public HuobiAuthParams GetWebsocketAuthentication(Uri uri) var signData = $"GET\n{uri.Host}\n{uri.AbsolutePath}\n{paramString}"; var signature = SignHMACSHA256(signData, SignOutputType.Base64); - return new HuobiAuthParams { AccessKey = _credentials.Key!.GetString(), Timestamp = (string)parameters["timestamp"], Signature = signature }; + return new HuobiAuthParams { AccessKey = _credentials.Key, Timestamp = (string)parameters["timestamp"], Signature = signature }; } public HuobiAuthenticationRequest2 GetWebsocketAuthentication2(Uri uri) { var parameters = new Dictionary(); - parameters.Add("AccessKeyId", _credentials.Key!.GetString()); + parameters.Add("AccessKeyId", _credentials.Key); parameters.Add("SignatureMethod", "HmacSHA256"); parameters.Add("SignatureVersion", 2); parameters.Add("Timestamp", DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.InvariantCulture)); @@ -90,7 +91,7 @@ public HuobiAuthenticationRequest2 GetWebsocketAuthentication2(Uri uri) var signData = $"GET\n{uri.Host}\n{uri.AbsolutePath}\n{paramString}"; var signature = SignHMACSHA256(signData, SignOutputType.Base64); - return new HuobiAuthenticationRequest2(_credentials.Key!.GetString(), (string)parameters["Timestamp"], signature); + return new HuobiAuthenticationRequest2(_credentials.Key, (string)parameters["Timestamp"], signature); } } }