exchange.GetTrades
Get the Trade structure array for the currently set trading pair or contract code, i.e., the market transaction data for spot or futures.
exchange.GetTrades()
exchange.GetTrades(symbol)Examples
-
Test the
exchange.GetTrades()function:javascriptfunction main(){ var trades = exchange.GetTrades() /* Due to network issues, the exchange API may be inaccessible (even if the host device can open the exchange website, the API interface may still be unreachable) In this case, trades will be null, and accessing trades[0].Id will cause an error. Therefore, when testing this code, please ensure the exchange API is accessible */ Log("id:", trades[0].Id, "time:", trades[0].Time, "Price:", trades[0].Price, "Amount:", trades[0].Amount, "type:", trades[0].Type) }pythondef 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"])c++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); } -
When the configured
exchangeobject is a futures exchange object, use thesymbolparameter to request market trade data for a specific instrument (futures contract).javascriptfunction main() { // BTC USDT-margined perpetual contract var trades = exchange.GetTrades("BTC_USDT.swap") Log(trades) }pythondef main(): trades = exchange.GetTrades("BTC_USDT.swap") Log(trades)c++void main() { auto trades = exchange.GetTrades("BTC_USDT.swap"); Log(trades); }
Returns
| Type | Description |
| The |
Arguments
| Name | Type | Required | Description |
symbol | string | No | The parameter When calling the When calling the When calling the |
See Also
Remarks
The exchange.GetTrades() function retrieves the market trading history (not your own trades) for the current trading pair or contract. Some exchanges do not support this function, and the specific range of returned data varies by exchange and needs to be handled according to actual circumstances. The returned data is an array, where the time order of each element is consistent with the order of data returned by the exchange.GetRecords() function, meaning the last element of the array is the data closest to the current time.
In the backtesting system, when using simulated-level Tick backtesting, the exchange.GetTrades() function returns an empty array.
In the backtesting system, when using **real-level Tick** backtesting, the data returned by the exchange.GetTrades() function is order flow snapshot data, i.e., a Trade structure array.
Exchanges that do not support the exchange.GetTrades() function:
| Function Name | Unsupported Spot Exchanges | Unsupported Futures Exchanges |
|---|---|---|
| GetTrades | Hyperliquid | Futures_BitMart / Futures_Bibox / Futures_Hyperliquid / Futures_edgeX |