Skip to content

Commit

Permalink
Updated CryptoExchange.Net
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Aug 7, 2024
1 parent 86e8044 commit 9ceec62
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions Huobi.Net/Clients/SpotApi/HuobiRestClientSpotApiAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
20 changes: 20 additions & 0 deletions Huobi.Net/ExtensionMethods/HuobiExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,25 @@ public static string ValidateHuobiSymbol(this string symbolString)
symbolString = symbolString.ToLower(CultureInfo.InvariantCulture);
return symbolString;
}

/// <summary>
/// Fill parameters in a path. Parameters are specified by '{}' and should be specified in occuring sequence
/// </summary>
/// <param name="path">The total path string</param>
/// <param name="values">The values to fill</param>
/// <returns></returns>
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;
}
}
}
2 changes: 1 addition & 1 deletion Huobi.Net/Huobi.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.10.0" />
<PackageReference Include="CryptoExchange.Net" Version="7.11.0" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions Huobi.Net/Huobi.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Huobi.Net/HuobiAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public override void AuthenticateRequest(
RestApiClient apiClient,
Uri uri,
HttpMethod method,
IDictionary<string, object> uriParameters,
IDictionary<string, object> bodyParameters,
Dictionary<string, string> headers,
ref IDictionary<string, object>? uriParameters,
ref IDictionary<string, object>? bodyParameters,
ref Dictionary<string, string>? headers,
bool auth,
ArrayParametersSerialization arraySerialization,
HttpMethodParameterPosition parameterPosition,
Expand All @@ -42,7 +42,8 @@ public override void AuthenticateRequest(
return;

// These are always in the uri
uriParameters.Add("AccessKeyId", _credentials.Key!.GetString());
uriParameters ??= new Dictionary<string, object>();
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));
Expand All @@ -62,7 +63,7 @@ public override void AuthenticateRequest(
public HuobiAuthParams GetWebsocketAuthentication(Uri uri)
{
var parameters = new Dictionary<string, object>();
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));
Expand All @@ -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<string, object>();
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));
Expand All @@ -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);
}
}
}

0 comments on commit 9ceec62

Please sign in to comment.