From 54059088ca12eba6e6fb7eb60b14adae055f9e5f Mon Sep 17 00:00:00 2001 From: BZ-CO <30245815+BZ-CO@users.noreply.github.com> Date: Wed, 18 Dec 2024 00:53:29 +0200 Subject: [PATCH] GateIo - Add the missing volume data OnGetTickerAsync and OnGetTickersAsync (#862) --- .../API/Exchanges/GateIo/ExchangeGateIoAPI.cs | 62 ++++++------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs b/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs index c8c59d7f..8535d69c 100644 --- a/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs @@ -41,13 +41,24 @@ protected override async Task< IEnumerable> > OnGetTickersAsync() { - var json = await MakeJsonRequestAsync("/spot/tickers"); + var response = await MakeJsonRequestAsync("/spot/tickers"); + var tickers = + new List>(); - var tickers = json.Select(tickerToken => ParseTicker(tickerToken)) - .Select( - ticker => new KeyValuePair(ticker.MarketSymbol, ticker) - ) - .ToList(); + foreach (var t in response) + { + var marketSymbol = t["currency_pair"].ToStringInvariant(); + tickers.Add(new KeyValuePair( + marketSymbol, + await this.ParseTickerAsync( + t, + t["currency_pair"].ToStringInvariant(), + "lowest_ask", + "highest_bid", + "last", + "base_volume", + "quote_volume"))); + } return tickers; } @@ -171,44 +182,9 @@ protected internal override async Task< protected override async Task OnGetTickerAsync(string symbol) { var json = await MakeJsonRequestAsync($"/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.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(), - Ask = IsEmptyString(tickerToken["highest_bid"]) - ? default - : tickerToken["highest_bid"].ConvertInvariant(), - Last = tickerToken["last"].ConvertInvariant(), - }; + return await this.ParseTickerAsync(json.First(), json.First()["currency_pair"].ToStringInvariant(), "lowest_ask", + "highest_bid", "last", "base_volume", "quote_volume"); } protected override async Task OnGetOrderBookAsync(