# Iceberg/Reserve-Order Replenishment

`D12-F04-A05` · Matching Engines and Venue Logic → Order Lifecycle and Queue State · archetype `record-transform` · difficulty 5/5 · verification **verified**

Full page: https://docs.thefintechbuilder.com/matching-engines-and-venue-logic/order-lifecycle-and-queue-state/iceberg-reserve-order-replenishment/
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 { icebergReplenishment } from "fintech-algorithms/matching-engines-and-venue-logic/order-lifecycle-and-queue-state/iceberg-reserve-order-replenishment";
```

## Signature

```ts
icebergReplenishment(totalRaw, initialRaw, displaySizeRaw, fillsRaw, priorityRaw)
```

Manages a hidden reserve that refills the displayed quantity as it fills. The trap is priority: on most venues each replenishment goes to the **back** of the queue, which is the cost of hiding size.

## Parameters

| Name | Type | Required | Notes |
| --- | --- | --- | --- |
| `totalRaw` | `number` | yes | Total order quantity including the hidden reserve. · min: 1, integer: true |
| `initialRaw` | `number` | yes | Initially displayed quantity. · min: 1, integer: true |
| `displaySizeRaw` | `number` | yes | Quantity displayed on each replenishment. · min: 1, integer: true |
| `fillsRaw` | `Fill[]` | yes | Fills against the displayed portion. |
| `priorityRaw` | `string` | yes | Whether replenishment retains or loses queue priority. |

## Returns

`{ tranches, displayed, reserve_remaining, priority_events, … }`

Each replenishment tranche with its priority consequence.

## Errors

- When the displayed size exceeds the total, or the priority rule is unrecognised — throws

## Complexity

Time `O(fills)`, space `O(tranches)`.

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

`totalRaw`:

```json
1000
```

`initialRaw`:

```json
200
```

`displaySizeRaw`:

```json
200
```

`fillsRaw`:

```json
[100, 200, 250, 300]
```

`priorityRaw`:

```json
10
```

### Call

```ts
icebergReplenishment(totalRaw, initialRaw, displaySizeRaw, fillsRaw, priorityRaw)
```

### Returns

object with 12 fields: model, total_quantity, display_size, executed_quantity, displayed_remaining, reserve_remaining, total_remaining, replenishment_count, …

```json
{
  "model": "zero-displayed-tranche-replenishment",
  "total_quantity": 1000,
  "display_size": 200,
  "executed_quantity": 850,
  "displayed_remaining": 150,
  "reserve_remaining": 0,
  "total_remaining": 150,
  "replenishment_count": 4,
  "current_priority_sequence": 14,
  "unfilled_requested_quantity": 0,
  "events": [
    {
      "type": "fill",
      "fill_request_index": 0,
      "quantity": 100,
      "displayed_remaining": 100,
      "reserve_remaining": 800,
      "priority_sequence": 10
    },
    {
      "type": "fill",
      "fill_request_index": 1,
      "quantity": 100,
      "displayed_remaining": 0,
      "reserve_remaining": 800,
      "priority_sequence": 10
    },
    {
      "type": "replenish",
      "quantity": 200,
      "new_priority_sequence": 11,
      "displayed_remaining": 200,
      "reserve_remaining": 600
    }
  ],
  "state": "displayed-only"
}
```

## Other exports

`limitOrderLifecycle`, `cancelReplacePriority`, `partialFillResidual`, `queuePositionAheadVolume`, `marketableOrderSweep`, `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/matching-engines-and-venue-logic/order-lifecycle-and-queue-state/iceberg-reserve-order-replenishment/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/matching-engines-and-venue-logic/order-lifecycle-and-queue-state/iceberg-reserve-order-replenishment/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/matching-engines-and-venue-logic/llms.txt
