exchange.GetFundings

exchange.GetFundings()函数用于获取当前周期的资金费率数据。

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

exchange.GetFundings() exchange.GetFundings(symbol)

参数symbol用于设置要查询的交易品种交易品种范围。当不传入symbol参数时,默认以当前交易对、合约代码所在维度范围请求所有品种的当期资金费率数据。 symbol false string

”`javascript /*backtest start: 2024-10-01 00:00:00 end: 2024-10-23 00:05:00 period: 1m basePeriod: 1m exchanges: [{“eid”:“Futures_Binance”,“currency”:“SOL_USDC”}] */

function main() { // LPT_USDT.swap 4小时周期 var symbols = [“SOL_USDT.swap”, “ETH_USDT.swap”, “LTC_USDT.swap”, “SOL_USDC.swap”, “ETH_USDC.swap”, “BTC_USD.swap”, “BTC_USDT.quarter”, “LPT_USDT.swap”] for (var symbol of symbols) { exchange.GetTicker(symbol) }

var arr = []
var arrParams = ["no param", "LTC_USDT.swap", "USDT.swap", "USD.swap", "USDC.swap", "USDT.futures", "BTC_USDT.quarter"]
for (p of arrParams) {
    if (p == "no param") {
        arr.push(exchange.GetFundings())
    } else {
        arr.push(exchange.GetFundings(p))
    }
}

var tbls = []
var index = 0
for (var fundings of arr) {
    var tbl = {
        "type": "table",
        "title": arrParams[index],
        "cols": ["Symbol", "Interval", "Time", "Rate"],
        "rows": [],
    }

    for (var f of fundings) {
        tbl["rows"].push([f.Symbol, f.Interval / 3600000, _D(f.Time), f.Rate * 100 + " %"])
    }
    tbls.push(tbl)
    index++
}

LogStatus(_D(), "\n 已经请求过的行情品种:", symbols, "\n`" + JSON.stringify(tbls) + "`")

} python “‘backtest start: 2024-10-01 00:00:00 end: 2024-10-23 00:05:00 period: 1m basePeriod: 1m exchanges: [{“eid”:“Futures_Binance”,“currency”:“SOL_USDC”}] “’

import json

def main(): # LPT_USDT.swap 4小时周期 symbols = [“SOL_USDT.swap”, “ETH_USDT.swap”, “LTC_USDT.swap”, “SOL_USDC.swap”, “ETH_USDC.swap”, “BTC_USD.swap”, “BTC_USDT.quarter”, “LPT_USDT.swap”] for symbol in symbols: exchange.GetTicker(symbol)

arr = []
arrParams = ["no param", "LTC_USDT.swap", "USDT.swap", "USD.swap", "USDC.swap", "USDT.futures", "BTC_USDT.quarter"]
for p in arrParams:
    if p == "no param":
        arr.append(exchange.GetFundings())
    else:
        arr.append(exchange.GetFundings(p))

tbls = []
index = 0
for fundings in arr:
    tbl = {
        "type": "table",
        "title": arrParams[index],
        "cols": ["Symbol", "Interval", "Time", "Rate"],
        "rows": [],
    }

    for f in fundings:
        tbl["rows"].append([f["Symbol"], f["Interval"] / 3600000, _D(f["Time"]), str(f["Rate"] * 100) + " %"])

    tbls.append(tbl)
    index += 1

LogStatus(_D(), "\n 已经请求过的行情品种:", symbols, "\n`" + json.dumps(tbls) + "`")```

”`cpp /*backtest start: 2024-10-01 00:00:00 end: 2024-10-23 00:05:00 period: 1m basePeriod: 1m exchanges: [{“eid”:“Futures_Binance”,“currency”:“SOL_USDC”}] */

void main() { // LPT_USDT.swap 4小时周期 json arrSymbol = R”([])“_json; std::string symbols[] = {“SOL_USDT.swap”, “ETH_USDT.swap”, “LTC_USDT.swap”, “SOL_USDC.swap”, “ETH_USDC.swap”, “BTC_USD.swap”, “BTC_USDT.quarter”, “LPT_USDT.swap”}; for (const std::string& symbol : symbols) { exchange.GetTicker(symbol); arrSymbol.push_back(symbol); }

std::vector<std::vector<Funding>> arr = {};
std::string arrParams[] = {"no param", "LTC_USDT.swap", "USDT.swap", "USD.swap", "USDC.swap", "USDT.futures", "BTC_USDT.quarter"};
for (const std::string& p : arrParams) {
    if (p == "no param") {
        arr.push_back(exchange.GetFundings());
    } else {
        arr.push_back(exchange.GetFundings(p));
    }
}

json tbls = R"([])"_json;
int index = 0;
for (int i = 0; i < arr.size(); i++) {
    auto fundings = arr[i];

    json tbl = R"({
        "type": "table",
        "cols": ["Symbol", "Interval", "Time", "Rate"],
        "rows": []
    })"_json;
    tbl["title"] = arrParams[index];

    for (int j = 0; j < fundings.size(); j++) {
        auto f = fundings[j];
        // json arrJson = {f.Symbol, f.Interval / 3600000, _D(f.Time), string(f.Rate * 100) + " %"};
        json arrJson = {f.Symbol, f.Interval / 3600000, _D(f.Time), f.Rate};
        tbl["rows"].push_back(arrJson);
    }
    tbls.push_back(tbl);
    index++;
}

LogStatus(_D(), "\n 已经请求过的行情品种:", arrSymbol.dump(), "\n`" + tbls.dump() + "`");

} 使用期货交易所对象,在回测系统中调用exchange.GetFundings()“`函数。在调用任何行情函数之前,GetFundings只返回当前默认交易对的Funding数据;调用行情函数之后会返回所有已请求品种的Funding数据。可以参考以下测试示例:

对于不支持批量查询资金费率数据的期货交易所,如果指定symbol参数为查询范围(例如:USDT.swap)或不传入symbol参数时,接口将报错。使用此类期货交易所对象调用GetFundings()函数时,必须指定symbol参数为具体的永续合约品种,才能查询到该品种的当期资金费率数据。 exchange.GetFundings()函数支持实盘和回测系统。 不支持批量获取资金费率数据的交易所:Futures_Bitget、Futures_OKX、Futures_MEXC、Futures_Deribit、Futures_Crypto。需要传入symbol参数的具体品种代码,例如:ETH_USDT.swap。 不支持exchange.GetFundings()函数的交易所:

| 函数名 | 不支持的现货交易所 | 不支持的期货交易所 | | - | - | - | | GetFundings | – | Futures_DigiFinex |

{@struct/Funding Funding}