TypeScript Types
Complete TypeScript type definitions for the WebSocket API.
Subscription Types
type Subscription =
| { type: 'l2Book'; coin: string; nSigFigs?: number; nLevels?: number; mantissa?: number; interval?: string }
| { type: 'l3Book'; coin: string; snapshot?: boolean }
| { type: 'l4Book'; coin: string; snapshot?: boolean }
| { type: 'trades'; coin: string; withSideInfo?: boolean }
| { type: 'candle'; coin: string; interval: string }
| { type: 'l1Book'; coin: string; interval?: string }
| { type: 'allMids' }
| { type: 'impactPrice'; coin: string; notional: string; interval?: string }
| { type: 'orderUpdates'; user: string }
| { type: 'userFills'; user: string; aggregateByTime?: boolean };Client Messages
type ClientMessage =
| { method: 'subscribe'; subscription: Subscription }
| { method: 'unsubscribe'; subscription: Subscription }
| { method: 'ping' }
| { method: 'post'; id: number; request: PostRequest };Server Messages
type ServerMessage =
| { channel: 'subscriptionResponse'; data: ClientMessage }
| { channel: 'l1Book'; data: L1BookData }
| { channel: 'l2Book'; data: L2BookData }
| { channel: 'l3Book'; data: L3BookSnapshot | L3BookUpdates }
| { channel: 'l4Book'; data: L4BookSnapshot | L4BookUpdates }
| { channel: 'allMids'; data: AllMidsData }
| { channel: 'trades'; data: Trade[] }
| { channel: 'candle'; data: Candle }
| { channel: 'impactPrice'; data: ImpactPriceData }
| { channel: 'orderUpdates'; data: OrderUpdate[] }
| { channel: 'userFills'; data: Fill[] }
| { channel: 'post'; data: PostResponse }
| { channel: 'pong' }
| { channel: 'error'; data: { error: string } };HTTP Types
type InfoRequest =
| { type: 'allMids' }
| { type: 'impactPrice'; coin: string; notional: string };
interface ImpactPriceHttpResponse {
buyImpactPx: string | null;
sellImpactPx: string | null;
time: number;
}Common Types
type Side = 'A' | 'B';L1 Book Data
interface L1BookData {
coin: string;
time: number;
bid: Level | null;
ask: Level | null;
}
interface Level {
px: string;
sz: string;
n: number;
}L2 Book Data
interface L2Level {
px: string;
sz: string;
n: number;
}
interface L2BookData {
coin: string;
time: number;
levels: [L2Level[], L2Level[]]; // [bids, asks]
}L3 Book Data
interface L3Order {
user: string;
coin: string;
side: Side;
limitPx: string;
sz: string;
oid: number;
timestamp: number;
}
interface L3BookSnapshot {
coin: string;
time: number;
height: number;
sequence: number;
levels: [L3Order[], L3Order[]];
}
interface L3BookUpdates {
time: number;
height: number;
diffs: SequencedOrderDiff[];
}L4 Book Data
interface L4Order extends L3Order {
triggerCondition: string;
isTrigger: boolean;
triggerPx: string;
isPositionTpsl: boolean;
reduceOnly: boolean;
orderType: 'Market' | 'Limit' | 'Stop Market' | 'Stop Limit' | 'Take Profit Limit' | 'Take Profit Market' | 'Vault Close';
tif?: string;
cloid?: string;
}
interface L4BookSnapshot {
coin: string;
time: number;
height: number;
sequence: number;
levels: [L4Order[], L4Order[]];
}
interface L4BookUpdates {
time: number;
height: number;
orders: OrderStatus[];
diffs: SequencedOrderDiff[];
}
interface OrderStatus {
time: string;
user: string;
status: 'open' | 'filled' | 'canceled' | 'triggered' | 'rejected';
order: L4Order;
}Order Diffs
type RawBookDiff =
| { New: { sz: string } }
| { Update: { origSz: string; newSz: string } }
| 'Remove';
interface OrderDiff {
user: string;
oid: number;
px: string;
coin: string;
side: Side;
rawBookDiff: RawBookDiff;
}
interface SequencedOrderDiff extends OrderDiff {
sequence: number;
}Order Updates
interface OrderUpdate {
order: OrderUpdateInner;
status: string;
statusTimestamp: number;
}
interface OrderUpdateInner {
coin: string;
side: Side;
limitPx: string;
sz: string;
oid: number;
timestamp: number;
origSz: string;
cloid?: string;
}All Mids Data
interface AllMidsData {
mids: Record<string, string>; // coin -> mid price
}Impact Price Data
interface ImpactPriceData {
coin: string;
notional: string;
buyImpactPx: string | null;
sellImpactPx: string | null;
time: number;
}Trades
interface Trade {
coin: string;
side: Side;
px: string;
sz: string;
hash: string;
time: number;
tid: number;
users: [string, string];
sideInfo?: SideInfo[];
}
interface SideInfo {
user: string;
startPos: string;
oid: number;
twapId?: number;
cloid?: string;
}Candles
interface Candle {
t: number; // open time (ms)
T: number; // close time (ms)
s: string; // symbol/coin
i: string; // interval
o: string; // open price
c: string; // close price
h: string; // high price
l: string; // low price
v: string; // volume
n: number; // trade count
}Fills
interface Fill {
coin: string;
px: string;
sz: string;
side: Side;
time: number;
startPosition: string;
dir: string;
closedPnl: string;
hash: string;
oid: number;
crossed: boolean;
fee: string;
builderFee?: string;
tid: number;
cloid?: string;
feeToken: string;
twapId?: number;
liquidation?: Liquidation;
}
interface Liquidation {
liquidatedUser: string;
markPx: string;
method: string;
}