Skip to content

Commit

Permalink
Trackers (#121)
Browse files Browse the repository at this point in the history
Updated examples
Updated CryptoExchange.Net to v8.1.0
Moved FormatSymbol to HTXExchange class
Added support Side setting on SharedTrade model
Added HTXTrackerFactory
Added overload to Create method on HTXOrderBookFactory support SharedSymbol parameter
Fixed rate limiting incorrectly applied to websocket market data connections
  • Loading branch information
JKorf authored Oct 28, 2024
1 parent cfed792 commit 53b09b7
Show file tree
Hide file tree
Showing 24 changed files with 490 additions and 31 deletions.
18 changes: 18 additions & 0 deletions Examples/Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTX.Examples.Api", "HTX.Exa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTX.Examples.Console", "HTX.Examples.Console\HTX.Examples.Console.csproj", "{FD4F95C8-D9B7-4F81-9245-4CE667DFD421}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTX.Examples.OrderBook", "HTX.Examples.OrderBook\HTX.Examples.OrderBook.csproj", "{B73A14C6-BED9-4C51-A2C4-6E5FA43741B2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTX.Examples.Tracker", "HTX.Examples.Tracker\HTX.Examples.Tracker.csproj", "{4A6E7966-5E0C-4FFF-A941-987CF91577CC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HTX.Net", "..\HTX.Net\HTX.Net.csproj", "{1761E80A-9D75-4D7F-8A88-31E4499D6DB9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +27,18 @@ Global
{FD4F95C8-D9B7-4F81-9245-4CE667DFD421}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FD4F95C8-D9B7-4F81-9245-4CE667DFD421}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD4F95C8-D9B7-4F81-9245-4CE667DFD421}.Release|Any CPU.Build.0 = Release|Any CPU
{B73A14C6-BED9-4C51-A2C4-6E5FA43741B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B73A14C6-BED9-4C51-A2C4-6E5FA43741B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B73A14C6-BED9-4C51-A2C4-6E5FA43741B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B73A14C6-BED9-4C51-A2C4-6E5FA43741B2}.Release|Any CPU.Build.0 = Release|Any CPU
{4A6E7966-5E0C-4FFF-A941-987CF91577CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A6E7966-5E0C-4FFF-A941-987CF91577CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A6E7966-5E0C-4FFF-A941-987CF91577CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A6E7966-5E0C-4FFF-A941-987CF91577CC}.Release|Any CPU.Build.0 = Release|Any CPU
{1761E80A-9D75-4D7F-8A88-31E4499D6DB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1761E80A-9D75-4D7F-8A88-31E4499D6DB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1761E80A-9D75-4D7F-8A88-31E4499D6DB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1761E80A-9D75-4D7F-8A88-31E4499D6DB9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 5 additions & 2 deletions Examples/HTX.Examples.Api/HTX.Examples.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JKorf.HTX.Net" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\HTX.Net\HTX.Net.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions Examples/HTX.Examples.Console/HTX.Examples.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JKorf.HTX.Net" Version="6.0.0" />
<ProjectReference Include="..\..\HTX.Net\HTX.Net.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions Examples/HTX.Examples.OrderBook/HTX.Examples.OrderBook.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\HTX.Net\HTX.Net.csproj" />
</ItemGroup>

</Project>
52 changes: 52 additions & 0 deletions Examples/HTX.Examples.OrderBook/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using HTX.Net.Interfaces;
using CryptoExchange.Net;
using CryptoExchange.Net.SharedApis;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console;

var collection = new ServiceCollection();
collection.AddHTX();
var provider = collection.BuildServiceProvider();

var trackerFactory = provider.GetRequiredService<IHTXOrderBookFactory>();

// Creat and start the order book
var book = trackerFactory.Create(new SharedSymbol(TradingMode.Spot, "ETH", "USDT"));
var result = await book.StartAsync();
if (!result.Success)
{
Console.WriteLine(result);
return;
}

// Create Spectre table
var table = new Table();
table.ShowRowSeparators = true;
table.AddColumn("Bid Quantity", x => { x.RightAligned(); })
.AddColumn("Bid Price", x => { x.RightAligned(); })
.AddColumn("Ask Price", x => { x.LeftAligned(); })
.AddColumn("Ask Quantity", x => { x.LeftAligned(); });

for(var i = 0; i < 10; i++)
table.AddEmptyRow();

await AnsiConsole.Live(table)
.StartAsync(async ctx =>
{
while (true)
{
var snapshot = book.Book;
for (var i = 0; i < 10; i++)
{
var bid = snapshot.bids.ElementAt(i);
var ask = snapshot.asks.ElementAt(i);
table.UpdateCell(i, 0, ExchangeHelpers.Normalize(bid.Quantity).ToString());
table.UpdateCell(i, 1, ExchangeHelpers.Normalize(bid.Price).ToString());
table.UpdateCell(i, 2, ExchangeHelpers.Normalize(ask.Price).ToString());
table.UpdateCell(i, 3, ExchangeHelpers.Normalize(ask.Quantity).ToString());
}

ctx.Refresh();
await Task.Delay(500);
}
});
18 changes: 18 additions & 0 deletions Examples/HTX.Examples.Tracker/HTX.Examples.Tracker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\HTX.Net\HTX.Net.csproj" />
</ItemGroup>

</Project>
104 changes: 104 additions & 0 deletions Examples/HTX.Examples.Tracker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
using HTX.Net.Interfaces;
using CryptoExchange.Net.SharedApis;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console;
using System.Globalization;

var collection = new ServiceCollection();
collection.AddHTX();
var provider = collection.BuildServiceProvider();

var trackerFactory = provider.GetRequiredService<IHTXTrackerFactory>();

// Creat and start the tracker, keep track of the last 10 minutes
var tracker = trackerFactory.CreateTradeTracker(new SharedSymbol(TradingMode.Spot, "ETH", "USDT"), period: TimeSpan.FromMinutes(10));
var result = await tracker.StartAsync();
if (!result.Success)
{
Console.WriteLine(result);
return;
}

// Create Spectre table
var table = new Table();
table.ShowRowSeparators = true;
table.AddColumn("5 Min Data").AddColumn("-5 Min", x => { x.RightAligned(); })
.AddColumn("Now", x => { x.RightAligned(); })
.AddColumn("Dif", x => { x.RightAligned(); });

table.AddRow("Count", "", "", "");
table.AddRow("Average price", "", "", "");
table.AddRow("Average weighted price", "", "", "");
table.AddRow("Buy/Sell Ratio", "", "", "");
table.AddRow("Volume", "", "", "");
table.AddRow("Value", "", "", "");
table.AddRow("Complete", "", "", "");
table.AddRow("", "", "", "");
table.AddRow("Status", "", "", "");
table.AddRow("Synced From", "", "", "");

// Set default culture for currency display
CultureInfo ci = new CultureInfo("en-US");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;

await AnsiConsole.Live(table)
.StartAsync(async ctx =>
{
while (true)
{
// Get the stats from 10 minutes until 5 minutes ago
var secondLastMinute = tracker.GetStats(DateTime.UtcNow.AddMinutes(-10), DateTime.UtcNow.AddMinutes(-5));

// Get the stats from 5 minutes ago until now
var lastMinute = tracker.GetStats(DateTime.UtcNow.AddMinutes(-5));

// Get the differences between them
var compare = secondLastMinute.CompareTo(lastMinute);

// Update the columns
UpdateDec(0, 1, secondLastMinute.TradeCount);
UpdateDec(0, 2, lastMinute.TradeCount);
UpdateStr(0, 3, $"[{(compare.TradeCountDif.Difference < 0 ? "red" : "green")}]{compare.TradeCountDif.Difference} / {compare.TradeCountDif.PercentageDifference}%[/]");

UpdateStr(1, 1, secondLastMinute.AveragePrice?.ToString("C"));
UpdateStr(1, 2, lastMinute.AveragePrice?.ToString("C"));
UpdateStr(1, 3, $"[{(compare.AveragePriceDif?.Difference < 0 ? "red" : "green")}]{compare.AveragePriceDif?.Difference?.ToString("C")} / {compare.AveragePriceDif?.PercentageDifference}%[/]");

UpdateStr(2, 1, secondLastMinute.VolumeWeightedAveragePrice?.ToString("C"));
UpdateStr(2, 2, lastMinute.VolumeWeightedAveragePrice?.ToString("C"));
UpdateStr(2, 3, $"[{(compare.VolumeWeightedAveragePriceDif?.Difference < 0 ? "red" : "green")}]{compare.VolumeWeightedAveragePriceDif?.Difference?.ToString("C")} / {compare.VolumeWeightedAveragePriceDif?.PercentageDifference}%[/]");

UpdateDec(3, 1, secondLastMinute.BuySellRatio);
UpdateDec(3, 2, lastMinute.BuySellRatio);
UpdateStr(3, 3, $"[{(compare.BuySellRatioDif?.Difference < 0 ? "red" : "green")}]{compare.BuySellRatioDif?.Difference} / {compare.BuySellRatioDif?.PercentageDifference}%[/]");

UpdateDec(4, 1, secondLastMinute.Volume);
UpdateDec(4, 2, lastMinute.Volume);
UpdateStr(4, 3, $"[{(compare.VolumeDif.Difference < 0 ? "red" : "green")}]{compare.VolumeDif.Difference} / {compare.VolumeDif.PercentageDifference}%[/]");

UpdateStr(5, 1, secondLastMinute.QuoteVolume.ToString("C"));
UpdateStr(5, 2, lastMinute.QuoteVolume.ToString("C"));
UpdateStr(5, 3, $"[{(compare.QuoteVolumeDif.Difference < 0 ? "red" : "green")}]{compare.QuoteVolumeDif.Difference?.ToString("C")} / {compare.QuoteVolumeDif.PercentageDifference}%[/]");

UpdateStr(6, 1, secondLastMinute.Complete.ToString());
UpdateStr(6, 2, lastMinute.Complete.ToString());

UpdateStr(8, 1, tracker.Status.ToString());
UpdateStr(9, 1, tracker.SyncedFrom?.ToString());

ctx.Refresh();
await Task.Delay(500);
}
});


void UpdateDec(int row, int col, decimal? val)
{
table.UpdateCell(row, col, val?.ToString() ?? string.Empty);
}

void UpdateStr(int row, int col, string? val)
{
table.UpdateCell(row, col, val ?? string.Empty);
}
8 changes: 7 additions & 1 deletion Examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
A minimal API showing how to integrate HTX.Net in a web API project

### HTX.Examples.Console
A simple console client demonstrating basic usage
A simple console client demonstrating basic usage

### HTX.Examples.OrderBook
Example of using the client side order book implementation

### HTX.Examples.Tracker
Example of using the trade tracker
5 changes: 1 addition & 4 deletions HTX.Net/Clients/SpotApi/HTXRestClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@ internal HTXRestClientSpotApi(ILogger logger, HttpClient? httpClient, HTXRestOpt

protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer();


/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverTime = null)
{
return $"{baseAsset.ToLowerInvariant()}{quoteAsset.ToLowerInvariant()}";
}
=> HTXExchange.FormatSymbol(baseAsset, quoteAsset, tradingMode, deliverTime);

/// <inheritdoc />
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
Expand Down
5 changes: 4 additions & 1 deletion HTX.Net/Clients/SpotApi/HTXRestClientSpotApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ async Task<ExchangeWebResult<IEnumerable<SharedTrade>>> IRecentTradeRestClient.G
if (!result)
return result.AsExchangeResult<IEnumerable<SharedTrade>>(Exchange, null, default);

return result.AsExchangeResult<IEnumerable<SharedTrade>>(Exchange, request.Symbol.TradingMode, result.Data.SelectMany(x => x.Details.Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp))).ToArray());
return result.AsExchangeResult<IEnumerable<SharedTrade>>(Exchange, request.Symbol.TradingMode, result.Data.SelectMany(x => x.Details.Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp)
{
Side = x.Side == OrderSide.Buy ? SharedOrderSide.Buy : SharedOrderSide.Sell
})).ToArray());
}

