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

exchange.GetFundings

The exchange.GetFundings() function is used to obtain the funding rate data for the current period.

The exchange.GetFundings() function returns an array of {@struct/Funding Funding} structures when the data request is successful, and returns a null value when the data request fails. {@struct/Funding Funding} array, null value

exchange.GetFundings() exchange.GetFundings(symbol)

The parameter symbol is used to set the transaction symbol or transaction symbol range to be queried. When the symbol parameter is not passed, the current funding rate data of all instruments will be requested by default in the dimension range of the current trading pair and contract code.

symbol false string

/*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-hour period
    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 Requested market types:", symbols, "\n`" + JSON.stringify(tbls) + "`")
}
'''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-hour period
    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 Requested market types:", symbols, "\n`" + json.dumps(tbls) + "`")
/*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-hour period
    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 Requested market types:", arrSymbol.dump(), "\n`" + tbls.dump() + "`");
}

Use the futures exchange object to call the exchange.GetFundings() function in the backtesting system. Before calling any market function, GetFundings only returns the Funding data of the current default trading pair. After calling the market function, it returns the Funding data of all requested varieties. You can refer to the following test example:

For futures exchanges that do not support batch query of funding rate data, if the symbol parameter is specified as the query range, for example: USDT.swap or the symbol parameter is not passed, the interface will report an error. When calling the GetFundings() function using this type of futures exchange object, you must specify the symbol parameter as a specific perpetual contract type in order to query the current funding rate data of the type. The exchange.GetFundings() function supports real trading and backtesting systems. Exchanges that do not support batch acquisition of funding rate data: Futures_Bitget, Futures_OKX, Futures_MEXC, Futures_Deribit, Futures_Crypto. Need to pass in the symbol parameter with the specific symbol code, for example: ETH_USDT.swap.

Exchanges that do not support the exchange.GetFundings() function:

Function Name Unsupported Spot Exchanges Unsupported Futures Exchanges
GetFundings Futures_DigiFinex

{@struct/Funding Funding}

exchange.GetContractType NetSettings