exchange.GetMarkets()
函数用于获取已订阅的交易品种信息。
包含{@struct/Market Market}结构体的字典。
object
exchange.GetMarkets()
/*backtest
start: 2024-07-01 00:00:00
end: 2024-07-07 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/
function main() {
var arrSymbol = ["rb2501", "MA888", "i2501", "p2501", "TA501"]
var tbl = {type: "table", title: "test markets", cols: ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], rows: []}
for (var i = 0; i < 10; i++) {
if (exchange.IO("status")) {
for (var symbol of arrSymbol) {
exchange.SetContractType(symbol)
}
var markets = exchange.GetMarkets()
for (var symbol in markets) {
var market = markets[symbol]
tbl.rows.push([symbol, 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(_D(), "\n", "`" + JSON.stringify(tbl) + "`")
return
}
Sleep(1000)
}
}
'''backtest
start: 2024-07-01 00:00:00
end: 2024-07-07 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
'''
import json
def main():
arrSymbol = ["rb2501", "MA888", "i2501", "p2501", "TA501"]
tbl = {"type": "table", "title": "test markets", "cols": ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"], "rows": []}
for i in range(10):
if exchange.IO("status"):
for symbol in arrSymbol:
exchange.SetContractType(symbol)
markets = exchange.GetMarkets()
for symbol in markets:
market = markets[symbol]
tbl["rows"].append([symbol, 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(_D(), "\n", "`" + json.dumps(tbl) + "`")
return
Sleep(1000)
/*backtest
start: 2024-07-01 00:00:00
end: 2024-07-07 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/
void main() {
auto arrSymbol = {"rb2501", "MA888", "i2501", "p2501", "TA501"};
json tbl = R"({
"type": "table",
"title": "test markets",
"cols": ["key", "Symbol", "BaseAsset", "QuoteAsset", "TickSize", "AmountSize", "PricePrecision", "AmountPrecision", "MinQty", "MaxQty", "MinNotional", "MaxNotional", "CtVal"],
"rows": []
})"_json;
for (int i = 0; i < 10; i++) {
if (exchange.IO("status") == 1) {
for (const auto& symbol : arrSymbol) {
exchange.SetContractType(symbol);
}
auto markets = exchange.GetMarkets();
for (auto& [key, market] : markets.items()) {
json arrJson = {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"]};
tbl["rows"].push_back(arrJson);
}
LogStatus(_D(), "\n", "`" + tbl.dump() + "`");
return;
}
Sleep(1000);
}
}
在回测系统中调用exchange.GetMarkets()
函数,只返回已经订阅过的合约信息。
exchange.GetMarkets()
函数返回值为一个字典。键名为合约代码,例如:
{
"MA888": {
"AmountPrecision": 1,
"AmountSize": 1,
"BaseAsset": "FUTURES",
"CtVal": 10,
"CtValCcy": "FUTURES",
"MaxNotional": 10000000,
"MaxQty": 1000,
"MinNotional": 1,
"MinQty": 1,
"PricePrecision": 0,
"QuoteAsset": "CNY",
"Symbol": "MA888",
"TickSize": 1
}
// ...
}
exchange.GetMarkets()
函数支持实盘、回测系统。exchange.GetMarkets()
函数只返回已订阅过的品种的相关数据。{@struct/Market Market}
exchange.GetData exchange.GetTickers