exchange.GetDepth
Gets the Depth structure, i.e. the order book data, of the spot or contract corresponding to the currently set trading pair and contract code.
exchange.GetDepth()
exchange.GetDepth(symbol)Examples
-
Get the depth of the current trading pair and print the second ask price.
javascriptfunction main(){ var depth = exchange.GetDepth() if (!depth || depth.Asks.length < 2) return // null on failure var price = depth.Asks[1].Price Log("Second ask price", price) }pythondef main(): depth = exchange.GetDepth() if not depth or len(depth["Asks"]) < 2: return price = depth["Asks"][1]["Price"] Log("Second ask price", price)rustfn main() { let Ok(depth) = exchange.GetDepth(None) else { return }; if depth.Asks.len() < 2 { return; } let price = depth.Asks[1].Price; Log!("Second ask price", price); } -
When the configured
exchangeobject is a futures exchange object, use thesymbolparameter to request the order book data of a specified instrument (futures instrument).javascriptfunction main() { // BTC USDT-margined perpetual contract var depth = exchange.GetDepth("BTC_USDT.swap") Log(depth) }pythondef main(): depth = exchange.GetDepth("BTC_USDT.swap") Log(depth)rustfn main() { // BTC USDT-margined perpetual contract let depth = exchange.GetDepth("BTC_USDT.swap").unwrap(); Log!(depth); }
Returns
| Type | Description |
|
|
Arguments
| Name | Type | Required | Description |
symbol | string | No | Instrument code, for example |
See Also
Remarks
In the backtesting system, when backtesting with Simulated-level Tick, all levels of the data returned by the exchange.GetDepth() function are simulated values.
In the backtesting system, when backtesting with Live-level Tick, the data returned by the exchange.GetDepth() function is a second-level depth snapshot.
On-chain swap exchanges (such as Uniswap and Jupiter) have no order book; the depth is derived from quotes at increasing sizes: each level's Amount is the base currency added at that level and its Price is the marginal fill price of that level. Quote sizes and the number of requests are given on the exchange pages, for example Uniswap and Jupiter.
Exchanges that do not support this function: OKX_DEX, Web3. The call fails with an error and returns null; for all exchanges see Capability Matrix.