Skip to content

Commit

Permalink
CryptoExchange V7.11.0 (#230)
Browse files Browse the repository at this point in the history
Updated CryptoExchange.Net to V7.11.0
  • Loading branch information
JKorf authored Aug 7, 2024
1 parent eb04e27 commit 080ddc3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ByBit.Net/Bybit.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>
25 changes: 17 additions & 8 deletions ByBit.Net/BybitAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace Bybit.Net
{
internal class BybitAuthenticationProvider : AuthenticationProvider
{
public string GetApiKey() => _credentials.Key!.GetString();

public BybitAuthenticationProvider(ApiCredentials credentials) : base(credentials)
{
}
Expand All @@ -26,9 +24,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 @@ -37,12 +35,22 @@ public override void AuthenticateRequest(
if (!auth)
return;

var parameters = parameterPosition == HttpMethodParameterPosition.InUri ? uriParameters : bodyParameters;
IDictionary<string, object> parameters;
if (parameterPosition == HttpMethodParameterPosition.InUri)
{
uriParameters ??= new Dictionary<string, object>();
parameters = uriParameters;
}
else
{
bodyParameters ??= new Dictionary<string, object>();
parameters = bodyParameters;
}
var timestamp = DateTimeConverter.ConvertToMilliseconds(GetTimestamp(apiClient).AddMilliseconds(-1000)).Value.ToString(CultureInfo.InvariantCulture);
if (apiClient is BybitRestClientCopyTradingApi || apiClient is BybitRestClientApi)
{
var signPayload = parameterPosition == HttpMethodParameterPosition.InUri ? uri.SetParameters(parameters, arraySerialization).Query.Replace("?", "") : requestBodyFormat == RequestBodyFormat.FormData ? parameters.ToFormData() : JsonConvert.SerializeObject(parameters);
var key = _credentials.Key!.GetString();
var key = _credentials.Key!;
var recvWindow = ((BybitRestOptions)apiClient.ClientOptions).ReceiveWindow.TotalMilliseconds;
var payload = timestamp + key + recvWindow + signPayload;

Expand All @@ -52,6 +60,7 @@ public override void AuthenticateRequest(
else
sign = SignRSASHA256(Encoding.UTF8.GetBytes(payload), SignOutputType.Base64);

headers ??= new Dictionary<string, string>();
headers.Add("X-BAPI-API-KEY", key);
headers.Add("X-BAPI-SIGN", sign);
headers.Add("X-BAPI-SIGN-TYPE", "2");
Expand All @@ -60,7 +69,7 @@ public override void AuthenticateRequest(
}
else
{
parameters.Add("api_key", _credentials.Key!.GetString());
parameters.Add("api_key", _credentials.Key);
parameters.Add("timestamp", timestamp);
var signData = parameterPosition == HttpMethodParameterPosition.InUri ? uri.SetParameters(parameters, arraySerialization).Query.Replace("?", "") : parameters.ToFormData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden
{
var expireTime = DateTimeConverter.ConvertToMilliseconds(DateTime.UtcNow.AddSeconds(30))!;
var authProvider = (BybitAuthenticationProvider)AuthenticationProvider!;
var key = authProvider.GetApiKey();
var key = authProvider.ApiKey;
var sign = authProvider.Sign($"GET/realtime{expireTime}");

return new BybitQuery("auth", new object[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden
{
var expireTime = DateTimeConverter.ConvertToMilliseconds(DateTime.UtcNow.AddSeconds(30))!;
var authProvider = (BybitAuthenticationProvider)AuthenticationProvider!;
var key = authProvider.GetApiKey();
var key = authProvider.ApiKey;
var sign = authProvider.Sign($"GET/realtime{expireTime}");

return new BybitUnifiedQuery("auth", new object[]
Expand Down
2 changes: 1 addition & 1 deletion ByBit.Net/Clients/SpotApi/v3/BybitSocketClientSpotApiV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected override AuthenticationProvider CreateAuthenticationProvider(ApiCreden
{
var expireTime = DateTimeConverter.ConvertToMilliseconds(DateTime.UtcNow.AddSeconds(30))!;
var authProvider = (BybitAuthenticationProvider)AuthenticationProvider!;
var key = authProvider.GetApiKey();
var key = authProvider.ApiKey;
var sign = authProvider.Sign($"GET/realtime{expireTime}");

return new BybitQuery("auth", new object[]
Expand Down
4 changes: 2 additions & 2 deletions ByBit.Net/Clients/V5/BybitSocketClientPrivateApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Query GetPingQuery(SocketConnection connection)
// Auth subscription
var expireTime = DateTimeConverter.ConvertToMilliseconds(DateTime.UtcNow.AddSeconds(30))!;
var authProvider = (BybitAuthenticationProvider)AuthenticationProvider!;
var key = authProvider.GetApiKey();
var key = authProvider.ApiKey;
var sign = authProvider.Sign($"GET/realtime{expireTime}");

return new BybitQuery("auth", new object[]
Expand All @@ -86,7 +86,7 @@ private Query GetPingQuery(SocketConnection connection)
// Trading
var expireTime = DateTimeConverter.ConvertToMilliseconds(DateTime.UtcNow.AddSeconds(30))!;
var authProvider = (BybitAuthenticationProvider)AuthenticationProvider!;
var key = authProvider.GetApiKey();
var key = authProvider.ApiKey;
var sign = authProvider.Sign($"GET/realtime{expireTime}");

return new BybitRequestQuery<object>("auth", null, new object[]
Expand Down

0 comments on commit 080ddc3

Please sign in to comment.