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
37 changes: 32 additions & 5 deletions HTX.Net/Clients/SpotApi/HTXRestClientSpotApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async Task<HttpResult<SharedKline[]>> IKlineRestClient.GetKlinesAsync(GetKlinesR
#endregion

#region Spot Symbol client
SharedSymbolCatalog? ISpotSymbolRestClient.SpotSymbolCatalog => ExchangeSymbolCache.GetSymbolCatalog(_exchangeName, _topicId, EnvironmentName, null);
GetSpotSymbolsOptions ISpotSymbolRestClient.GetSpotSymbolsOptions { get; } = new GetSpotSymbolsOptions(_exchangeName, false);

async Task<HttpResult<SharedSpotSymbol[]>> ISpotSymbolRestClient.GetSpotSymbolsAsync(GetSymbolsRequest request, CancellationToken ct)
Expand All @@ -84,7 +85,17 @@ async Task<HttpResult<SharedSpotSymbol[]>> ISpotSymbolRestClient.GetSpotSymbolsA
if (!result.Success)
return HttpResult.Fail<SharedSpotSymbol[]>(result);

var response = HttpResult.Ok(result, result.Data.Select(s => new SharedSpotSymbol(
var data = result.Data
.Select(x => ParseSymbol(x))
.ToArray();

ExchangeSymbolCache.UpdateSymbolInfo(_topicId, EnvironmentName, null, data);
return HttpResult.Ok(result, SharedUtils.ApplySymbolFilter(data, request));
}

private SharedSpotSymbol ParseSymbol(HTXSymbolConfig s)
{
var result = new SharedSpotSymbol(
s.BaseAsset.ToUpperInvariant(),
s.QuoteAsset.ToUpperInvariant(),
s.Symbol,
Expand All @@ -94,11 +105,27 @@ async Task<HttpResult<SharedSpotSymbol[]>> ISpotSymbolRestClient.GetSpotSymbolsA
PriceDecimals = s.PricePrecision,
MinNotionalValue = s.MinOrderValue,
MinTradeQuantity = s.MinOrderQuantity,
MaxTradeQuantity = s.MaxOrderQuantity
}).ToArray());
MaxTradeQuantity = s.MaxOrderQuantity,
DisplayName = s.Symbol,
QuoteAssetType = SharedAssetType.Crypto
};

if (LibraryHelpers.IsCommodity(s.BaseAsset))
{
result.BaseAssetType = SharedAssetType.TradFi;
result.BaseAssetSubType = SharedAssetSubType.Commodity;
}
else
{
result.BaseAssetType = SharedAssetType.Crypto;
if (LibraryHelpers.IsStableCoin(s.BaseAsset))
result.BaseAssetSubType = SharedAssetSubType.StableCoin;
}

if (LibraryHelpers.IsStableCoin(s.QuoteAsset))
result.QuoteAssetSubType = SharedAssetSubType.StableCoin;

ExchangeSymbolCache.UpdateSymbolInfo(_topicId, EnvironmentName, null, response.Data!);
return response;
return result;
}

async Task<ExchangeCallResult<SharedSymbol[]>> ISpotSymbolRestClient.GetSpotSymbolsForBaseAssetAsync(string baseAsset)
Expand Down
46 changes: 36 additions & 10 deletions HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
#endregion

#region Futures Symbol client

#warning Update to V5

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'

Check warning on line 159 in HTX.Net/Clients/UsdtFutures/HTXRestClientUsdtFuturesApiShared.cs

View workflow job for this annotation

GitHub Actions / build

#warning: 'Update to V5'
SharedSymbolCatalog? IFuturesSymbolRestClient.FuturesSymbolCatalog => ExchangeSymbolCache.GetSymbolCatalog(_exchangeName, _topicId, EnvironmentName, null);
GetFuturesSymbolsOptions IFuturesSymbolRestClient.GetFuturesSymbolsOptions { get; } = new GetFuturesSymbolsOptions(_exchangeName, false);
async Task<HttpResult<SharedFuturesSymbol[]>> IFuturesSymbolRestClient.GetFuturesSymbolsAsync(GetSymbolsRequest request, CancellationToken ct)
{
Expand All @@ -168,26 +169,51 @@
if (!result.Success)
return HttpResult.Fail<SharedFuturesSymbol[]>(result);

IEnumerable<HTXContractInfo> data = result.Data;
if (request.TradingMode.HasValue)
data = data.Where(x => request.TradingMode == TradingMode.PerpetualLinear ? x.BusinessType == BusinessType.Swap : x.BusinessType == BusinessType.Futures);
var data = result.Data
.Select(x => ParseSymbol(x))
.ToArray();

ExchangeSymbolCache.UpdateSymbolInfo(_topicId, EnvironmentName, null, data);
return HttpResult.Ok(result, SharedUtils.ApplySymbolFilter(data, request));
}

var response = HttpResult.Ok(result, data.Select(s => new SharedFuturesSymbol(
private SharedFuturesSymbol ParseSymbol(HTXContractInfo s)
{
var result = new SharedFuturesSymbol(
s.BusinessType == BusinessType.Futures ? TradingMode.DeliveryLinear : TradingMode.PerpetualLinear,
s.Asset,
"USDT",
"USDT",
s.Symbol,
s.Status == ContractStatus.Listing)
{
PriceStep = s.PriceTick,
ContractSize = s.ContractSize,
DeliveryTime = s.DeliveryDate,
QuantityStep = 1
}).ToArray());
QuantityStep = 1,
DisplayName = s.Symbol,
QuoteAssetType = SharedAssetType.Crypto,
QuoteAssetSubType = SharedAssetSubType.StableCoin
};

// HTX API has no way to retrieve underlying type specifics, we can only extract known types
if (LibraryHelpers.IsCommodity(result.BaseAsset))
{
result.BaseAssetType = SharedAssetType.TradFi;
result.BaseAssetSubType = SharedAssetSubType.Commodity;
}
else if (LibraryHelpers.IsEquity(result.BaseAsset, ["X"], []))
{
result.BaseAssetType = SharedAssetType.TradFi;
result.BaseAssetSubType = SharedAssetSubType.Equity;
}
else
{
result.BaseAssetType = SharedAssetType.Crypto;
}

ExchangeSymbolCache.UpdateSymbolInfo(_topicId, EnvironmentName, null, response.Data!);
return response;
return result;
}

async Task<ExchangeCallResult<SharedSymbol[]>> IFuturesSymbolRestClient.GetFuturesSymbolsForBaseAssetAsync(string baseAsset)
{
if (!ExchangeSymbolCache.HasCached(_topicId, EnvironmentName, null))
Expand Down
2 changes: 1 addition & 1 deletion HTX.Net/HTX.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="CryptoExchange.Net" Version="12.1.0" />
<PackageReference Include="CryptoExchange.Net" Version="12.2.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.101">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading