# Price bands

How a Pair's price band limits how far from the market an order can be priced or trade, and what happens to each order type at the band.

> **In development, coming soon**
>
> Price bands are in development, coming soon. No Pair carries a band yet, so `priceBand` is absent from every Pair. This page describes how bands work once they are turned on; the fields and codes below are already in the API, so you can handle them now.

A price band limits how far from the market an order on a Pair can be priced or trade. The band is measured from a reference price that follows the Pair's trades. A limit order priced beyond the band is refused. A market order, or another order whose price Polyester sets, trades up to the band and its unfilled remainder is canceled. The band never cancels an order that is already resting.

## Read a Pair's band

Each Pair's band is returned by [`MarketDataService.GetSpotConfig`](https://testnet.polyester.com/docs/api-docs/connect/marketdata.v1.MarketDataService/GetSpotConfig) ([`GET /v1/spot/config`](https://testnet.polyester.com/docs/api-docs/rest/GET/v1/spot/config)) as the Pair's `priceBand`:

- **`lowerBps`**: how far below the reference price a sell may be priced or trade, in basis points (1 bp = 0.01%).
- **`upperBps`**: how far above the reference price a buy may be priced or trade, in basis points.
- **`referenceWindowMs`**: how long the reference price stays fixed before it can move to a newer trade, in milliseconds. `0` lets it move with every order.

```json
{
	"pairs": [
		{
			"symbol": "BTC-USDT",
			"tickSize": "0.01",
			"priceBand": { "lowerBps": 500, "upperBps": 500, "referenceWindowMs": 60000 }
		}
	]
}
```

*These are example values. Read the current band for each Pair rather than hardcoding it.*

`priceBand` is absent on a Pair that has no band, and orders on that Pair are not checked against one. Only a Pair that publishes an index price can have a band.

## The band's limits

With reference price `R` and the Pair's tick size `T`:

```text
lower limit = R * (1 - lowerBps / 10,000), rounded up to a multiple of T
upper limit = R * (1 + upperBps / 10,000), rounded down to a multiple of T
```

Both limits are inside the band. With `R` = `100`, `lowerBps` = `500`, `upperBps` = `250`, and a tick size of `0.01`, the lower limit is `95.00` and the upper limit is `102.50`.

Each order works with the limits in force when it arrives. They stay the same for the whole of its match, even when its own fills are new trades.

## The reference price

- **Its starting point.** When a Pair's band is turned on, the reference price is the Pair's last trade price, or its listing reference price if it has never traded. A Pair with a band always has a reference price.
- **It follows trades.** Whenever the Pair handles a request (an order, a modify, or a cancel) or fires triggers, and at least `referenceWindowMs` have passed since the reference price was set, it moves to the latest trade price, if the Pair has traded since.
- **The index price keeps it honest.** If the price it would move to lies outside the band measured around the Pair's index price, the reference price moves to the index price instead, rounded down to the tick size. While the Pair has no current index price, the reference price follows trades only.

The reference price itself is not published. The last trade price is a close estimate, so `last * (1 + upperBps / 10,000)` and `last * (1 - lowerBps / 10,000)` predict most refusals. The two can differ for up to `referenceWindowMs`, and after the reference price moves to the index price, so handle `PRICE_BAND_VIOLATION` even when your estimate passes.

## Rules for each order type

### Limit orders

