# Lee-Ready Trade Signing

`D11-F01-A03` · Market Microstructure → Trade Classification · archetype `record-transform` · difficulty 3/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/market-microstructure/trade-classification/lee-ready-trade-signing/
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 { leeReady } from "fintech-algorithms/market-microstructure/trade-classification/lee-ready-trade-signing";
```

## Signature

```ts
leeReady(data, config)
```

The standard hybrid: quote test where the trade is away from the midpoint, tick test at it. The classification most empirical microstructure results are built on, so reproducing them requires this rule specifically.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | `ClassificationInput` | yes | Trades with prices, and where the rule needs them, the prevailing quotes. |
| `config` | `ClassificationConfig` | yes | Tolerances and tie-breaking rules. Trades exactly at a quote or unchanged in price are the cases where classifiers differ, so the tie rule is part of the contract. |

## Returns

`{ classifications, summary, diagnostics }`

Per-trade sign with the rule that produced it, plus counts of the unclassifiable cases. Lee-Ready disagrees with its siblings on exactly those, and hiding them would hide the disagreement.

## Errors

- When required quote data is absent for a rule that needs it — reported per trade rather than thrown

## Complexity

Time `O(n)`, space `O(n)`.

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

`data`:

```json
{
  "trades": [
    {
      "id": "T001",
      "sequence": 1,
      "session": "S1",
      "event_time_ms": 1000,
      "available_time_ms": 1025,
      "price": 100.01,
      "size": 100,
      "status": "valid",
      "condition": "regular"
    },
    {
      "id": "T002",
      "sequence": 2,
      "session": "S1",
      "event_time_ms": 2000,
      "available_time_ms": 2025,
      "price": 99.99,
      "size": 125,
      "status": "valid",
      "condition": "regular"
    },
    {
      "id": "T003",
      "sequence": 3,
      "session": "S1",
      "event_time_ms": 3000,
      "available_time_ms": 3025,
      "price": 100,
      "size": 150,
      "status": "valid",
      "condition": "regular"
    }
  ],
  "quotes": [
    {
      "id": "Q001",
      "sequence": 1,
      "event_time_ms": 500,
      "available_time_ms": 520,
      "bid": 99.99,
      "ask": 100.01,
      "status": "valid",
      "source": "SYNTH-NBBO"
    },
    {
      "id": "Q002",
      "sequence": 2,
      "event_time_ms": 1500,
      "available_time_ms": 1520,
      "bid": 99.99,
      "ask": 100.01,
      "status": "valid",
      "source": "SYNTH-NBBO"
    },
    {
      "id": "Q003",
      "sequence": 3,
      "event_time_ms": 2500,
      "available_time_ms": 2520,
      "bid": 99.99,
      "ask": 100.01,
      "status": "valid",
      "source": "SYNTH-NBBO"
    }
  ]
}
```

`config`:

```json
{
  "quote_lag_ms": 0,
  "midpoint_tolerance": 0,
  "zero_tick_mode": "carry"
}
```

### Call

```ts
leeReady(data, config)
```

### Returns

object with 20 fields: state, method, trace, total_valid, classified_count, unknown_count, buy_count, sell_count, …

```json
{
  "state": "ok",
  "method": "lee-ready",
  "trace": [
    {
      "id": "T001",
      "sequence": 1,
      "event_time_ms": 1000,
      "price": 100.01,
      "volume": 100,
      "sign": 1,
      "side": "buy",
      "reason": "above-midpoint",
      "rule": "quote",
      "midpoint": 100,
      "quote_id": "Q001",
      "cumulative_signed_volume": 100
    },
    {
      "id": "T002",
      "sequence": 2,
      "event_time_ms": 2000,
      "price": 99.99,
      "volume": 125,
      "sign": -1,
      "side": "sell",
      "reason": "below-midpoint",
      "rule": "quote",
      "midpoint": 100,
      "quote_id": "Q002",
      "cumulative_signed_volume": -25
    },
    {
      "id": "T003",
      "sequence": 3,
      "event_time_ms": 3000,
      "price": 100,
      "volume": 150,
      "sign": 1,
      "side": "buy",
      "reason": "midpoint-fallback:uptick",
      "rule": "tick-fallback",
      "midpoint": 100,
      "quote_id": "Q003",
      "cumulative_signed_volume": 125
    }
  ],
  "total_valid": 60,
  "classified_count": 60,
  "unknown_count": 0,
  "buy_count": 40,
  "sell_count": 20,
  "buy_volume": 6925,
  "sell_volume": 3425,
  "unknown_volume": 0,
  "signed_volume": 3500,
  "total_volume": 10350,
  "coverage": 1
}
```

Showing 14 of 20 fields.

## Other exports

`tickTest`, `quoteTest`, `studentTCdf`, `bulkVolumeClassification`, `runTopic`. 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: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

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/trade-classification/lee-ready-trade-signing/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/market-microstructure/trade-classification/lee-ready-trade-signing/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/market-microstructure/llms.txt
