Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
Updated CryptoExchange.Net version, added CommonSpotClient to DI, upd…
Browse files Browse the repository at this point in the history
…ated common ticker function to include last price
  • Loading branch information
JKorf committed Oct 9, 2023
1 parent e684d00 commit edae854
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Bittrex.Net/Bittrex.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CryptoExchange.Net" Version="6.1.0" />
<PackageReference Include="CryptoExchange.Net" Version="6.1.5" />
<PackageReference Include="Microsoft.AspNet.SignalR.Client" Version="2.4.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="ConfigureAwaitChecker.Analyzer" Version="5.0.0">
Expand Down
1 change: 1 addition & 0 deletions Bittrex.Net/BittrexHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static IServiceCollection AddBittrex(

services.AddSingleton<IBittrexOrderBookFactory, BittrexOrderBookFactory>();
services.AddTransient<IBittrexRestClient, BittrexRestClient>();
services.AddTransient(x => x.GetRequiredService<IBittrexRestClient>().SpotApi.CommonSpotClient);
if (socketClientLifeTime == null)
services.AddSingleton<IBittrexSocketClient, BittrexSocketClient>();
else
Expand Down
42 changes: 28 additions & 14 deletions Bittrex.Net/Clients/SpotApi/BittrexRestClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,47 @@ async Task<WebCallResult<Ticker>> IBaseRestClient.GetTickerAsync(string symbol,
if (string.IsNullOrEmpty(symbol))
throw new ArgumentException(nameof(symbol) + " required for Bittrex " + nameof(ISpotClient.GetTickerAsync), nameof(symbol));

var ticker = await ExchangeData.GetSymbolSummaryAsync(symbol, ct: ct).ConfigureAwait(false);
if (!ticker)
return ticker.As<Ticker>(null);
var tickerTask = ExchangeData.GetTickerAsync(symbol, ct: ct);
var summaryTask = ExchangeData.GetSymbolSummaryAsync(symbol, ct: ct);
await Task.WhenAll(tickerTask, summaryTask).ConfigureAwait(false);

return ticker.As(new Ticker
if (!tickerTask.Result)
return tickerTask.Result.As<Ticker>(null);

if (!summaryTask.Result)
return summaryTask.Result.As<Ticker>(null);

return tickerTask.Result.As(new Ticker
{
SourceObject = ticker.Data,
Symbol = ticker.Data.Symbol,
HighPrice = ticker.Data.HighPrice,
LowPrice = ticker.Data.LowPrice,
Volume = ticker.Data.Volume
SourceObject = tickerTask.Result.Data,
Symbol = tickerTask.Result.Data.Symbol,
HighPrice = summaryTask.Result.Data.HighPrice,
LowPrice = summaryTask.Result.Data.LowPrice,
Volume = summaryTask.Result.Data.Volume,
LastPrice = tickerTask.Result.Data.LastPrice
});
}

async Task<WebCallResult<IEnumerable<Ticker>>> IBaseRestClient.GetTickersAsync(CancellationToken ct)
{
var tickers = await ExchangeData.GetSymbolSummariesAsync(ct: ct).ConfigureAwait(false);
if (!tickers)
return tickers.As<IEnumerable<Ticker>>(null);
var tickerTask = ExchangeData.GetTickersAsync(ct: ct);
var summaryTask = ExchangeData.GetSymbolSummariesAsync(ct: ct);
await Task.WhenAll(tickerTask, summaryTask).ConfigureAwait(false);

if (!tickerTask.Result)
return tickerTask.Result.As<IEnumerable<Ticker>>(null);

if (!summaryTask.Result)
return summaryTask.Result.As<IEnumerable<Ticker>>(null);

return tickers.As(tickers.Data.Select(t => new Ticker
return tickerTask.Result.As(summaryTask.Result.Data.Select(t => new Ticker
{
SourceObject = t,
Symbol = t.Symbol,
HighPrice = t.HighPrice,
LowPrice = t.LowPrice,
Volume = t.Volume
Volume = t.Volume,
LastPrice = tickerTask.Result.Data.SingleOrDefault(ti => ti.Symbol == t.Symbol)?.LastPrice
}));
}

Expand Down

0 comments on commit edae854

Please sign in to comment.