Skip to content
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

GateIo - Add the missing volume data OnGetTickerAsync and OnGetTicker… #862

Merged
merged 1 commit into from
Dec 17, 2024
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
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
Loading