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 ec13458 commit 9b8ae85
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Bitfinex.Net/Bitfinex.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 @@ -51,7 +51,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
20 changes: 15 additions & 5 deletions Bitfinex.Net/BitfinexAuthenticationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,28 @@ public BitfinexAuthenticationProvider(ApiCredentials credentials, INonceProvider
_nonceProvider = nonceProvider ?? new BitfinexNonceProvider();
}

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;

// Auth requests are always POST
if (uri.AbsolutePath.Contains("v1"))
{
bodyParams.Add("request", uri.AbsolutePath);
bodyParams.Add("nonce", _nonceProvider.GetNonce().ToString());
bodyParameters.Add("request", uri.AbsolutePath);
bodyParameters.Add("nonce", _nonceProvider.GetNonce().ToString());

var signature = JsonConvert.SerializeObject(bodyParams);
var signature = JsonConvert.SerializeObject(bodyParameters);
var payload = Convert.ToBase64String(Encoding.ASCII.GetBytes(signature));
var signedData = Sign(payload);

Expand All @@ -49,7 +59,7 @@ public override void AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpM
}
else if (uri.AbsolutePath.Contains("v2"))
{
var json = JsonConvert.SerializeObject(bodyParams);
var json = JsonConvert.SerializeObject(bodyParameters);
var n = _nonceProvider.GetNonce().ToString();
var signature = $"/api{uri.AbsolutePath}{n}{json}";
var signedData = SignHMACSHA384(signature);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public override CallResult DoHandleMessage(SocketConnection connection, DataEven
if (message.Data is BitfinexChecksum checksum)
_checksumHandler?.Invoke(message.As(checksum.Checksum, _symbol));
else if (message.Data is BitfinexUpdate<IEnumerable<T>> arrayUpdate)
_handler?.Invoke(message.As(arrayUpdate.Data, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
_handler?.Invoke(message.As(arrayUpdate.Data, _channel, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
else if (message.Data is BitfinexUpdate<T> singleUpdate)
_handler?.Invoke(message.As<IEnumerable<T>>(new[] { singleUpdate.Data }, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
_handler?.Invoke(message.As<IEnumerable<T>>(new[] { singleUpdate.Data }, _channel, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
else if (message.Data is BitfinexTopicUpdate<IEnumerable<T>> array3Update)
_handler?.Invoke(message.As(array3Update.Data, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
_handler?.Invoke(message.As(array3Update.Data, _channel, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
else if (message.Data is BitfinexTopicUpdate<T> single3Update)
_handler?.Invoke(message.As<IEnumerable<T>>(new[] { single3Update.Data }, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));
_handler?.Invoke(message.As<IEnumerable<T>>(new[] { single3Update.Data }, _channel, _symbol, _firstUpdate ? SocketUpdateType.Snapshot : SocketUpdateType.Update));

_firstUpdate = false;
return new CallResult(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,50 +152,50 @@ public BitfinexUserSubscription(ILogger logger,
public override CallResult DoHandleMessage(SocketConnection connection, DataEvent<object> message)
{
if (message.Data is BitfinexSocketEvent<List<BitfinexPosition>> positionSnapshot)
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(positionSnapshot.Data, "ps", SocketUpdateType.Snapshot));
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(positionSnapshot.Data, "ps", null, SocketUpdateType.Snapshot));
else if (message.Data is BitfinexSocketEvent<BitfinexPosition> positionUpdate)
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(new[] { positionUpdate.Data }, EnumConverter.GetString(positionUpdate.EventType), SocketUpdateType.Update));
_positionHandler?.Invoke(message.As<IEnumerable<BitfinexPosition>>(new[] { positionUpdate.Data }, EnumConverter.GetString(positionUpdate.EventType), positionUpdate.Data.Symbol, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<List<BitfinexFunding>> loanSnapshot)
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(loanSnapshot.Data, "fls", SocketUpdateType.Snapshot));
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(loanSnapshot.Data, "fls", null, SocketUpdateType.Snapshot));
else if (message.Data is BitfinexSocketEvent<BitfinexFunding> loanUpdate)
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(new[] { loanUpdate.Data }, EnumConverter.GetString(loanUpdate.EventType), SocketUpdateType.Update));
_fundingLoanHandler?.Invoke(message.As<IEnumerable<BitfinexFunding>>(new[] { loanUpdate.Data }, EnumConverter.GetString(loanUpdate.EventType), loanUpdate.Data.Symbol, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<List<BitfinexFundingCredit>> creditSnapshot)
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(creditSnapshot.Data, "fcs", SocketUpdateType.Snapshot));
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(creditSnapshot.Data, "fcs", null, SocketUpdateType.Snapshot));
else if (message.Data is BitfinexSocketEvent<BitfinexFundingCredit> creditUpdate)
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(new[] { creditUpdate.Data }, EnumConverter.GetString(creditUpdate.EventType), SocketUpdateType.Update));
_fundingCreditHandler?.Invoke(message.As<IEnumerable<BitfinexFundingCredit>>(new[] { creditUpdate.Data }, EnumConverter.GetString(creditUpdate.EventType), creditUpdate.Data.Symbol, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<List<BitfinexFundingOffer>> offerSnapshot)
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(offerSnapshot.Data, "fos", SocketUpdateType.Snapshot));
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(offerSnapshot.Data, "fos", null, SocketUpdateType.Snapshot));
else if (message.Data is BitfinexSocketEvent<BitfinexFundingOffer> offerUpdate)
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(new[] { offerUpdate.Data }, EnumConverter.GetString(offerUpdate.EventType), SocketUpdateType.Update));
_fundingOfferHandler?.Invoke(message.As<IEnumerable<BitfinexFundingOffer>>(new[] { offerUpdate.Data }, EnumConverter.GetString(offerUpdate.EventType), offerUpdate.Data.Symbol, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<List<BitfinexOrder>> orderSnapshot)
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(orderSnapshot.Data, "os", SocketUpdateType.Snapshot));
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(orderSnapshot.Data, "os", null, SocketUpdateType.Snapshot));
else if (message.Data is BitfinexSocketEvent<BitfinexOrder> orderUpdate)
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(new[] { orderUpdate.Data }, EnumConverter.GetString(orderUpdate.EventType), SocketUpdateType.Update));
_orderHandler?.Invoke(message.As<IEnumerable<BitfinexOrder>>(new[] { orderUpdate.Data }, EnumConverter.GetString(orderUpdate.EventType), orderUpdate.Data.Symbol, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<BitfinexFundingTrade> fundingTrade)
_fundingTradeHandler?.Invoke(message.As(fundingTrade.Data, EnumConverter.GetString(fundingTrade.EventType), SocketUpdateType.Update));
_fundingTradeHandler?.Invoke(message.As(fundingTrade.Data, EnumConverter.GetString(fundingTrade.EventType), null, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<BitfinexTradeDetails> trade)
_tradeHandler?.Invoke(message.As(trade.Data, EnumConverter.GetString(trade.EventType), SocketUpdateType.Update));
_tradeHandler?.Invoke(message.As(trade.Data, EnumConverter.GetString(trade.EventType), trade.Data.Symbol, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<List<BitfinexWallet>> walletSnapshot)
_walletHandler?.Invoke(message.As<IEnumerable<BitfinexWallet>>(walletSnapshot.Data, "ws", SocketUpdateType.Snapshot));
_walletHandler?.Invoke(message.As<IEnumerable<BitfinexWallet>>(walletSnapshot.Data, "ws", null, SocketUpdateType.Snapshot));
else if (message.Data is BitfinexSocketEvent<BitfinexWallet> walletUpdate)
_walletHandler?.Invoke(message.As<IEnumerable<BitfinexWallet>>(new[] { walletUpdate.Data }, "wu", SocketUpdateType.Update));
_walletHandler?.Invoke(message.As<IEnumerable<BitfinexWallet>>(new[] { walletUpdate.Data }, "wu", null, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<BitfinexBalance> balanceUpdate)
_balanceHandler?.Invoke(message.As(balanceUpdate.Data, "bu", SocketUpdateType.Update));
_balanceHandler?.Invoke(message.As(balanceUpdate.Data, "bu", null, SocketUpdateType.Update));
else if (message.Data is BitfinexSocketEvent<BitfinexFundingInfo> fundingInfoUpdate)
_fundingInfoHandler?.Invoke(message.As(fundingInfoUpdate.Data, "fiu", SocketUpdateType.Update));
_fundingInfoHandler?.Invoke(message.As(fundingInfoUpdate.Data, "fiu", fundingInfoUpdate.Data.Symbol, SocketUpdateType.Update));

else if (message.Data is BitfinexSocketEvent<BitfinexMarginBase> marginBaseUpdate)
_marginBaseHandler?.Invoke(message.As(marginBaseUpdate.Data, "miu", SocketUpdateType.Update));
_marginBaseHandler?.Invoke(message.As(marginBaseUpdate.Data, "miu", null, SocketUpdateType.Update));
else if (message.Data is BitfinexSocketEvent<BitfinexMarginSymbol> marginSymbolUpdate)
_marginSymbolHandler?.Invoke(message.As(marginSymbolUpdate.Data, "miu", SocketUpdateType.Update));
_marginSymbolHandler?.Invoke(message.As(marginSymbolUpdate.Data, "miu", marginSymbolUpdate.Data.Symbol, SocketUpdateType.Update));

return new CallResult(null);
}
Expand Down

0 comments on commit 9b8ae85

Please sign in to comment.