- **Beyond the band.** A buy priced above the upper limit, or a sell priced below the lower limit, is refused with `PRICE_BAND_VIOLATION`.
- **Away from the market.** A buy priced below the band, or a sell priced above it, is accepted and rests. The band does not limit how far from the market you can rest an order.
- **Inside the band.** The order trades as usual, up to its limit price.
- **Fill-or-kill.** A fill-or-kill order that the band would stop short of its full quantity is refused whole with `PRICE_BAND_VIOLATION`.
- **Pegged entry price.** A pegged order's derived price is checked like any limit price.
- **Preview.** [`PreviewOrder`](https://testnet.polyester.com/docs/developer-docs/shared-concepts/preview-order#a-limit-price-past-the-price-band) checks a limit price against the band the Pair last published. A price beyond it previews `admissible: false` with `PRICE_BAND_VIOLATION`, and the rejection's `price_band_limit_ticks` (REST `priceBandLimit`) is the limit: the upper limit for a buy, the lower limit for a sell. `CreateOrder` checks the band again.

### Market orders

A market order is never refused because of its price. It trades up to the band's limit (a buy up to the upper limit, a sell down to the lower limit) and up to its own slippage boundary, whichever comes first.

- When the band stops it while liquidity within its slippage boundary remains, its unfilled remainder is canceled with `PRICE_BAND`.
- When its slippage boundary, the book, or the maximum market quantity stops it first, its remainder is canceled with `MARKET_REMAINDER`, as without a band.

Fills before the cancel stand, and the remaining reserved funds are released. The same applies to a buy sized by quote amount.

### Resting orders

The band never cancels a resting order, even when the reference price moves past its price. An order the band has left behind stays on the book, but nothing trades with it while it is outside the band. While it is the best price on its side, an incoming order stops at it: the remainder of a market order, or of a limit order that crosses it, is canceled with `PRICE_BAND` rather than trade past the band or rest crossed.

### Modifies and batches

- **An amend is always allowed.** A modify that keeps the price, does not raise the total quantity, and keeps the client order ID changes the order in place and is never checked against the band.
- **A replace is checked.** A modify that replaces the order (a new price, a larger total quantity, a new client order ID, or `REPLACE_ONLY`) is checked at the new price like a new limit order. If the band refuses it, the modify fails with `PRICE_BAND_VIOLATION` and the original order is unchanged. See [Amend or replace](https://testnet.polyester.com/docs/developer-docs/shared-concepts/order-types-and-lifecycle#amend-or-replace).
- **A batch item is checked on its own**, exactly as the same single order or modify would be.

### Triggers and strategies

When a trigger fires, the order it places is treated by its type:

- **A limit order** is checked against the band. This covers stop-limit and take-profit-limit orders, and a trailing stop's buy without a slippage cap, which places a limit order at `limit_price_ticks`.
- **An order whose price Polyester sets is not refused.** A market order, a market order turned into an immediate-or-cancel limit order by its slippage cap, and a capped trailing stop's order trade up to the band like a market order. Their remainder past the band is canceled with `PRICE_BAND`.

When the band refuses a trigger's limit order:

- **A standalone trigger fails** with `TRIGGER_FAILURE_REASON_PRICE_BAND_VIOLATION`.
- **An attached take-profit, stop-loss, or trailing stop stays active.** It reports `EVENT_FIRE_REFUSED` with `PRICE_BAND_VIOLATION` and is not fired again until the band moves. The first price through its trigger price after that fires it again. See [Attached TP/SL](https://testnet.polyester.com/docs/developer-docs/shared-concepts/triggers/attached-tp-sl).

Strategies follow the same rules for each order they place:

- **TWAP.** A limit slice outside the band is refused, and the TWAP fails with `PRICE_BAND_VIOLATION`. A market slice trades up to the band, and its remainder is canceled with `PRICE_BAND`. See [TWAP](https://testnet.polyester.com/docs/developer-docs/shared-concepts/triggers/twap).
- **Ladder.** Each level is checked at its own price when it is placed, as a single limit order would be. See [Ladder](https://testnet.polyester.com/docs/developer-docs/shared-concepts/triggers/ladder).

## Codes

ConnectRPC uses the full Protobuf names. REST and SBE use the short names.

- **`PRICE_BAND_VIOLATION`** · 60 · ConnectRPC `ERROR_CODE_PRICE_BAND_VIOLATION`\
  The order or replace was refused: a limit price beyond the band, or a fill-or-kill the band would stop short. Nothing was placed or changed. A preview of such a limit order answers `admissible: false` with this code and `price_band_limit_ticks`. The SBE trade WebSocket sends `RejectCode` `PRICE_BAND_VIOLATION` (60).
- **`PRICE_BAND`** · cancel reason 20 · ConnectRPC `CANCEL_REASON_PRICE_BAND`\
  The band stopped the order: it filled up to the band's limit and its unfilled remainder was canceled. Its fills stand. The SBE trade WebSocket sends `CancelReason` `PRICE_BAND` (20).
- **`PRICE_BAND_VIOLATION`** · trigger failure reason 14 · ConnectRPC `TRIGGER_FAILURE_REASON_PRICE_BAND_VIOLATION`\
  The band refused the order a standalone trigger or a TWAP placed, so the trigger failed.

Every code is listed in the [error catalogue](https://testnet.polyester.com/docs/developer-docs/error-handling/error-codes), and every cancel reason in [Why an order ended](https://testnet.polyester.com/docs/developer-docs/shared-concepts/order-types-and-lifecycle#why-an-order-ended).

## Price bands and slippage protection

[Market order price protection](https://testnet.polyester.com/docs/developer-docs/shared-concepts/market-order-price-protection) and the price band both bound a market order, but they answer different questions:

- **Slippage protection is yours.** Each market order gets its own boundary, from your slippage value or the Pair's default, measured from its reference price when it is placed. It protects you from filling deep in a thin book.
- **The price band is the market's.** Polyester sets it per Pair, it applies to every order, limit or market, and it keeps trades close to the Pair's reference price.
- **The closer one stops the order.** A wide slippage value never lets a market order trade past the band, and the band never widens a narrow slippage value. The cancel reason tells you which one stopped it: `MARKET_REMAINDER` for the slippage boundary, `PRICE_BAND` for the band.

With a reference price of `100` and an upper limit of `102.50`, a market buy with `600` bps of slippage has a boundary of `106`, but it trades no higher than `102.50`.

## For market makers

- **Read the band with the other Pair limits**, at startup and whenever you refresh the Pair configuration, and estimate the limits from the last trade price.
- **Keep aggressive prices inside the band.** A buy above the upper limit or a sell below the lower limit is refused. Quotes far from the market on the passive side are accepted.
- **Reprice with care.** A replace beyond the band fails and leaves the old quote unchanged. Reducing a quote's size in place, and canceling it, always work.
- **Watch quotes the band leaves behind.** They are not canceled, but they do not trade while outside the band and can stop incoming orders at their price. Reprice or cancel them.
- **Do not retry a refusal unchanged.** Treat `PRICE_BAND_VIOLATION` as a sign that your estimate of the reference price is stale, refresh it, and price again.

> **The band lags fast markets**
>
> The reference price moves at most once per `referenceWindowMs`. In a fast move, the band can trail the last trade until the window passes and the next order moves it.
