src/format/types.ts
v0.3.0 · 1.6 KB
/** Numeric input accepted by the format helpers: a JS number or a decimal string (as returned by the API). */
export type Numeric = number | string;
/** Order side. `'B'`/`'A'` is the API's own encoding (bid/ask); `'buy'`/`'sell'` are accepted as aliases. */
export type OrderSide = 'B' | 'A' | 'buy' | 'sell';
/** Market kind: perps (main dex and HIP-3 dexes) or spot pairs. */
export type MarketKind = 'perp' | 'spot';
/** Rounding direction for sizes. */
export type SizeRounding = 'floor' | 'round' | 'ceil';
/**
* Rounding direction for prices.
* - `round` / `floor` / `ceil`: plain directions.
* - `passive`: away from the book (buy -> floor, sell -> ceil). Use for post-only quotes.
* - `aggressive`: toward execution (buy -> ceil, sell -> floor). Use for IoC limit caps.
* `passive` and `aggressive` require `side`.
*/
export type PriceRounding = 'round' | 'floor' | 'ceil' | 'passive' | 'aggressive';
/** Describes the price grid of one asset. */
export interface PriceGridOptions {
/** `szDecimals` of the asset from `meta` / `spotMeta`. */
szDecimals: number;
/** Default `'perp'`. HIP-3 markets (`xyz:TSLA`) are perps. */
market?: MarketKind;
/**
* Allow integer prices regardless of the 5-significant-figure cap (default `true`).
* Only changes the grid for prices >= 100000, where 5 significant figures alone would force a step of 10.
* See `formatPrice` for the risk note.
*/
integerExemption?: boolean;
}
export interface FormatPriceOptions extends PriceGridOptions {
/** Default `'round'`. */
mode?: PriceRounding;
/** Required for `passive` / `aggressive`. */
side?: OrderSide;
}