diff --git a/Bittrex.Net/Bittrex.Net.csproj b/Bittrex.Net/Bittrex.Net.csproj index 20bea60..1a81e49 100644 --- a/Bittrex.Net/Bittrex.Net.csproj +++ b/Bittrex.Net/Bittrex.Net.csproj @@ -39,7 +39,7 @@ - + diff --git a/Bittrex.Net/BittrexHelpers.cs b/Bittrex.Net/BittrexHelpers.cs index e6ef73e..7fb4939 100644 --- a/Bittrex.Net/BittrexHelpers.cs +++ b/Bittrex.Net/BittrexHelpers.cs @@ -75,6 +75,7 @@ public static IServiceCollection AddBittrex( services.AddSingleton(); services.AddTransient(); + services.AddTransient(x => x.GetRequiredService().SpotApi.CommonSpotClient); if (socketClientLifeTime == null) services.AddSingleton(); else diff --git a/Bittrex.Net/Clients/SpotApi/BittrexRestClientSpotApi.cs b/Bittrex.Net/Clients/SpotApi/BittrexRestClientSpotApi.cs index abc0884..8cb2931 100644 --- a/Bittrex.Net/Clients/SpotApi/BittrexRestClientSpotApi.cs +++ b/Bittrex.Net/Clients/SpotApi/BittrexRestClientSpotApi.cs @@ -97,33 +97,47 @@ async Task> 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(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(null); + + if (!summaryTask.Result) + return summaryTask.Result.As(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>> IBaseRestClient.GetTickersAsync(CancellationToken ct) { - var tickers = await ExchangeData.GetSymbolSummariesAsync(ct: ct).ConfigureAwait(false); - if (!tickers) - return tickers.As>(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>(null); + + if (!summaryTask.Result) + return summaryTask.Result.As>(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 })); }