For the complete documentation index, see llms.txt. This page is also available as Markdown.

types

All types are derived from the backend API specification (Go → TypeScript via tygo).

Primitive Types

type ChainID = number;       // uint64 - EIP-155 chain ID
type InstanceID = number;    // uint32 - Protocol instance ID
type TokenID = number;       // uint32 - Token ID
type MarketID = number;      // uint32 - Market ID
type PerpetualID = number;   // uint32 - Perpetual ID (smart contract)
type FeeLevelID = number;    // uint32 - Fee level ID
type AccountID = number;     // uint64 - Trading account ID
type OrderID = number;       // uint64 - Order ID
type RequestID = number;     // uint64 - Request ID (idempotency key)
type PositionID = number;    // uint64 - Position ID
type Decimals = number;      // uint8 - Decimal places
type Fraction = number;      // uint32 - Fraction in hundredths
type Micros = number;        // int64 - Value in 10^-6 fractions
type Amount = string;        // Decimal string for large numbers
type Price = number;         // uint64 - Scaled price
type SPrice = number;        // int64 - Signed scaled price
type Size = number;          // uint64 - Scaled size

Scaling

Prices and sizes are scaled integers. Use market config for decimals:


Timestamps

BlockTimestamp

BlockTxTimestamp

BlockTxLogTimestamp


Chain & Protocol

Chain

Token

ProtocolInstance

GasPrice


Context

Context

Top-level payload returned by /pub/context.


Market

Market

MarketConfig

Fee rates are in micros (10^-6 fractions): 1000 = 0.1% = 10 bps. See Fees & fee tiers for how to pick the right entry and compute what an order costs.

MarketState

FundingEvent

at is the point in time the rate applies at, not the one the event was published at. The exchange requires a funding rate to be set shortly before the block it applies to, so:

  • at runs slightly ahead of the chain head (under a minute) for the newest event, and events sit on a regular grid one funding interval apart.

  • Until the block it applies at is reached, at.t of the newest event is an estimate. The event is republished with the exact timestamp once that block arrives, so a funding interval produces two messages on the funding@<chain_id> stream: the rate, then the same rate with its final timestamp. Both carry the same feb, which identifies the interval — treat a repeat of a known feb as an update, not a new funding event.


Order

Order

OrderType

Value
Name
Description

0

Unspecified

1

OpenLong

Open long position

2

OpenShort

Open short position

3

CloseLong

Close long position

4

CloseShort

Close short position

5

Cancel

Cancel order

6

IncreasePositionCollateral

Add margin

7

Change

Modify order

OrderStatus

Value
Name

0

Unspecified

1

Pending

2

Open

3

PartiallyFilled

4

Filled

5

Canceled

6

Expired

7

Failed

8

Untriggered

9

Triggered

10

Executed

OrderFlags

Value
Name
Description

0

GoodTillCancel

Default, stays until filled/canceled

1

PostOnly

Only maker, rejects if would take

2

FillOrKill

Fill entire order or cancel

4

ImmediateOrCancel

Fill what's available, cancel rest

TriggerPriceCondition

Value
Name
Description

0

Unspecified

1

GTELast

Trigger when last price >= trigger

2

LTELast

Trigger when last price <= trigger

3

GTEMark

Trigger when mark price >= trigger

4

LTEMark

Trigger when mark price <= trigger

OrderStatusReason

Value
Name

0

Unspecified

1

AmountExceedsAvailableBalance

2

AccountFrozen

3

CancelExistingInvalidCloseOrders

4

CantChangeCloseOrder

5

ChangeExpiredOrderNeedsNewExpiry

6

ClearingExpiredOrder

7

ClearingFrozenAccountOrder

8

ClearingInvalidCloseOrder

9

ClearingSelfMatchingOrder

10

CloseOrderExceedsPosition

11

CloseOrderPositionMismatch

12

ContractNotOperational

13

CrossesBook

14

ExceedsLastExecutionBlock

15

ForwardingReverted

16

ImmediateOrCancelExecuted

17

ImmediateOrderUnderMinimum

18

InsuficientFundsForRecycleFee

19

InvalidAccountFrozenOrder

20

InvalidExpiryBlock

21

InvalidOrderId

22

MakerOrderFilled

23

MakerOrderSettlementFailed

24

MaximumAccountOrders

25

MaxMatchesReached

26

NoOp

27

OrderBookFull

28

OrderCancelled

29

OrderCancelledByAdmin

30

OrderCancelledByLiquidator

31

OrderChanged

32

OrderDescIdTooLow

33

OrderDoesNotExist

34

OrderForwardingNotAllowed

35

OrderPlaced

36

OrderPostFailed

37

OrderSettlementImpliesInsolvent

38

OrderSizeExceedsAvailableSize

39

PostOrderUnderMinimum

40

PriceOutOfRange

41

RecycleBalanceInsufficientSevere

42

SizeOutOfRange

43

TakerOrderFilled

44

TakerOrderSettlementFailed

45

UnableToCancelOrder

46

UnmatchedLotRemainsInFillOrKill

47

UnspecifiedCollateral

48

UnspecifiedPrice

49

UnspecifiedSize

50

WrongAccountForOrder

51

WrongChainForOrder

52

WrongMarketForOrder

53

PerpetualInsolvent

54

Triggered

55

InvalidAmount

56

InvalidFlags

57

InvalidTriggerOrder

58

WrongTriggerPosition

59

TriggerDescIdTooLow

60

TriggerOrderRequest

61

ValueExceedsMaximum

62

ClearingRemainingOrderLockBeyondBalance

63

PriceSetDuringTriggerExec

64

TriggeredExecutionAttemptsExhausted

65

TriggeredOrderExecuted

66

TriggeredOrderPartiallyFilled

67

TriggeredOrderExpired

68

TriggeredOrderRecoverableFailure

69

OrderExtensionRejected

OrderFailureReason

Present as fr on order events whose sr is OrderPostFailed (36), MakerOrderSettlementFailed (23) or TakerOrderSettlementFailed (44). Those three say where the order failed — posting, or settlement as maker or taker — and fr says why the exchange refused it. Omitted on every other event, and on order snapshots (which carry no sr either).

Value
Name
Meaning

0

Unspecified

The order did not fail, or failed before the exchange evaluated it

1

InsufficientBalance

Account balance is below the collateral, negative-PnL collateral and fee the new position requires

2

InsufficientCollateralIncrease

Available collateral is below what increasing the existing position requires

3

InsufficientCollateralInvert

Available collateral is below what inverting the existing position requires

4

NoPositionToClose

A close order was evaluated against a position that does not exist

5

PerpetualSolvency

Settling at this price would leave the perpetual insolvent

6

NegativePositionValue

Closing or decreasing the position would realise a negative position value

7

ReferencePriceStale

No fresh reference price was available to value the order against

8

ExceedsMaxNegPnlCollat

The negative PnL the order would have to collateralize against the mark price exceeds the limit the order was placed with — the mnp sent on the request, or the market's order_max_neg_pnl_collat_bps if it was omitted. See Placing Orders

9

Other

The order failed for a reason this API version does not publish yet

5 (PerpetualSolvency) only ever accompanies a settlement failure: an order is allowed to rest on the book in that state, so it is never a posting failure.

8 (ExceedsMaxNegPnlCollat) is also settlement-only, and only on a fill that creates, increases or inverts a position — the limit is not evaluated when an order is posted, and a purely reducing fill never collateralizes negative PnL. Each side of a fill is judged against its own limit: a maker whose limit is exceeded is cleared from the book while the taker fills on from other inventory, whereas a taker whose limit is exceeded unwinds the whole settlement and fills nothing. See Placing Orders for both sides in detail.

OrderSpec

An order placement, change or cancellation as the client describes it — the same description on both transports. It is what a WebSocket OrderRequest (mt: 22) carries under its message header, and what the order submission endpoint accepts without one.

Field-by-field semantics, the at-most-once delivery rules and the retry strategy are documented at Placing Orders and apply identically on both transports.

BatchOrderRequest

Several OrderSpecs in one request, each with the meaning it has on its own — the rules on request IDs, retries and at-most-once execution are per order, not per batch. The orders may name different markets and different accounts of the calling wallet, and are handed to the exchange in the order they are listed.

Accepted by the order submission endpoint only. The message type is allocated on both transports, but the WebSocket connection does not currently accept a batch frame — submit orders there one OrderRequest (mt: 22) at a time.

BatchStatusResponse

The answer to a request carrying several operations: one Status per operation, at the position of the operation it answers.

A zero status.code means the operations were judged individually and statuses carries their outcomes. A non-zero status.code means the request was refused before any operation was looked at: nothing was acted on and statuses is empty.

