Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Oct 27, 2024
1 parent 2d4531e commit 687633a
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions CoinEx.Net/CoinExTrackerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CoinEx.Net.Interfaces;
using CoinEx.Net.Clients;
using CoinEx.Net.Interfaces;
using CoinEx.Net.Interfaces.Clients;
using CryptoExchange.Net.SharedApis;
using CryptoExchange.Net.Trackers.Klines;
using CryptoExchange.Net.Trackers.Trades;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -12,7 +12,14 @@ namespace CoinEx.Net
/// <inheritdoc />
public class CoinExTrackerFactory : ICoinExTrackerFactory
{
private readonly IServiceProvider _serviceProvider;
private readonly IServiceProvider? _serviceProvider;

/// <summary>
/// ctor
/// </summary>
public CoinExTrackerFactory()
{
}

/// <summary>
/// ctor
Expand All @@ -26,23 +33,27 @@ public CoinExTrackerFactory(IServiceProvider serviceProvider)
/// <inheritdoc />
public ITradeTracker CreateTradeTracker(SharedSymbol symbol, int? limit = null, TimeSpan? period = null)
{
IRecentTradeRestClient restClient;
ITradeSocketClient socketClient;
var restClient = _serviceProvider?.GetRequiredService<ICoinExRestClient>() ?? new CoinExRestClient();
var socketClient = _serviceProvider?.GetRequiredService<ICoinExSocketClient>() ?? new CoinExSocketClient();

IRecentTradeRestClient sharedRestClient;
ITradeSocketClient sharedSocketClient;
if (symbol.TradingMode == TradingMode.Spot)
{
restClient = _serviceProvider.GetRequiredService<ICoinExRestClient>().SpotApiV2.SharedClient;
socketClient = _serviceProvider.GetRequiredService<ICoinExSocketClient>().SpotApiV2.SharedClient;
sharedRestClient = restClient.SpotApiV2.SharedClient;
sharedSocketClient = socketClient.SpotApiV2.SharedClient;
}
else
{
restClient = _serviceProvider.GetRequiredService<ICoinExRestClient>().SpotApiV2.SharedClient;
socketClient = _serviceProvider.GetRequiredService<ICoinExSocketClient>().SpotApiV2.SharedClient;
sharedRestClient = restClient.FuturesApi.SharedClient;
sharedSocketClient = socketClient.FuturesApi.SharedClient;
}

return new TradeTracker(
_serviceProvider.GetRequiredService<ILoggerFactory>().CreateLogger(restClient.Exchange),
restClient,
socketClient,
_serviceProvider?.GetRequiredService<ILoggerFactory>().CreateLogger(restClient.Exchange),
sharedRestClient,
null,
sharedSocketClient,
symbol,
limit,
period
Expand Down

0 comments on commit 687633a

Please sign in to comment.