Skip to content

Commit

Permalink
Updated CryptoExchange.Net version
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Jun 11, 2024
1 parent 14cb8ac commit 792942e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ByBit.Net/Bybit.Net.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
Expand Down Expand Up @@ -48,7 +48,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="7.5.2" />
<PackageReference Include="CryptoExchange.Net" Version="7.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
16 changes: 13 additions & 3 deletions ByBit.Net/BybitAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@ public BybitAuthenticationProvider(ApiCredentials credentials) : base(credential
{
}

public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, IDictionary<string, object> uriParams, IDictionary<string, object> bodyParams, Dictionary<string, string> headers, bool auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, RequestBodyFormat bodyFormat)
public override void AuthenticateRequest(
RestApiClient apiClient,
Uri uri,
HttpMethod method,
IDictionary<string, object> uriParameters,
IDictionary<string, object> bodyParameters,
Dictionary<string, string> headers,
bool auth,
ArrayParametersSerialization arraySerialization,
HttpMethodParameterPosition parameterPosition,
RequestBodyFormat requestBodyFormat)
{
if (!auth)
return;

var parameters = parameterPosition == HttpMethodParameterPosition.InUri ? uriParams : bodyParams;
var parameters = parameterPosition == HttpMethodParameterPosition.InUri ? uriParameters : 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("?", "") : bodyFormat == RequestBodyFormat.FormData ? parameters.ToFormData() : JsonConvert.SerializeObject(parameters);
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 recvWindow = ((BybitRestOptions)apiClient.ClientOptions).ReceiveWindow.TotalMilliseconds;
var payload = timestamp + key + recvWindow + signPayload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public BybitOptionsSubscription(ILogger logger, string[] topics, Action<DataEven
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
var data = (BybitSpotSocketEvent<T>)message.Data;
_handler?.Invoke(message.As(data.Data, data.Topic, string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
var splitIndex = data.Topic.LastIndexOf('.');
_handler?.Invoke(message.As(data.Data, data.Topic, splitIndex == -1 ? null : data.Topic.Substring(splitIndex + 1), string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
return new CallResult(null);
}

Expand Down
3 changes: 2 additions & 1 deletion ByBit.Net/Objects/Sockets/Subscriptions/BybitSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public BybitSubscription(ILogger logger, string[] topics, Action<DataEvent<T>> h
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
var data = (BybitSpotSocketEvent<T>)message.Data;
_handler?.Invoke(message.As(data.Data, data.Topic, string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
var splitIndex = data.Topic.LastIndexOf('.');
_handler?.Invoke(message.As(data.Data, data.Topic, splitIndex == -1 ? null : data.Topic.Substring(splitIndex + 1), string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
return new CallResult(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public BybitUnifiedSubscription(ILogger logger, string[] topics, Action<DataEven
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
var data = (BybitSpotSocketEvent<T>)message.Data;
_handler?.Invoke(message.As(data.Data, data.Topic, string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
var splitIndex = data.Topic.LastIndexOf('.');
_handler?.Invoke(message.As(data.Data, data.Topic, splitIndex == -1 ? null : data.Topic.Substring(splitIndex + 1), string.Equals(data.Type, "snapshot", StringComparison.Ordinal) ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
return new CallResult(null);
}

Expand Down

0 comments on commit 792942e

Please sign in to comment.