Operations do not share a fate — a batch is not a transaction, and some of it succeeding while the rest is refused is the normal outcome, not an error.


Fill

bfa is non-zero only for fills of orders placed with a builder-bound API key that requested a fee — see Integrations → Builder codes. It follows the account fee onto every fill that changes a position's size, closes included.

LiquiditySide

Value
Name

0

Unspecified

1

Maker

2

Taker


Position

The same shape is used for a position snapshot and for each entry of e, a settlement event. In an event the amount fields report what that event moved rather than the position's standing state, and sr says which kind of event it is and therefore which fields are meaningful.

Fees on a position

fee is the total to charge against this position or event as the corresponding "cost" when computing PnL/ROI, including any builder fee — a position does not report the builder share separately the way trades and account totals do. Its meaning differs between the two forms the type is used in:

Where

fee holds

cfee

Snapshot (a live position)

The entry-side fees still outstanding against the position, proportional to its remaining size. Indicative: the amount was actually charged when the position was opened or increased, and this is the share of it the remaining size carries. It does not include the fee that closing the remaining size will cost, which is not knowable in advance

Always 0

Event that adds size (sr: 17 Increased, 21 Opened, 18 Inverted)

What that fill charged

0

Event that removes size (sr: 13 Closed, 14 Decreased)

The pro-rata entry fees the closed size released plus cfee. Subtract it from the event's realized PnL for a net figure

The fee the close or decrease itself paid

Liquidation / deleverage / unwind (sr: 19, 15, 22)

The entry share released

0 — these are not charged a trading fee

So on an exit, fee - cfee is the entry side and cfee is the exit side. Use fee for PnL; use cfee only when you want to show the two apart.

cfee is reported as zero rather than omitted everywhere it does not apply: on a snapshot, on events that add to a position, and on the exits the exchange does not charge — liquidation, deleveraging, unwinding, and closing a frozen account. Read sr to know which kind of event you are looking at rather than treating a zero cfee as a signal in its own right.

An inversion — an order that crosses through flat and opens the other side — is one fill reported as two events at the same log position: an sr: 13 for the side that closed, carrying its cfee, and an sr: 18 for the side that opened, carrying its entry fee. The contract charges the inversion as a single fee on the full order lot and it is split between the two rows by size, so summing across both is correct and neither double-counts.

PositionType

Value
Name

0

Unspecified

1

Long

2

Short

PositionStatus

Value
Name

0

Unspecified

1

Open

2

Closed

3

Liquidated

4

Deleveraged

5

Unwound

6

Failed

PositionStatusReason

Common values:

Value
Name

13

PositionClosed

14

PositionDecreased

15

PositionDeleveraged

17

PositionIncreased

18

PositionInverted

19

PositionLiquidated

21

PositionOpened

22

PositionUnwound


Account & Wallet

Wallet

Account

AccountEvent

AccountEventType

Value
Name

0

Unspecified

1

Deposit

2

Withdrawal

3

IncreasePositionCollateral

4

Settlement

5

Liquidation

6

TransferToProtocol

7

TransferFromProtocol

8

Funding

9

Deleveraging

10

Unwinding

11

PositionCollateralDecreased

12

LastForwardedDescIdReset

AccountStats

Portfolio

Equity or PnL of a wallet as a time series, served by GET /api/v1/trading/portfolio/:kind/:period. Which of the two chart carries is set by the kind in the request — the shape is the same either way.

ChartPoint


Market Data

L2PriceLevel

L2Book

Snapshot and update are the same shape, distinguished by mt. On an update (mt: 16) a level with o: 0 is a removal. The REST endpoint only ever answers a snapshot, at most 100 levels per side.

Trade

Candle


Profile

RefCode

Announcement


API Keys

Ed25519 per-request-signed API key authentication.

ScopeMask

API key scope bitmask. trade implies read; withdrawals are never permitted via an API key.

ApiKeyPayloadRequest

Requests the EIP-712 message to sign for enrolling an API key.

ApiKeyPayloadResponse

ApiKeyEnrollRequest

Submits the signed enrollment payload; pop_signature is the mandatory Ed25519 proof-of-possession over the typed-data hash.

ApiKeyInfo

Public, non-secret view of an enrolled key.

ApiKeyEnrollResponse

ApiKeySignInRequest

First WebSocket frame for API-key authentication. Extends MessageHeader.