Skip to content

Bybit - GetTickersAsync implementation #845

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 2 commits into from
Sep 30, 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
65 changes: 65 additions & 0 deletions src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitV5Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public ExchangeBybitV5Base()
WebSocketOrderBookType = WebSocketOrderBookType.FullBookFirstThenDeltas;
RateLimit = new RateGate(10, TimeSpan.FromSeconds(1));
RequestWindow = TimeSpan.FromSeconds(15);
MarketSymbolSeparator = string.Empty;
MarketSymbolIsUppercase = true;
}

protected override async Task OnGetNonceOffset()
Expand Down Expand Up @@ -270,6 +272,69 @@ protected override async Task<ExchangeOrderBook> OnGetOrderBookAsync(
return book;
}

protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>> OnGetTickersAsync()
{
//{
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "spot",
// "list": [
// {
// "symbol": "MOJOUSDT",
// "bid1Price": "0.01755",
// "bid1Size": "128.66",
// "ask1Price": "0.01763",
// "ask1Size": "311.27",
// "lastPrice": "0.01759",
// "prevPrice24h": "0.01848",
// "price24hPcnt": "-0.0482",
// "highPrice24h": "0.01851",
// "lowPrice24h": "0.01726",
// "turnover24h": "67118.0455931",
// "volume24h": "3769556.35"
// },
// ...
// ]
// }
//}

var tickers = new List<KeyValuePair<string, ExchangeTicker>>();

var marketSymbolsMetadata = await GetMarketSymbolsMetadataAsync();

var url = $"/v5/market/tickers?category={MarketCategory.ToStringLowerInvariant()}";
var token = await MakeJsonRequestAsync<JToken>(url);
var tickerList = token["list"];
foreach (var ticker in tickerList)
{
var marketSymbol = ticker["symbol"].ToStringInvariant();
if (!marketSymbolsMetadata.Any(x => x.MarketSymbol == marketSymbol))
{
// "Please always use the Trading symbols found in the instrument-info api, then query tickers by those symbols." - Bybit API support
continue;
}

var exchangeTicker = await this.ParseTickerAsync(
ticker,
marketSymbol,
"ask1Price",
"bid1Price",
"lastPrice",
// https://bybit-exchange.github.io/docs/faq#what-is-the-difference-between-turnover-and-volume
"volume24h", // Volume: is in the same currency as the quantity's currency
"turnover24h" // Turnover: is in the opposite currency to the quantity's currency
);

tickers.Add(new KeyValuePair<string, ExchangeTicker>(
marketSymbol,
exchangeTicker
));
}

return tickers;
}

#endregion Public

#region Private
Expand Down
Loading