Type/to search
Built-in Functions
Global
Log
Market
exchange.GetTicker
exchange.GetTickers
exchange.GetDepth
exchange.GetTrades
exchange.GetRecords
exchange.GetMarkets
exchange.GetRawJSON
exchange.SetData
exchange.GetData
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

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.

    javascript
    function 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) }
    python
    def 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"])
    rust
    fn 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 exchange object is a futures exchange object, use the symbol parameter to request the market trade record data of a specific instrument (futures instrument).

    javascript
    function main() { // BTC's USDT-margined perpetual contract var trades = exchange.GetTrades("BTC_USDT.swap") Log(trades) }
    python
    def main(): trades = exchange.GetTrades("BTC_USDT.swap") Log(trades)
    rust
    fn main() { // BTC's USDT-margined perpetual contract let trades = exchange.GetTrades("BTC_USDT.swap").unwrap(); Log!(trades); }

Returns

TypeDescription

Trade array / null value

Trade structure array on success; null value on failure.

Arguments

NameTypeRequiredDescription

symbol

string

No

Instrument code, for example BTC_USDT on a spot exchange object or BTC_USDT.swap on a futures exchange object; the notation (including options) is described in Symbols. If omitted, the recent trades of the current trading pair and contract code are requested.

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.