# Gap Classification

`D06-F01-A04` · Price Action and Candlesticks → Candle Foundations · archetype `record-transform` · difficulty 2/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/price-action-and-candlesticks/candle-foundations/gap-classification/
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 { gapClassification } from "fintech-algorithms/price-action-and-candlesticks/candle-foundations/gap-classification";
```

## Signature

```ts
gapClassification(inputs)
```

Classifies full-range, body, or opening gaps in either direction using an explicit tick-scaled minimum distance.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `inputs` | `{ previous: { open: number; high: number; low: number; close: number }; current: { open: number; high: number; low: number; close: number }; tick_size: number; minimum_gap_ticks: number }` | yes | Record containing `previous`, `current`, `tick_size`, and `minimum_gap_ticks` as defined by the topic data contract. |

## Returns

`{ state, gap_direction, gap_type, gap_distance, threshold_distance, open_gap_up, open_gap_down, body_gap_up, body_gap_down, full_range_gap_up, full_range_gap_down, signed_open_gap, previous_close, current_open }`

One classification record with `state` equal to `gap` or `overlap`, plus all directional checks and measured distances.

## Errors

- When either candle is invalid, tick_size is not positive, or minimum_gap_ticks is negative — throws

## Complexity

Time `O(1)`, 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

`inputs`:

```json
{
  "previous": {
    "open": 100,
    "high": 105,
    "low": 99,
    "close": 104
  },
  "current": {
    "open": 106,
    "high": 110,
    "low": 106,
    "close": 109
  },
  "tick_size": 1,
  "minimum_gap_ticks": 1
}
```

### Call

```ts
gapClassification(inputs)
```

### Returns

object with 14 fields: state, gap_direction, gap_type, gap_distance, threshold_distance, open_gap_up, open_gap_down, body_gap_up, …

```json
{
  "state": "gap",
  "gap_direction": "up",
  "gap_type": "full-range",
  "gap_distance": 1,
  "threshold_distance": 1,
  "open_gap_up": true,
  "open_gap_down": false,
  "body_gap_up": true,
  "body_gap_down": false,
  "full_range_gap_up": true,
  "full_range_gap_down": false,
  "signed_open_gap": 2,
  "previous_close": 104,
  "current_open": 106
}
```

## Other exports

`calculate`, `shadowToBodyRatio`, `trendContextFilter`, `doji`, `dragonflyDoji`, `gravestoneDoji`, `marubozu`, `spinningTop`, `hammer`, `hangingMan`, `invertedHammer`, `shootingStar`, `bullishEngulfing`, `bearishEngulfing`, `bullishHarami`, `bearishHarami`, `piercingLine`, `darkCloudCover`, `tweezerTop`, `tweezerBottom`. 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.12.0.
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/price-action-and-candlesticks/candle-foundations/gap-classification/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/price-action-and-candlesticks/candle-foundations/gap-classification/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/price-action-and-candlesticks/llms.txt
