Skip to content

upgrade Huobi MarketSymbolsMetadata to V2 #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2022
Merged
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
86 changes: 54 additions & 32 deletions src/ExchangeSharp/API/Exchanges/Huobi/ExchangeHuobiAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ namespace ExchangeSharp
public sealed partial class ExchangeHuobiAPI : ExchangeAPI
{
public override string BaseUrl { get; set; } = "https://api.huobipro.com";
public string BaseUrlV1 { get; set; } = "https://api.huobipro.com/v1";
public override string BaseUrlWebSocket { get; set; } = "wss://api.huobipro.com/ws";
public string BaseUrlV1 { get; set; } = "https://api.huobipro.com/v1";
public string BaseUrlV2 { get; set; } = "https://api.huobipro.com/v2";
public override string BaseUrlWebSocket { get; set; } = "wss://api.huobipro.com/ws";
public string PrivateUrlV1 { get; set; } = "https://api.huobipro.com/v1";

public bool IsMargin { get; set; }
Expand Down Expand Up @@ -123,43 +124,64 @@ protected override async Task<IEnumerable<string>> OnGetMarketSymbolsAsync()

protected internal override async Task<IEnumerable<ExchangeMarket>> OnGetMarketSymbolsMetadataAsync()
{
/*
{
"status"
:
"ok", "data"
:
[{
"base-currency": "btc",
"quote-currency": "usdt",
"price-precision": 2,
"amount-precision": 4,
"symbol-partition": "main"
}, {
"base-currency": "bch",
"quote-currency": "usdt",
"price-precision": 2,
"amount-precision": 4,
"symbol-partition": "main"
},

*/
List<ExchangeMarket> markets = new List<ExchangeMarket>();
JToken allMarketSymbols = await MakeJsonRequestAsync<JToken>("/common/symbols", BaseUrlV1, null);
/*{
"status":"ok",
"data":[
{
"tags": "",
"state": "online",
"wr": "1.5",
"sc": "ethusdt",
"p": [
{
"id": 9,
"name": "Grayscale",
"weight": 91
}
],
"bcdn": "ETH",
"qcdn": "USDT",
"elr": null,
"tpp": 2,
"tap": 4,
"fp": 8,
"smlr": null,
"flr": null,
"whe": false,
"cd": false,
"te": true,
"sp": "main",
"d": null,
"bc": "eth",
"qc": "usdt",
"toa": 1514779200000,
"ttp": 8,
"w": 999400000,
"lr": 5,
"dn": "ETH/USDT"
}
],
"ts":"1641870869718",
"full":1
}*/
List<ExchangeMarket> markets = new List<ExchangeMarket>();
JToken allMarketSymbols = await MakeJsonRequestAsync<JToken>("/settings/common/symbols", BaseUrlV2, null);
foreach (var marketSymbol in allMarketSymbols)
{
var baseCurrency = marketSymbol["base-currency"].ToStringLowerInvariant();
var quoteCurrency = marketSymbol["quote-currency"].ToStringLowerInvariant();
var pricePrecision = marketSymbol["price-precision"].ConvertInvariant<double>();
var baseCurrency = marketSymbol["bc"].ToStringLowerInvariant();
var quoteCurrency = marketSymbol["qc"].ToStringLowerInvariant();
var symbolCode = marketSymbol["sc"].ToStringLowerInvariant();
var pricePrecision = marketSymbol["tpp"].ConvertInvariant<double>();
var priceStepSize = Math.Pow(10, -pricePrecision).ConvertInvariant<decimal>();
var amountPrecision = marketSymbol["amount-precision"].ConvertInvariant<double>();
var amountPrecision = marketSymbol["tap"].ConvertInvariant<double>();
var quantityStepSize = Math.Pow(10, -amountPrecision).ConvertInvariant<decimal>();
var state = marketSymbol["state"].ToStringLowerInvariant();
var market = new ExchangeMarket
{
BaseCurrency = baseCurrency,
QuoteCurrency = quoteCurrency,
MarketSymbol = baseCurrency + quoteCurrency,
IsActive = true,
MarketSymbol = symbolCode,
IsActive = state == "online",
PriceStepSize = priceStepSize,
QuantityStepSize = quantityStepSize,
MinPrice = priceStepSize,
Expand Down Expand Up @@ -278,7 +300,7 @@ protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValu
{
if (marketSymbols == null || marketSymbols.Length == 0)
{
marketSymbols = (await GetMarketSymbolsAsync()).ToArray();
marketSymbols = (await GetMarketSymbolsMetadataAsync()).Where(s => s.IsActive.Value).Select(s => s.MarketSymbol).ToArray();
}
foreach (string marketSymbol in marketSymbols)
{
Expand Down