exchange.GetTrades
Gets the Trade structure array of the spot or futures corresponding to the currently set trading pair and contract code, i.e. the market's trade (tick) data.
exchange.GetTrades()
exchange.GetTrades(symbol)Examples
-
Get recent trades of the current trading pair and print the first one.
javascriptfunction main(){ var trades = exchange.GetTrades() if (!trades || trades.length == 0) return // null on failure, [] when there are no trades var t = trades[0] Log("Id:", t.Id, "Time:", t.Time, "Price:", t.Price, "Amount:", t.Amount, "Type:", t.Type) }pythondef main(): trades = exchange.GetTrades() if not trades: return t = trades[0] Log("Id:", t["Id"], "Time:", t["Time"], "Price:", t["Price"], "Amount:", t["Amount"], "Type:", t["Type"])rustfn main() { let Ok(trades) = exchange.GetTrades(None) else { return }; let Some(t) = trades.first() else { return }; Log!("Id:", t.Id, "Time:", t.Time, "Price:", t.Price, "Amount:", t.Amount, "Type:", t.Type); } -
When the configured
exchangeobject is a futures exchange object, use thesymbolparameter to request the market trade record data of a specific instrument (futures instrument).javascriptfunction main() { // BTC's USDT-margined perpetual contract var trades = exchange.GetTrades("BTC_USDT.swap") Log(trades) }pythondef main(): trades = exchange.GetTrades("BTC_USDT.swap") Log(trades)rustfn main() { // BTC's USDT-margined perpetual contract let trades = exchange.GetTrades("BTC_USDT.swap").unwrap(); Log!(trades); }
Returns
| Type | Description |
|
|
Arguments
| Name | Type | Required | Description |
symbol | string | No | Instrument code, for example |
See Also
Remarks
The exchange.GetTrades() function is used to get the trade history (not your own trades) of the market corresponding to the current trading pair and contract. Some exchanges do not support this function, and the specific range of trade records returned varies from exchange to exchange, which needs to be handled according to the actual situation. The returned data is an array, in which the time order of each element is consistent with the order of the data returned by the exchange.GetRecords() function, i.e. the last element of the array is the data closest to the current time.
In the backtesting system, when backtesting with simulation-level Tick, the exchange.GetTrades() function returns an empty array.
In the backtesting system, when backtesting with **live-trading-level Tick**, the data returned by the exchange.GetTrades() function is order flow snapshot data, i.e. the Trade structure array.
Exchanges that do not support this function: Futures_EdgeX, Pendle, KyberSwap, OneInch, Jupiter, Futures_IB, Web3. The call fails with an error and returns null; for all exchanges see Capability Matrix.