fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Order-Book Slope

Install and import#

bash
npm install fintech-algorithms
ts
import { orderBookSlope } from "fintech-algorithms/market-microstructure/order-book-dynamics/order-book-slope";

Signature#

orderBookSlope(bidPrices, bidSizes, askPrices, askSizes)

How steeply depth accumulates as you move away from the touch. A steep book absorbs size with little price movement; a flat one does not — it is a liquidity measure that the spread alone cannot express.

Parameters#

NameTypeNotes
bidPricesnumber[]Bid prices, best first.
bidSizesnumber[]Sizes aligned with bidPrices.
askPricesnumber[]Ask prices, best first.
askSizesnumber[]Sizes aligned with askPrices.

Returns#

{ bid_slope, ask_slope, slope, asymmetry, … }

Slope per side and combined, with the asymmetry between them.

Errors#

  • When prices and sizes differ in length, or a side is empty — throws

Complexity: time O(levels), space O(1).

Worked example#

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input#

bidPrices
[99.5, 99, 98.5]
bidSizes
[400, 600, 1000]
askPrices
[100.5, 101, 101.5]
askSizes
[300, 700, 1000]

Call#

orderBookSlope(bidPrices, bidSizes, askPrices, askSizes)

Returns#

object with 14 fields: model, level_count, bid_level_count, ask_level_count, midpoint, bid_cumulative_depth, ask_cumulative_depth, bid_local_slopes, …

{
  "model": "naes-skjeltorp-snapshot-slope",
  "level_count": 3,
  "bid_level_count": 3,
  "ask_level_count": 3,
  "midpoint": 100,
  "bid_cumulative_depth": [400, 1000, 2000],
  "ask_cumulative_depth": [300, 1000, 2000],
  "bid_local_slopes": [1198.2929094215954, 30.433603371811753, 19.86797971382265],
  "ask_local_slopes": [1140.7564949312646, 42.42772839686445, 20.269353041374735],
  "bid_slope": 416.1981641690766,
  "ask_slope": 401.1511921231679,
  "order_book_slope": 408.67467814612223,
  "slope_tolerance": 4.161981641690766e-10,
  "state": "steeper-bid"
}

Other exports#

This module also exports depthWeightedMidprice, microprice, orderBookResiliency, hawkesOrderArrival, calculate. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Order-Book Slope — system map

Calculation flow#

Order-Book Slope validation flow
flowchart LR
    A["Question: How quickly does cumulative displayed depth grow as prices move away from the midpoint?"] --> B["Reconstruct one causal book or event state"]
    B --> C["Freeze scope, window, sequence, session, units, and variant"]
    C --> D{"Eligible input?"}
    D -- "No" --> E["Reject with topic-specific reason"]
    D -- "Yes" --> F["Apply the frozen Order-Book Slope relationship"]
    F --> G["Expose intermediate diagnostics and state"]
    G --> H{"Static identity, fitted proxy, or conditional model?"}
    H --> I["Report output with convention and evidence boundary"]

How it works#

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References#

The rest of the Order-Book Dynamics family#