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 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.

    javascript
    function 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) }
    python
    def main(): depth = exchange.GetDepth() if not depth or len(depth["Asks"]) < 2: return price = depth["Asks"][1]["Price"] Log("Second ask price", price)
    rust
    fn 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 exchange object is a futures exchange object, use the symbol parameter to request the order book data of a specified instrument (futures instrument).

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

Returns

TypeDescription

Depth / null value

Depth structure 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 order book of the current trading pair and contract code is requested.

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.