#endregion
Expand Down
3 changes: 2 additions & 1 deletion HTX.Net/Clients/SpotApi/HTXSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ internal HTXSocketClientSpotApi(ILogger logger, HTXSocketOptions options)
public IHTXSocketClientSpotApiShared SharedClient => this;

/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverTime = null) => $"{baseAsset.ToLowerInvariant()}{quoteAsset.ToLowerInvariant()}";
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverTime = null)
=> HTXExchange.FormatSymbol(baseAsset, quoteAsset, tradingMode, deliverTime);

/// <inheritdoc />
public override string? GetListenerIdentifier(IMessageAccessor message)
Expand Down
5 changes: 4 additions & 1 deletion HTX.Net/Clients/SpotApi/HTXSocketClientSpotApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ async Task<ExchangeResult<UpdateSubscription>> ITradeSocketClient.SubscribeToTra
return new ExchangeResult<UpdateSubscription>(Exchange, validationError);

var symbol = request.Symbol.GetSymbol(FormatSymbol);
var result = await SubscribeToTradeUpdatesAsync(symbol, update => handler(update.AsExchangeEvent(Exchange, update.Data.Details.Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp)))), ct).ConfigureAwait(false);
var result = await SubscribeToTradeUpdatesAsync(symbol, update => handler(update.AsExchangeEvent(Exchange, update.Data.Details.Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp)
{
Side = x.Side == OrderSide.Buy ? SharedOrderSide.Buy : SharedOrderSide.Sell
}))), ct).ConfigureAwait(false);

