资源加载中... loading...

exchange.GetTickers


```exchange.GetTickers()```函数请求数据成功时返回{@struct/Ticker Ticker}结构数组,请求数据失败时返回空值。
{@struct/Ticker Ticker}数组、空值

exchange.GetTickers()

```javascript
function main() {
    var tickers = exchange.GetTickers()
    if (tickers && tickers.length > 0) {
        Log("交易所中可交易品种个数:", tickers.length)
    }
}
def main():
    tickers = exchange.GetTickers()
    if tickers and len(tickers) > 0:
        Log("交易所中可交易品种个数:", len(tickers))
void main() {
    auto tickers = exchange.GetTickers();
    if (tickers.Valid && tickers.size() > 0) {
        Log("交易所中可交易品种个数:", tickers.size());
    }
}

调用exchange.GetTickers()函数,获取聚合行情数据。

/*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"]
    
    // 请求其它交易对行情数据之前,调用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])
    }
    
    // 请求其它交易对行情数据
    for (var symbol of arrSymbol) {
        exchange.GetTicker(symbol)
    }

    // 再次调用GetTickers
    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]) +  "`")
}
'''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]) +  "`")
/*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"}]
*/

json tickerToJson(const Ticker& ticker) {
    json arrJson;

    arrJson.push_back(ticker.Symbol);
    arrJson.push_back(ticker.High);
    arrJson.push_back(ticker.Open);
    arrJson.push_back(ticker.Low);
    arrJson.push_back(ticker.Last);
    arrJson.push_back(ticker.Buy);
    arrJson.push_back(ticker.Sell);
    arrJson.push_back(ticker.Time);
    arrJson.push_back(ticker.Volume);

    return arrJson;
}

void main() {
    std::string arrSymbol[] = {"ADA_USDT", "LTC_USDT", "ETH_USDT", "SOL_USDT"};
    
    auto tickers1 = exchange.GetTickers();
    json tbl1 = R"({
        "type": "table", 
        "cols": ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"],
        "rows": []
    })"_json;
    tbl1["title"] = "tickers1";
    
    for (const auto& ticker : tickers1) {
        json arrJson = tickerToJson(ticker);
        tbl1["rows"].push_back(arrJson);
    }
    
    for (const std::string& symbol : arrSymbol) {
        exchange.GetTicker(symbol);
    }
    
    auto tickers2 = exchange.GetTickers();
    json tbl2 = R"({
        "type": "table", 
        "cols": ["Symbol", "High", "Open", "Low", "Last", "Buy", "Sell", "Time", "Volume"],
        "rows": []
    })"_json;
    tbl2["title"] = "tickers2";
    
    for (const auto& ticker : tickers2) {
        json arrJson = tickerToJson(ticker);
        tbl2["rows"].push_back(arrJson);
    }
    
    json tbls = R"([])"_json;
    tbls.push_back(tbl1);
    tbls.push_back(tbl2);
    LogStatus("`" + tbls.dump() + "`");
}

使用现货交易所对象,回测系统中调用exchange.GetTickers()函数。调用任何行情函数之前,GetTickers只返回当前默认交易对的ticker数据,调用行情函数之后会返回所有请求过的品种的ticker数据。可以参考以下测试例子:

  • 该函数请求交易所聚合行情接口,调用之前无需设置交易对、合约代码。仅返回交易所上线交易品种的行情数据。
  • 回测系统支持该函数。
  • 未提供聚合行情接口的交易所对象,不支持该函数。
  • 该函数不支持期权合约。

不支持exchange.GetTickers()函数的交易所:

函数名 不支持的现货交易所 不支持的期货交易所
GetTickers Zaif / WOO / Gemini / Coincheck / BitFlyer / Bibox Futures_WOO / Futures_dYdX / Futures_Deribit / Futures_Bibox / Futures_Aevo

{@struct/Ticker Ticker}, {@fun/Market/exchange.GetTicker exchange.GetTicker}

exchange.GetMarkets Trade