Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DeepCoin.Net/Clients/DeepCoinUserClientProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void ClearUserClients(string userIdentifier)
/// <inheritdoc />
public IDeepCoinRestClient GetRestClient(string userIdentifier, ApiCredentials? credentials = null, DeepCoinEnvironment? environment = null)
{
if (!_restClients.TryGetValue(userIdentifier, out var client))
if (!_restClients.TryGetValue(userIdentifier, out var client) || client.Disposed)
client = CreateRestClient(userIdentifier, credentials, environment);

return client;
Expand All @@ -73,7 +73,7 @@ public IDeepCoinRestClient GetRestClient(string userIdentifier, ApiCredentials?
/// <inheritdoc />
public IDeepCoinSocketClient GetSocketClient(string userIdentifier, ApiCredentials? credentials = null, DeepCoinEnvironment? environment = null)
{
if (!_socketClients.TryGetValue(userIdentifier, out var client))
if (!_socketClients.TryGetValue(userIdentifier, out var client) || client.Disposed)
client = CreateSocketClient(userIdentifier, credentials, environment);

return client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@ async Task<ExchangeWebResult<SharedDeposit[]>> IDepositRestClient.GetDepositsAsy
if (result.Data.Total > (result.Data.Page * result.Data.PageSize))
nextToken = new PageToken(page++, pageSize);

return result.AsExchangeResult<SharedDeposit[]>(Exchange, TradingMode.Spot, result.Data.Data.Select(x => new SharedDeposit(x.Asset, x.Quantity, x.DepositStatus == Enums.DepositStatus.Success, x.CreateTime)
return result.AsExchangeResult<SharedDeposit[]>(Exchange, TradingMode.Spot, result.Data.Data.Select(x =>
new SharedDeposit(
x.Asset,
x.Quantity,
x.DepositStatus == Enums.DepositStatus.Success,
x.CreateTime,
x.DepositStatus == DepositStatus.Success ? SharedTransferStatus.Completed
: x.DepositStatus == DepositStatus.Confirming ? SharedTransferStatus.InProgress
: SharedTransferStatus.Failed)
{
TransactionId = x.TransactionHash,
Network = x.NetworkName,
Expand Down Expand Up @@ -350,6 +358,44 @@ async Task<ExchangeWebResult<SharedSpotSymbol[]>> ISpotSymbolRestClient.GetSpotS
return response;
}

async Task<ExchangeResult<SharedSymbol[]>> ISpotSymbolRestClient.GetSpotSymbolsForBaseAssetAsync(string baseAsset)
{
if (!ExchangeSymbolCache.HasCached(_topicSpotId))
{
var symbols = await ((ISpotSymbolRestClient)this).GetSpotSymbolsAsync(new GetSymbolsRequest()).ConfigureAwait(false);
if (!symbols)
return new ExchangeResult<SharedSymbol[]>(Exchange, symbols.Error!);
}

return new ExchangeResult<SharedSymbol[]>(Exchange, ExchangeSymbolCache.GetSymbolsForBaseAsset(_topicSpotId, baseAsset));
}

async Task<ExchangeResult<bool>> ISpotSymbolRestClient.SupportsSpotSymbolAsync(SharedSymbol symbol)
{
if (symbol.TradingMode != TradingMode.Spot)
throw new ArgumentException(nameof(symbol), "Only Spot symbols allowed");

if (!ExchangeSymbolCache.HasCached(_topicSpotId))
{
var symbols = await ((ISpotSymbolRestClient)this).GetSpotSymbolsAsync(new GetSymbolsRequest()).ConfigureAwait(false);
if (!symbols)
return new ExchangeResult<bool>(Exchange, symbols.Error!);
}

return new ExchangeResult<bool>(Exchange, ExchangeSymbolCache.SupportsSymbol(_topicSpotId, symbol));
}

async Task<ExchangeResult<bool>> ISpotSymbolRestClient.SupportsSpotSymbolAsync(string symbolName)
{
if (!ExchangeSymbolCache.HasCached(_topicSpotId))
{
var symbols = await ((ISpotSymbolRestClient)this).GetSpotSymbolsAsync(new GetSymbolsRequest()).ConfigureAwait(false);
if (!symbols)
return new ExchangeResult<bool>(Exchange, symbols.Error!);
}

return new ExchangeResult<bool>(Exchange, ExchangeSymbolCache.SupportsSymbol(_topicSpotId, symbolName));
}
#endregion

#region Spot Order Client
Expand Down Expand Up @@ -746,10 +792,51 @@ async Task<ExchangeWebResult<SharedFuturesSymbol[]>> IFuturesSymbolRestClient.Ge
MaxShortLeverage = s.MaxLeverage
}).ToArray());

ExchangeSymbolCache.UpdateSymbolInfo(_topicFuturesId, response.Data);
// Also register [BaseAsset][QuoteAsset] as they might be returned for websocket updates
var symbolRegistrations = response.Data
.Concat(response.Data.Select(x => new SharedSpotSymbol(x.BaseAsset, x.QuoteAsset, x.BaseAsset + x.QuoteAsset, x.Trading, x.TradingMode))).ToArray();

ExchangeSymbolCache.UpdateSymbolInfo(_topicFuturesId, symbolRegistrations);
return response;
}
async Task<ExchangeResult<SharedSymbol[]>> IFuturesSymbolRestClient.GetFuturesSymbolsForBaseAssetAsync(string baseAsset)
{
if (!ExchangeSymbolCache.HasCached(_topicFuturesId))
{
var symbols = await ((IFuturesSymbolRestClient)this).GetFuturesSymbolsAsync(new GetSymbolsRequest()).ConfigureAwait(false);
if (!symbols)
return new ExchangeResult<SharedSymbol[]>(Exchange, symbols.Error!);
}

return new ExchangeResult<SharedSymbol[]>(Exchange, ExchangeSymbolCache.GetSymbolsForBaseAsset(_topicFuturesId, baseAsset));
}

async Task<ExchangeResult<bool>> IFuturesSymbolRestClient.SupportsFuturesSymbolAsync(SharedSymbol symbol)
{
if (symbol.TradingMode == TradingMode.Spot)
throw new ArgumentException(nameof(symbol), "Spot symbols not allowed");

if (!ExchangeSymbolCache.HasCached(_topicFuturesId))
{
var symbols = await ((IFuturesSymbolRestClient)this).GetFuturesSymbolsAsync(new GetSymbolsRequest()).ConfigureAwait(false);
if (!symbols)
return new ExchangeResult<bool>(Exchange, symbols.Error!);
}

return new ExchangeResult<bool>(Exchange, ExchangeSymbolCache.SupportsSymbol(_topicFuturesId, symbol));
}

async Task<ExchangeResult<bool>> IFuturesSymbolRestClient.SupportsFuturesSymbolAsync(string symbolName)
{
if (!ExchangeSymbolCache.HasCached(_topicFuturesId))
{
var symbols = await ((IFuturesSymbolRestClient)this).GetFuturesSymbolsAsync(new GetSymbolsRequest()).ConfigureAwait(false);
if (!symbols)
return new ExchangeResult<bool>(Exchange, symbols.Error!);
}

return new ExchangeResult<bool>(Exchange, ExchangeSymbolCache.SupportsSymbol(_topicFuturesId, symbolName));
}
#endregion

#region Futures Order Client
Expand Down Expand Up @@ -1064,7 +1151,8 @@ async Task<ExchangeWebResult<SharedPosition[]>> IFuturesOrderRestClient.GetPosit
{
LiquidationPrice = x.LiquidationPrice == 0 ? null : x.LiquidationPrice,
Leverage = x.Leverage,
AverageOpenPrice = x.AveragePrice,
AverageOpenPrice = x.AveragePrice,
PositionMode = SharedPositionMode.HedgeMode,
PositionSide = x.PositionSide == PositionSide.Long ? SharedPositionSide.Long : SharedPositionSide.Short
}).ToArray());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ async Task<ExchangeResult<UpdateSubscription>> IPositionSocketClient.SubscribeTo
return new ExchangeResult<UpdateSubscription>(Exchange, validationError);

var result = await SubscribeToUserDataUpdatesAsync(request.ListenKey!,
onPositionMessage: update => handler(update.ToType<SharedPosition[]>(update.Data.Select(x => new SharedPosition(ExchangeSymbolCache.ParseSymbol(_topicSpotId, x.Symbol), x.Symbol, x.PositionSize, x.UpdateTime)
onPositionMessage: update => handler(update.ToType<SharedPosition[]>(update.Data.Select(x => new SharedPosition(ExchangeSymbolCache.ParseSymbol(_topicFuturesId, x.Symbol), x.Symbol, x.PositionSize, x.UpdateTime)
{
AverageOpenPrice = x.OpenPrice,
PositionMode = SharedPositionMode.HedgeMode,
PositionSide = x.PositionSide == Enums.PositionSide.Short ? SharedPositionSide.Short : SharedPositionSide.Long,
Leverage = x.Leverage
}).ToArray())),
Expand Down Expand Up @@ -251,7 +252,7 @@ async Task<ExchangeResult<UpdateSubscription>> IUserTradeSocketClient.SubscribeT
request.ListenKey!,
onUserTradeMessage: update => handler(update.ToType<SharedUserTrade[]>(update.Data.Select(x =>
new SharedUserTrade(
ExchangeSymbolCache.ParseSymbol(_topicFuturesId, x.Symbol) ?? ExchangeSymbolCache.ParseSymbol(_topicSpotId, x.Symbol),
ExchangeSymbolCache.ParseSymbol(_topicFuturesId, x.Symbol) ?? ExchangeSymbolCache.ParseSymbol(_topicFuturesId, x.Symbol),
x.Symbol,
x.OrderId.ToString(),
x.TradeId.ToString(),
Expand Down
2 changes: 1 addition & 1 deletion DeepCoin.Net/DeepCoin.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="10.3.0" />
<PackageReference Include="CryptoExchange.Net" Version="10.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.101">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
61 changes: 61 additions & 0 deletions DeepCoin.Net/DeepCoin.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 63 additions & 1 deletion DeepCoin.Net/DeepCoinTrackerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using CryptoExchange.Net.Authentication;
using CryptoExchange.Net.SharedApis;
using CryptoExchange.Net.Trackers.Klines;
using CryptoExchange.Net.Trackers.Trades;
using CryptoExchange.Net.Trackers.UserData.Interfaces;
using CryptoExchange.Net.Trackers.UserData.Objects;
using DeepCoin.Net.Clients;
using DeepCoin.Net.Interfaces;
using DeepCoin.Net.Interfaces.Clients;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using DeepCoin.Net.Clients;

namespace DeepCoin.Net
{
Expand Down Expand Up @@ -73,5 +77,63 @@ public ITradeTracker CreateTradeTracker(SharedSymbol symbol, int? limit = null,
period
);
}

/// <inheritdoc />
public IUserSpotDataTracker CreateUserSpotDataTracker(SpotUserDataTrackerConfig? config = null)
{
var restClient = _serviceProvider?.GetRequiredService<IDeepCoinRestClient>() ?? new DeepCoinRestClient();
var socketClient = _serviceProvider?.GetRequiredService<IDeepCoinSocketClient>() ?? new DeepCoinSocketClient();
return new DeepCoinUserSpotDataTracker(
_serviceProvider?.GetRequiredService<ILogger<DeepCoinUserSpotDataTracker>>() ?? new NullLogger<DeepCoinUserSpotDataTracker>(),
restClient,
socketClient,
null,
config
);
}

/// <inheritdoc />
public IUserSpotDataTracker CreateUserSpotDataTracker(string userIdentifier, ApiCredentials credentials, SpotUserDataTrackerConfig? config = null, DeepCoinEnvironment? environment = null)
{
var clientProvider = _serviceProvider?.GetRequiredService<IDeepCoinUserClientProvider>() ?? new DeepCoinUserClientProvider();
var restClient = clientProvider.GetRestClient(userIdentifier, credentials, environment);
var socketClient = clientProvider.GetSocketClient(userIdentifier, credentials, environment);
return new DeepCoinUserSpotDataTracker(
_serviceProvider?.GetRequiredService<ILogger<DeepCoinUserSpotDataTracker>>() ?? new NullLogger<DeepCoinUserSpotDataTracker>(),
restClient,
socketClient,
userIdentifier,
config
);
}

/// <inheritdoc />
public IUserFuturesDataTracker CreateUserFuturesDataTracker(FuturesUserDataTrackerConfig? config = null)
{
var restClient = _serviceProvider?.GetRequiredService<IDeepCoinRestClient>() ?? new DeepCoinRestClient();
var socketClient = _serviceProvider?.GetRequiredService<IDeepCoinSocketClient>() ?? new DeepCoinSocketClient();
return new DeepCoinUserFuturesDataTracker(
_serviceProvider?.GetRequiredService<ILogger<DeepCoinUserFuturesDataTracker>>() ?? new NullLogger<DeepCoinUserFuturesDataTracker>(),
restClient,
socketClient,
null,
config
);
}

/// <inheritdoc />
public IUserFuturesDataTracker CreateUserFuturesDataTracker(string userIdentifier, ApiCredentials credentials, FuturesUserDataTrackerConfig? config = null, DeepCoinEnvironment? environment = null)
{
var clientProvider = _serviceProvider?.GetRequiredService<IDeepCoinUserClientProvider>() ?? new DeepCoinUserClientProvider();
var restClient = clientProvider.GetRestClient(userIdentifier, credentials, environment);
var socketClient = clientProvider.GetSocketClient(userIdentifier, credentials, environment);
return new DeepCoinUserFuturesDataTracker(
_serviceProvider?.GetRequiredService<ILogger<DeepCoinUserFuturesDataTracker>>() ?? new NullLogger<DeepCoinUserFuturesDataTracker>(),
restClient,
socketClient,
userIdentifier,
config
);
}
}
}
Loading