Skip to content

Commit

Permalink
GateIo - Add the missing volume data OnGetTickerAsync and OnGetTicker…
Browse files Browse the repository at this point in the history
…sAsync (#862)
  • Loading branch information
BZ-CO authored Dec 17, 2024
1 parent 9545f6c commit 5405908
Showing 1 changed file with 19 additions and 43 deletions.
62 changes: 19 additions & 43 deletions src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,24 @@ protected override async Task<
IEnumerable<KeyValuePair<string, ExchangeTicker>>
> OnGetTickersAsync()
{
var json = await MakeJsonRequestAsync<JToken>("/spot/tickers");
var response = await MakeJsonRequestAsync<JToken>("/spot/tickers");
var tickers =
new List<KeyValuePair<string, ExchangeTicker>>();

var tickers = json.Select(tickerToken => ParseTicker(tickerToken))
.Select(
ticker => new KeyValuePair<string, ExchangeTicker>(ticker.MarketSymbol, ticker)
)
.ToList();
foreach (var t in response)
{
var marketSymbol = t["currency_pair"].ToStringInvariant();
tickers.Add(new KeyValuePair<string, ExchangeTicker>(
marketSymbol,
await this.ParseTickerAsync(
t,
t["currency_pair"].ToStringInvariant(),
"lowest_ask",
"highest_bid",
"last",
"base_volume",
"quote_volume")));
}

return tickers;
}
Expand Down Expand Up @@ -171,44 +182,9 @@ protected internal override async Task<
protected override async Task<ExchangeTicker> OnGetTickerAsync(string symbol)
{
var json = await MakeJsonRequestAsync<JToken>($"/spot/tickers?currency_pair={symbol}");
return ParseTicker(json.First());
}

private ExchangeTicker ParseTicker(JToken tickerToken)
{
bool IsEmptyString(JToken token) =>
token.Type == JTokenType.String && token.ToObject<string>() == string.Empty;

/*
{
"currency_pair": "BTC3L_USDT",
"last": "2.46140352",
"lowest_ask": "2.477",
"highest_bid": "2.4606821",
"change_percentage": "-8.91",
"base_volume": "656614.0845820589",
"quote_volume": "1602221.66468375534639404191",
"high_24h": "2.7431",
"low_24h": "1.9863",
"etf_net_value": "2.46316141",
"etf_pre_net_value": "2.43201848",
"etf_pre_timestamp": 1611244800,
"etf_leverage": "2.2803019447281203"
}
*/

return new ExchangeTicker
{
Exchange = Name,
MarketSymbol = tickerToken["currency_pair"].ToStringInvariant(),
Bid = IsEmptyString(tickerToken["lowest_ask"])
? default
: tickerToken["lowest_ask"].ConvertInvariant<decimal>(),
Ask = IsEmptyString(tickerToken["highest_bid"])
? default
: tickerToken["highest_bid"].ConvertInvariant<decimal>(),
Last = tickerToken["last"].ConvertInvariant<decimal>(),
};
return await this.ParseTickerAsync(json.First(), json.First()["currency_pair"].ToStringInvariant(), "lowest_ask",
"highest_bid", "last", "base_volume", "quote_volume");
}

protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
Expand Down

0 comments on commit 5405908

Please sign in to comment.