Skip to content

Commit f7d66db

Browse files
committed
Work-around huobi api bugs, some symbol metadata not in tickers...
1 parent 81ba517 commit f7d66db

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

ExchangeSharp/API/Exchanges/Huobi/ExchangeHuobiAPI.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ protected override async Task<IEnumerable<ExchangeMarket>> OnGetMarketSymbolsMet
154154
var priceStepSize = Math.Pow(10, -pricePrecision).ConvertInvariant<decimal>();
155155
var amountPrecision = marketSymbol["amount-precision"].ConvertInvariant<double>();
156156
var quantityStepSize = Math.Pow(10, -amountPrecision).ConvertInvariant<decimal>();
157-
158157
var market = new ExchangeMarket
159158
{
160159
BaseCurrency = baseCurrency,
@@ -166,8 +165,6 @@ protected override async Task<IEnumerable<ExchangeMarket>> OnGetMarketSymbolsMet
166165
MinPrice = priceStepSize,
167166
MinTradeSize = quantityStepSize,
168167
};
169-
170-
171168
markets.Add(market);
172169
}
173170
return markets;
@@ -210,11 +207,13 @@ protected async override Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
210207
List<KeyValuePair<string, ExchangeTicker>> tickers = new List<KeyValuePair<string, ExchangeTicker>>();
211208
string symbol;
212209
JToken obj = await MakeJsonRequestAsync<JToken>("/market/tickers", BaseUrl, null);
213-
214-
foreach (JToken child in obj["data"])
210+
foreach (JToken child in obj)
215211
{
216212
symbol = child["symbol"].ToStringInvariant();
217-
tickers.Add(new KeyValuePair<string, ExchangeTicker>(symbol, this.ParseTicker(child, symbol, null, null, "close", "amount", "vol")));
213+
if (symbol != "hb10" && symbol != "huobi10") // WTF...
214+
{
215+
tickers.Add(new KeyValuePair<string, ExchangeTicker>(symbol, this.ParseTicker(child, symbol, null, null, "close", "amount", "vol")));
216+
}
218217
}
219218

220219
return tickers;

ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,21 +438,31 @@ internal static ExchangeTicker ParseTicker(this ExchangeAPI api, JToken token, s
438438
}
439439

440440
// create the ticker and return it
441-
JToken askValue = token[askKey];
442-
JToken bidValue = token[bidKey];
443-
if (askValue is JArray)
441+
decimal ask = 0m;
442+
decimal bid = 0m;
443+
if (askKey != null)
444444
{
445-
askValue = askValue[0];
445+
JToken askValue = token[askKey];
446+
if (askValue is JArray)
447+
{
448+
askValue = askValue[0];
449+
ask = askValue.ConvertInvariant<decimal>();
450+
}
446451
}
447-
if (bidValue is JArray)
452+
if (bidKey != null)
448453
{
449-
bidValue = bidValue[0];
454+
JToken bidValue = token[bidKey];
455+
if (bidValue is JArray)
456+
{
457+
bidValue = bidValue[0];
458+
bid = bidValue.ConvertInvariant<decimal>();
459+
}
450460
}
451461
ExchangeTicker ticker = new ExchangeTicker
452462
{
453463
MarketSymbol = marketSymbol,
454-
Ask = askValue.ConvertInvariant<decimal>(),
455-
Bid = bidValue.ConvertInvariant<decimal>(),
464+
Ask = ask,
465+
Bid = bid,
456466
Id = (idKey == null ? null : token[idKey].ToStringInvariant()),
457467
Last = last,
458468
Volume = new ExchangeVolume

0 commit comments

Comments
 (0)