exchange.GetTrades

获取当前设置的交易对、合约代码对应的现货或合约的{@struct/Trade Trade}结构数组,即市场的成交数据。

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

exchange.GetTrades() exchange.GetTrades(symbol)

参数symbol用于指定请求的{@struct/Trade Trade}数组数据对应的具体交易对、合约代码。不传该参数时,默认请求当前设置的交易对、合约代码的最近成交记录数据。

当调用exchange.GetTrades(symbol)函数时,若exchange为现货交易所对象,如需请求获取计价币种为USDT、交易币种为BTC的成交数据,参数symbol为:"BTC_USDT",格式为FMZ平台定义的交易对格式。

当调用exchange.GetTrades(symbol)函数时,若exchange为期货交易所对象,如需请求获取BTC的U本位永续合约的成交数据,参数symbol为:"BTC_USDT.swap",格式为FMZ平台定义的交易对合约代码的组合,以字符”.“分隔。

当调用exchange.GetTrades(symbol)函数时,若exchange为期货交易所对象,如需请求获取BTC的U本位期权合约的成交数据,参数symbol为:"BTC_USDT.BTC-240108-40000-C"(以币安期权BTC-240108-40000-C为例),格式为FMZ平台定义的交易对与交易所定义的具体期权合约代码的组合,以字符”.“分隔。 symbol false string


function main(){
    var trades = exchange.GetTrades()
    /*
        可能由于网络原因,无法访问交易所接口(即使托管者程序所在设备能打开交易所网站,API接口也可能无法访问)
        此时trades为null,当访问trades[0].Id时,会导致错误,因此在测试该代码时,请确保能够访问交易所接口
    */
    Log("id:", trades[0].Id, "time:", trades[0].Time, "Price:", trades[0].Price, "Amount:", trades[0].Amount, "type:", trades[0].Type)
}

def main():
    trades = exchange.GetTrades()
    Log("id:", trades[0]["Id"], "time:", trades[0]["Time"], "Price:", trades[0]["Price"], "Amount:", trades[0]["Amount"], "type:", trades[0]["Type"])

void main() {
    auto trades = exchange.GetTrades();
    Log("id:", trades[0].Id, "time:", trades[0].Time, "Price:", trades[0].Price, "Amount:", trades[0].Amount, "type:", trades[0].Type);
}
测试exchange.GetTrades()函数:

function main() {
    // BTC的U本位永续合约
    var trades = exchange.GetTrades("BTC_USDT.swap")
    Log(trades)
}

def main():
    trades = exchange.GetTrades("BTC_USDT.swap")
    Log(trades)

void main() {
    auto trades = exchange.GetTrades("BTC_USDT.swap");
    Log(trades);
}
当配置的exchange对象为期货交易所对象时,使用symbol参数请求特定品种(期货品种)的市场成交记录数据。

exchange.GetTrades()函数获取当前交易对、合约对应的市场交易历史(非自己的交易)。部分交易所不支持该函数,具体返回的数据范围因交易所而异,需根据实际情况处理。返回数据为数组,其中每个元素的时间顺序与exchange.GetRecords()函数的返回数据顺序一致,即数组最后一个元素是距离当前时间最近的数据。 回测系统中,使用模拟级Tick回测时,exchange.GetTrades()函数返回空数组。

回测系统中,使用实盘级Tick回测时,exchange.GetTrades()函数返回的数据为订单流快照数据,即{@struct/Trade Trade}结构数组。 不支持exchange.GetTrades()函数的交易所:

函数名 不支持的现货交易所 不支持的期货交易所
GetTrades Hyperliquid Futures_BitMart / Futures_Bibox / Futures_Hyperliquid / Futures_edgeX

{@fun/Market/exchange.GetTicker exchange.GetTicker}, {@fun/Market/exchange.GetDepth exchange.GetDepth}, {@fun/Market/exchange.GetRecords exchange.GetRecords}