exchange.GetMarkets
Retrieves market information from the exchange.
exchange.GetMarkets()Examples
-
Call example for a futures exchange object.
javascriptfunction main() { var markets = exchange.GetMarkets() if (!markets) return // null on failure var currency = exchange.GetCurrency() // To get the current contract code you can also use the exchange.GetContractType() function var ct = "swap" var key = currency + "." + ct Log(key, ":", markets[key]) }pythondef main(): markets = exchange.GetMarkets() if markets is None: return currency = exchange.GetCurrency() ct = "swap" key = currency + "." + ct Log(key, ":", markets[key])rustfn main() { let markets = exchange.GetMarkets(); let currency = exchange.GetCurrency(); // To get the current contract code you can also use the exchange.GetContractType() function let ct = "swap"; let key = format!("{}.{}", currency, ct); Log!(key, ":", format!("{:?}", markets.get(&key))); } -
In the backtesting system, use the futures exchange object to call the
exchange.GetMarkets()function. Before calling any market data function, GetMarkets only returns the market data of the current default trading pair; after calling a market data function, it returns the market data of all symbols that have already been requested. Refer to the following test example.javascript/*backtest start: 2023-05-10 00:00:00 end: 2023-05-20 00:00:00 period: 1m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ function main() { var arrSymbol = ["SOL_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"] var tbl1 = { type: "table", title: "markets1", cols: ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], rows: [] } var markets1 = exchange.GetMarkets() for (var key in markets1) { var market = markets1[key] tbl1.rows.push([key, market.Symbol, market.BaseAsset, market.QuoteAsset, market.TickSize, market.AmountSize, market.PricePrecision, market.AmountPrecision, market.MinQty, market.MaxQty, market.MinNotional, market.MaxNotional, market.CtVal]) } for (var symbol of arrSymbol) { exchange.GetTicker(symbol) } var tbl2 = { type: "table", title: "markets2", cols: ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], rows: [] } var markets2 = exchange.GetMarkets() for (var key in markets2) { var market = markets2[key] tbl2.rows.push([key, market.Symbol, market.BaseAsset, market.QuoteAsset, market.TickSize, market.AmountSize, market.PricePrecision, market.AmountPrecision, market.MinQty, market.MaxQty, market.MinNotional, market.MaxNotional, market.CtVal]) } LogStatus("`" + JSON.stringify([tbl1, tbl2]) + "`") }python'''backtest start: 2023-05-10 00:00:00 end: 2023-05-20 00:00:00 period: 1m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] ''' import json def main(): arrSymbol = ["SOL_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"] tbl1 = { "type": "table", "title": "markets1", "cols": ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], "rows": [] } markets1 = exchange.GetMarkets() for key in markets1: market = markets1[key] tbl1["rows"].append([key, market["Symbol"], market["BaseAsset"], market["QuoteAsset"], market["TickSize"], market["AmountSize"], market["PricePrecision"], market["AmountPrecision"], market["MinQty"], market["MaxQty"], market["MinNotional"], market["MaxNotional"], market["CtVal"]]) for symbol in arrSymbol: exchange.GetTicker(symbol) tbl2 = { "type": "table", "title": "markets2", "cols": ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], "rows": [] } markets2 = exchange.GetMarkets() for key in markets2: market = markets2[key] tbl2["rows"].append([key, market["Symbol"], market["BaseAsset"], market["QuoteAsset"], market["TickSize"], market["AmountSize"], market["PricePrecision"], market["AmountPrecision"], market["MinQty"], market["MaxQty"], market["MinNotional"], market["MaxNotional"], market["CtVal"]]) LogStatus("`" + json.dumps([tbl1, tbl2]) + "`")rust/*backtest start: 2023-05-10 00:00:00 end: 2023-05-20 00:00:00 period: 1m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ fn marketToJson(key: &str, market: &Market) -> String { format!(r#"["{}", "{}", "{}", "{}", {}, {}, {}, {}, {}, {}, {}, {}, {}]"#, key, market.Symbol, market.BaseAsset, market.QuoteAsset, market.TickSize, market.AmountSize, market.PricePrecision, market.AmountPrecision, market.MinQty, market.MaxQty, market.MinNotional, market.MaxNotional, market.CtVal) } fn main() { let arrSymbol = ["SOL_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"]; // The Rust SDK has no JSON serialization feature; here format! is used to concatenate the table's JSON text let markets1 = exchange.GetMarkets(); let mut rows1: Vec<String> = Vec::new(); for (key, market) in &markets1 { rows1.push(marketToJson(key, market)); } let tbl1 = format!(r#"{{"type": "table", "title": "markets1", "cols": ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], "rows": [{}]}}"#, rows1.join(",")); for symbol in arrSymbol { exchange.GetTicker(symbol); } let markets2 = exchange.GetMarkets(); let mut rows2: Vec<String> = Vec::new(); for (key, market) in &markets2 { rows2.push(marketToJson(key, market)); } let tbl2 = format!(r#"{{"type": "table", "title": "markets2", "cols": ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], "rows": [{}]}}"#, rows2.join(",")); LogStatus!(format!("`[{},{}]`", tbl1, tbl2)); }
Returns
| Type | Description |
object / null value | A dictionary containing |
See Also
Remarks
The return value of the exchange.GetMarkets() function is a dictionary. For spot exchanges, the key is the trading instrument name, in a fixed trading pair format, for example:
json
{
"BTC_USDT" : {...}, // The value is a Market structure
"LTC_USDT" : {...},
...
}
For futures contract exchanges, since the same instrument may have multiple contracts—for example, the BTC_USDT trading pair includes perpetual contracts, quarterly contracts, etc.—the keys in the dictionary returned by the exchange.GetMarkets() function are a combination of the trading pair and the contract code, for example:
json
{
"BTC_USDT.swap" : {...}, // The value is a Market structure
"BTC_USDT.quarter" : {...},
"LTC_USDT.swap" : {...},
...
}
-
The
exchange.GetMarkets()function is supported by both live trading and the backtesting system. -
The
exchange.GetMarkets()function only returns market information for trading instruments that are already listed on the exchange. -
Options: on some futures exchanges that trade options the result includes option contracts, keyed by the pair plus the exchange's option code (such as
ETH_USDT.ETH-25JUN27-2800-C-USDT; the format differs by exchange); whether options are included and the exact key format are given in the "Options" section of each exchange page.
Exchanges that do not support this function: Coincheck, Exchange, Web3. The call fails with an error and returns null; for all exchanges see Capability Matrix.