fintech-algorithms

Price-Band Validation

Install and import

bash
npm install fintech-algorithms
ts
import { priceBandValidation } from "fintech-algorithms/matching-engines-and-venue-logic/order-controls/price-band-validation";

Signature

priceBandValidation(side, limit_price_atoms, lower_band_atoms, upper_band_atoms, band_as_of_ns, inclusive)

Checks a limit price against the venue's dynamic price band. Bands move with the reference price, so a valid order becomes invalid moments later — which is why the band's as-of time is part of the check.

Parameters

NameTypeNotes
side"buy" | "sell"Order side, which decides which bound binds.
limit_price_atomsnumberLimit price in atoms.
min: 0 · integer: true
lower_band_atomsnumberLower band in atoms.
min: 0 · integer: true
upper_band_atomsnumberUpper band in atoms.
min: 0 · integer: true
band_as_of_nsnumberNanosecond timestamp the band was published, so a stale band is detectable.
inclusivebooleanWhether prices exactly on the band are accepted.

Returns

{ valid, reason, band_as_of_ns, … }

The verdict with the band version applied.

Errors

  • When the lower band exceeds the upper band — throws

Complexity: time O(1), space O(1).

Worked example

executed 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

side
"buy"
limit_price_atoms
1020000
lower_band_atoms
950000
upper_band_atoms
1050000
band_as_of_ns
1200000000
inclusive
true

Call

priceBandValidation(side, limit_price_atoms, lower_band_atoms, upper_band_atoms, band_as_of_ns, inclusive)

Returns

object with 12 fields: side, limit_price_atoms, lower_band_atoms, upper_band_atoms, band_as_of_ns, inclusive, valid, distance_from_lower_atoms, …

{
  "side": "buy",
  "limit_price_atoms": 1020000,
  "lower_band_atoms": 950000,
  "upper_band_atoms": 1050000,
  "band_as_of_ns": 1200000000,
  "inclusive": true,
  "valid": true,
  "distance_from_lower_atoms": 70000,
  "distance_to_upper_atoms": 30000,
  "violation_atoms": 0,
  "reason": "inside-band",
  "state": "accepted"
}

Other exports

This module also exports tickSizeValidation, selfTradePrevention, cancelOnDisconnect, fatFingerLimit, circuitBreakerTrigger, 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.

Diagrams

Price-Band Validation — system map

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References