# Order-Book Slope

`D11-F04-A01` · Market Microstructure → Order-Book Dynamics · archetype `record-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/market-microstructure/order-book-dynamics/order-book-slope/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

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

## Signature

```ts
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

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `bidPrices` | `number[]` | yes | Bid prices, best first. |
| `bidSizes` | `number[]` | yes | Sizes aligned with bidPrices. |
| `askPrices` | `number[]` | yes | Ask prices, best first. |
| `askSizes` | `number[]` | yes | 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

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`:

```json
[99.5, 99, 98.5]
```

`bidSizes`:

```json
[400, 600, 1000]
```

`askPrices`:

```json
[100.5, 101, 101.5]
```

`askSizes`:

```json
[300, 700, 1000]
```

### Call

```ts
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, …

```json
{
  "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

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

## Verification and provenance

Tier: **verified** (via D).

The worked example below is the figure published in this algorithm's article, replayed and asserted by the test suite on every build. The arithmetic cannot drift without the build failing.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/market-microstructure/order-book-dynamics/order-book-slope/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-microstructure/order-book-dynamics/order-book-slope/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-microstructure/llms.txt
