17. Slippage#

17.1. Synopsis#

SLIPPAGE(
  (<orderbook_expression>),
  {BUY | SELL},
  <float>)

17.2. Description#

SLIPPAGE computes the slippage of a buy or sell order for the given order book.

The function will go through the complete order book. The user must limit the number of levels returned by the ORDERBOOK function in order to limit the slippage computation.

The function works for any valid order book computed by the ORDERBOOK function.

17.3. Parameters#

orderbook_expression

The ORDERBOOK query that will build the order book for which the slippage must be computed.

..note::

The query requires extra () around the ORDERBOOK query, as it is a subquery.

17.4. Examples#

How many BTC would you be able to buy for 1,000,000 USD, as of now:

SLIPPAGE((ORDERBOOK((SELECT * FROM "coinbase/btc_usd/orders_buy", "coinbase/btc_usd/orders_sell" ORDER BY sequence),
  now,
  engine=coinbase,
  product='btc_usd',
  mode=collapsed)), BUY, 1000000)

How many BTC would you be able to sell for 1,000,000 USD, as of now, but going through only the first 100 levels:

SLIPPAGE((ORDERBOOK((SELECT * FROM "coinbase/btc_usd/orders_buy", "coinbase/btc_usd/orders_sell" ORDER BY sequence),
  now,
  engine=coinbase,
  product='btc_usd',
  mode=collapsed,
  max_level=100)), SELL, 1000000)