exchange.GetTickers
Retrieves aggregated market data from the exchange (an array of Ticker structures). When exchange is a spot exchange object, it returns the ticker market data for all trading pairs; when exchange is a futures exchange object, it returns the ticker market data for all contracts.
exchange.GetTickers()Examples
-
Call the
exchange.GetTickers()function to retrieve aggregated market ticker data.javascriptfunction main() { var tickers = exchange.GetTickers() if (tickers && tickers.length > 0) { Log("Number of tradable symbols:", tickers.length) } }pythondef main(): tickers = exchange.GetTickers() if tickers and len(tickers) > 0: Log("Number of tradable symbols:", len(tickers))rustfn main() { if let Ok(tickers) = exchange.GetTickers() { if tickers.len() > 0 { Log!("Number of tradable symbols:", tickers.len()); } } } -
Use a spot exchange object and call the
exchange.GetTickers()function in the backtesting system. Before calling any market data function, GetTickers only returns the ticker data of the current default trading pair; after calling a market data function, it returns the ticker data of all trading pairs that have been requested. You can refer to the following test example.javascript/*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] */ function main() { var arrSymbol = ["ADA_USDT", "LTC_USDT", "ETH_USDT", "SOL_USDT"] // Before requesting the market data of other trading pairs, call GetTickers var tickers1 = exchange.GetTickers() var tbl1 = {type: "table", title: "tickers1", cols: ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"], rows: []} for (var ticker of tickers1) { tbl1.rows.push([ticker.Symbol, ticker.High, ticker.Open, ticker.Low, ticker.Last, ticker.Buy, ticker.Sell, ticker.Time, ticker.Volume]) } // Request the market data of other trading pairs for (var symbol of arrSymbol) { exchange.GetTicker(symbol) } // Call GetTickers again var tickers2 = exchange.GetTickers() var tbl2 = {type: "table", title: "tickers2", cols: ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"], rows: []} for (var ticker of tickers2) { tbl2.rows.push([ticker.Symbol, ticker.High, ticker.Open, ticker.Low, ticker.Last, ticker.Buy, ticker.Sell, ticker.Time, ticker.Volume]) } LogStatus("`" + JSON.stringify([tbl1, tbl2]) + "`") }python'''backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] ''' import json def main(): arrSymbol = ["ADA_USDT", "LTC_USDT", "ETH_USDT", "SOL_USDT"] tickers1 = exchange.GetTickers() tbl1 = {"type": "table", "title": "tickers1", "cols": ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"], "rows": []} for ticker in tickers1: tbl1["rows"].append([ticker["Symbol"], ticker["High"], ticker["Open"], ticker["Low"], ticker["Last"], ticker["Buy"], ticker["Sell"], ticker["Time"], ticker["Volume"]]) for symbol in arrSymbol: exchange.GetTicker(symbol) tickers2 = exchange.GetTickers() tbl2 = {"type": "table", "title": "tickers2", "cols": ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"], "rows": []} for ticker in tickers2: tbl2["rows"].append([ticker["Symbol"], ticker["High"], ticker["Open"], ticker["Low"], ticker["Last"], ticker["Buy"], ticker["Sell"], ticker["Time"], ticker["Volume"]]) LogStatus("`" + json.dumps([tbl1, tbl2]) + "`")rust/*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] */ fn tickerToJson(ticker: &Ticker) -> String { format!(r#"["{}", {}, {}, {}, {}, {}, {}, {}, {}]"#, ticker.Symbol, ticker.High, ticker.Open, ticker.Low, ticker.Last, ticker.Buy, ticker.Sell, ticker.Time, ticker.Volume) } fn main() { let arrSymbol = ["ADA_USDT", "LTC_USDT", "ETH_USDT", "SOL_USDT"]; // Before requesting the market data of other trading pairs, call GetTickers // The Rust SDK has no JSON serialization, so use format! to concatenate the JSON text of the table let tickers1 = exchange.GetTickers().unwrap(); let rows1 = tickers1.iter().map(tickerToJson).collect::<Vec<String>>().join(","); let tbl1 = format!(r#"{{"type": "table", "title": "tickers1", "cols": ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"], "rows": [{}]}}"#, rows1); // Request the market data of other trading pairs for symbol in arrSymbol { exchange.GetTicker(symbol); } // Call GetTickers again let tickers2 = exchange.GetTickers().unwrap(); let rows2 = tickers2.iter().map(tickerToJson).collect::<Vec<String>>().join(","); let tbl2 = format!(r#"{{"type": "table", "title": "tickers2", "cols": ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"], "rows": [{}]}}"#, rows2); LogStatus!(format!("`[{},{}]`", tbl1, tbl2)); }
Returns
| Type | Description |
| Array of |
See Also
Remarks
Notes:
-
This function requests the exchange's aggregated market data interface. There is no need to set a trading pair or contract code before calling it, and it only returns market data for trading instruments that are already listed on the exchange.
-
The backtesting system supports this function.
-
Exchange objects that do not provide an aggregated market data interface do not support this function.
-
This function does not support options contracts.
Exchanges that do not support this function: BitFlyer, Coincheck, Gemini, WOO, Futures_WOO, Zaif, Futures_EdgeX, Futures_Aevo, Pendle, Futures_Boros, Uniswap, PancakeSwap, Aerodrome, Velodrome, KyberSwap, OneInch, Jupiter, Exchange, Web3. The call fails with an error and returns null; for all exchanges see Capability Matrix.