return new ExchangeResult<UpdateSubscription>(Exchange, result);
}
Expand Down
5 changes: 2 additions & 3 deletions HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ internal HTXRestClientUsdtFuturesApi(ILogger log, HttpClient? httpClient, HTXRes
protected override IMessageSerializer CreateSerializer() => new SystemTextJsonMessageSerializer();

public IHTXRestClientUsdtFuturesApiShared SharedClient => this;

/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverTime = null)
{
return $"{baseAsset.ToUpperInvariant()}-{quoteAsset.ToUpperInvariant()}" + (!deliverTime.HasValue ? string.Empty: ("-" + deliverTime.Value.ToString("yyMMdd")));
}
=> HTXExchange.FormatSymbol(baseAsset, quoteAsset, tradingMode, deliverTime);

/// <inheritdoc />
protected override AuthenticationProvider CreateAuthenticationProvider(ApiCredentials credentials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async Task<ExchangeWebResult<SharedFuturesTicker>> IFuturesTickerRestClient.GetF
if (!resultIndex.Result)
return resultIndex.Result.AsExchangeResult<SharedFuturesTicker>(Exchange, null, default);

return resultTicker.Result.AsExchangeResult(Exchange, request.Symbol.TradingMode, new SharedFuturesTicker(symbol, resultTicker.Result.Data.ClosePrice ?? 0, resultTicker.Result.Data.HighPrice ?? 0, resultTicker.Result.Data.LowPrice ?? 0, resultTicker.Result.Data.Volume ?? 0, resultTicker.Result.Data.OpenPrice == null ? null : Math.Round((resultTicker.Result.Data.ClosePrice ?? 0) / resultTicker.Result.Data.OpenPrice.Value * 100 - 100, 2))
return resultTicker.Result.AsExchangeResult(Exchange, request.Symbol.TradingMode, new SharedFuturesTicker(symbol, resultTicker.Result.Data.ClosePrice, resultTicker.Result.Data.HighPrice, resultTicker.Result.Data.LowPrice, resultTicker.Result.Data.Volume ?? 0, resultTicker.Result.Data.OpenPrice == null ? null : Math.Round((resultTicker.Result.Data.ClosePrice ?? 0) / resultTicker.Result.Data.OpenPrice.Value * 100 - 100, 2))
{
IndexPrice = resultIndex.Result.Data.Single().IndexPrice,
FundingRate = resultFunding.Result.Data.FundingRate,
Expand Down Expand Up @@ -103,7 +103,7 @@ async Task<ExchangeWebResult<IEnumerable<SharedFuturesTicker>>> IFuturesTickerRe
return resultTickers.Result.AsExchangeResult<IEnumerable<SharedFuturesTicker>>(Exchange, SupportedTradingModes, data.Select(x =>
{
var funding = resultFunding.Result.Data.SingleOrDefault(p => p.ContractCode == x.ContractCode);
return new SharedFuturesTicker(x.ContractCode!, x.ClosePrice ?? 0, x.HighPrice ?? 0, x.LowPrice ?? 0, x.Volume ?? 0, x.OpenPrice == null ? null : Math.Round((x.ClosePrice ?? 0) / x.OpenPrice.Value * 100 - 100, 2))
return new SharedFuturesTicker(x.ContractCode!, x.ClosePrice, x.HighPrice, x.LowPrice, x.Volume ?? 0, x.OpenPrice == null ? null : Math.Round((x.ClosePrice ?? 0) / x.OpenPrice.Value * 100 - 100, 2))
{
FundingRate = funding?.FundingRate,
NextFundingTime = funding?.FundingTime
Expand Down Expand Up @@ -977,7 +977,10 @@ async Task<ExchangeWebResult<IEnumerable<SharedTrade>>> IRecentTradeRestClient.G
if (!result)
return result.AsExchangeResult<IEnumerable<SharedTrade>>(Exchange, null, default);

return result.AsExchangeResult<IEnumerable<SharedTrade>>(Exchange, request.Symbol.TradingMode, result.Data.Reverse().Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp)).ToArray());
return result.AsExchangeResult<IEnumerable<SharedTrade>>(Exchange, request.Symbol.TradingMode, result.Data.Reverse().Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp)
{
Side = x.Direction == OrderSide.Buy ? SharedOrderSide.Buy : SharedOrderSide.Sell
}).ToArray());
}

#endregion
Expand Down
5 changes: 1 addition & 4 deletions HTX.Net/Clients/UsdtFutures/HTXSocketClientUsdtFuturesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ internal HTXSocketClientUsdtFuturesApi(ILogger logger, HTXSocketOptions options)

/// <inheritdoc />
public override string FormatSymbol(string baseAsset, string quoteAsset, TradingMode tradingMode, DateTime? deliverTime = null)
{
return $"{baseAsset.ToUpperInvariant()}-{quoteAsset.ToUpperInvariant()}" + (!deliverTime.HasValue ? string.Empty : ("-" + deliverTime.Value.ToString("yyMMdd")));
}

=> HTXExchange.FormatSymbol(baseAsset, quoteAsset, tradingMode, deliverTime);

/// <inheritdoc />
public override ReadOnlyMemory<byte> PreprocessStreamMessage(SocketConnection connection, WebSocketMessageType type, ReadOnlyMemory<byte> data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ async Task<ExchangeResult<UpdateSubscription>> ITradeSocketClient.SubscribeToTra
return new ExchangeResult<UpdateSubscription>(Exchange, validationError);

var symbol = request.Symbol.GetSymbol(FormatSymbol);
var result = await SubscribeToTradeUpdatesAsync(symbol, update => handler(update.AsExchangeEvent(Exchange, update.Data.Trades.Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp)))), ct).ConfigureAwait(false);
var result = await SubscribeToTradeUpdatesAsync(symbol, update => handler(update.AsExchangeEvent(Exchange, update.Data.Trades.Select(x => new SharedTrade(x.Quantity, x.Price, x.Timestamp)
{
Side = x.Side == OrderSide.Buy ? SharedOrderSide.Buy : SharedOrderSide.Sell
}))), ct).ConfigureAwait(false);

return new ExchangeResult<UpdateSubscription>(Exchange, result);
}
Expand Down
Loading

0 comments on commit 53b09b7

Please sign in to comment.