exchange.GetFundings
获取当前周期资金费率数据。
exchange.GetFundings()
exchange.GetFundings(symbol)示例
-
查询资金费率(不传参数时按默认范围)并逐条打印。
javascriptfunction main() { var fundings = exchange.GetFundings() if (!fundings) return for (var f of fundings) { Log(f.Symbol, "费率", f.Rate * 100, "%", "间隔", f.Interval / 3600000, "小时", _D(f.Time)) } // 输出:每个品种一行,依次为品种代码、资金费率(%)、结算间隔(小时)、时间 }pythondef main(): fundings = exchange.GetFundings() if fundings is None: return for f in fundings: hours = f["Interval"] / 3600000 Log(f["Symbol"], "费率", f["Rate"] * 100, "%", "间隔", hours, "小时", _D(f["Time"] / 1000)) # 输出:每个品种一行,依次为品种代码、资金费率(%)、结算间隔(小时)、时间rustfn main() { let Ok(fundings) = exchange.GetFundings(None) else { return }; for f in &fundings { let hours = f.Interval as f64 / 3600000.0; Log!(f.Symbol, "费率", f.Rate * 100.0, "%", "间隔", hours, "小时", _D(f.Time)); } // 输出:每个品种一行,依次为品种代码、资金费率(%)、结算间隔(小时)、时间 } -
使用期货交易所对象,在回测系统中调用
exchange.GetFundings()函数。调用任何行情函数之前,GetFundings只返回当前默认交易对的Funding数据,调用行情函数之后会返回所有请求过的品种的Funding数据。可以参考以下测试例子。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 (var 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 symbols:", 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 Requested symbols:", symbols, "\n`" + json.dumps(tbls) + "`")rust/*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"}] */ fn main() { // LPT_USDT.swap 4小时周期 let 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); } let mut arr: Vec<Vec<Funding>> = Vec::new(); let 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.push(exchange.GetFundings(None).unwrap()); } else { arr.push(exchange.GetFundings(p).unwrap()); } } // Rust SDK 没有JSON序列化,使用format!拼接表格的JSON文本 let mut tbls: Vec<String> = Vec::new(); for (index, fundings) in arr.iter().enumerate() { let mut rows: Vec<String> = Vec::new(); for f in fundings { rows.push(format!(r#"["{}", {}, "{}", "{} %"]"#, f.Symbol, f.Interval as f64 / 3600000.0, _D(f.Time), f.Rate * 100.0)); } let tbl = format!(r#"{{"type": "table", "title": "{}", "cols": ["Symbol", "Interval", "Time", "Rate"], "rows": [{}]}}"#, arrParams[index], rows.join(",")); tbls.push(tbl); } LogStatus!(_D(None), "\n Requested symbols:", format!("{:?}", symbols), format!("\n`[{}]`", tbls.join(","))); }
返回值
| 类型 | 描述 |
| 成功时返回 |
参数
| 名称 | 类型 | 必填 | 描述 |
symbol | string | 否 | 要查询的品种(例如 |
参考
备注
对于不支持批量查询资金费率数据的期货交易所,如果指定symbol参数为查询范围,例如:USDT.swap或者不传symbol参数时接口会报错。使用这类期货交易所对象调用GetFundings()函数必须指定symbol参数为具体某个永续合约品种,才能查询到该品种的当期资金费率数据。
exchange.GetFundings()函数支持实盘、回测系统。
哪些期货交易所不支持批量查询资金费率、必须传入具体品种(例如ETH_USDT.swap),见各交易所页的注意事项(所有交易所的入口见能力矩阵)。
不支持的交易所:Futures_Polymarket、Futures_Futu、Futures_IB。调用时报错并返回空值,所有交易所的对照见能力矩阵。