# Depth-at-Distance Profile

`D11-F05-A03` · Market Microstructure → Market-Depth Analytics · archetype `record-transform` · difficulty 3/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/market-microstructure/market-depth-analytics/depth-at-distance-profile/
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 { depthAtDistanceProfile } from "fintech-algorithms/market-microstructure/market-depth-analytics/depth-at-distance-profile";
```

## Signature

```ts
depthAtDistanceProfile(bidsRaw, asksRaw, tickRaw, maxRaw)
```

Depth bucketed by distance from the touch, in ticks. Shows where liquidity actually sits rather than reducing the book to a single number.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `bidsRaw` | `Level[]` | yes | Bid levels. |
| `asksRaw` | `Level[]` | yes | Ask levels. |
| `tickRaw` | `number` | yes | Tick size. · min: 0 |
| `maxRaw` | `number` | yes | Maximum distance in ticks to profile. · min: 0 |

## Returns

`{ profile, max_distance, tick, … }`

Depth per distance bucket on both sides.

## Errors

- When tick size is not positive — throws

## Complexity

Time `O(levels)`, space `O(buckets)`.

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

`bidsRaw`:

```json
[
  {
    "price": 99.99,
    "quantity": 500
  },
  {
    "price": 99.98,
    "quantity": 800
  },
  {
    "price": 99.97,
    "quantity": 1200
  }
]
```

Showing 3 of 5 elements.

`asksRaw`:

```json
[
  {
    "price": 100.01,
    "quantity": 300
  },
  {
    "price": 100.02,
    "quantity": 600
  },
  {
    "price": 100.03,
    "quantity": 1000
  }
]
```

Showing 3 of 5 elements.

`tickRaw`:

```json
0.01
```

`maxRaw`:

```json
4
```

### Call

```ts
depthAtDistanceProfile(bidsRaw, asksRaw, tickRaw, maxRaw)
```

### Returns

object with 8 fields: model, tick_size, max_distance_ticks, bid_profile, ask_profile, included_bid_depth, included_ask_depth, state

```json
{
  "model": "same-side-best-tick-distance-profile",
  "tick_size": 0.01,
  "max_distance_ticks": 4,
  "bid_profile": [
    {
      "distance_ticks": 0,
      "quantity": 500,
      "cumulative_quantity": 500,
      "depth_share": 0.1388888888888889
    },
    {
      "distance_ticks": 1,
      "quantity": 800,
      "cumulative_quantity": 1300,
      "depth_share": 0.2222222222222222
    },
    {
      "distance_ticks": 2,
      "quantity": 1200,
      "cumulative_quantity": 2500,
      "depth_share": 0.3333333333333333
    }
  ],
  "ask_profile": [
    {
      "distance_ticks": 0,
      "quantity": 300,
      "cumulative_quantity": 300,
      "depth_share": 0.09090909090909091
    },
    {
      "distance_ticks": 1,
      "quantity": 600,
      "cumulative_quantity": 900,
      "depth_share": 0.18181818181818182
    },
    {
      "distance_ticks": 2,
      "quantity": 1000,
      "cumulative_quantity": 1900,
      "depth_share": 0.30303030303030304
    }
  ],
  "included_bid_depth": 3600,
  "included_ask_depth": 3300,
  "state": "bid-profile-heavier"
}
```

## Other exports

`cumulativeDepth`, `topNDepthImbalance`, `expectedFillPrice`, `sweepCostAndSlippage`, `liquidityWallConcentration`, `depthDepletionReplenishment`, `marketDepthHeatmap`, `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/market-depth-analytics/depth-at-distance-profile/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-microstructure/market-depth-analytics/depth-at-distance-profile/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-microstructure/llms.txt
