Skip to main content

Monaco Protocol SDK v1.0.85

Error responses expose their stable code on the new APIError.serverCode, and a deactivated account is refused with ACCOUNT_DEACTIVATED. Account frames add initial margin, withdrawable collateral and realized PnL, and order snapshot rows report origin. Risk-engine money now sits on the 6-decimal USDC grid, a margin limit order resting through the mark is charged as if it filled at the mark, and a perp limit order past the price band is rejected instead of resting. Action items: branch on serverCode / the WebSocket error code (for example ACCOUNT_DEACTIVATED), not on message text; keep margin transfer and allocation amounts to 6 decimal places and order prices at or below 100,000,000 per unit.

Added

APIError.serverCode

APIError.serverCode returns the REST error envelope’s code (for example ACCOUNT_DEACTIVATED or POST_ONLY_WOULD_CROSS), or undefined when there is none. Branch on it instead of the message. See Error Handling.

Initial margin, withdrawable collateral and realized PnL on account frames

sdk.ws.account frames and account snapshot rows may carry initialMarginRequired, withdrawableCollateral and realizedPnl (decimal strings), equal to the margin account’s fields of the same names. withdrawableCollateral is rounded toward zero at 6 decimal places. Absent means unknown, never zero, and the SDK rejects a frame whose present value is not a non-empty string. See WebSockets.

origin on order snapshot rows

Each orders snapshot row (OrderSnapshotItem) may carry origin (USER, LIQUIDATION, ADL, COPY or SYSTEM), as getOrder reports it, and every order event now carries it, USER included. useUserOrders takes origin from snapshot rows and every order frame: a frame fills in a row’s missing origin but never replaces one it holds. See useUserOrders.

React login takes options

useAuth().login(options) now forwards its options to sdk.login, so connectWebSocket: true also works from React. See useAuth.

Changed

Money on the USDC grid

Every stored USD amount in the risk engine — collateral, risk bucket allocations and draws, realized PnL, funding paid, margin requirements and order costs — is a whole number of 0.000001 USD. A published withdrawableCollateral or availableOrderCollateral is exactly what its endpoint accepts, and funding settles zero-sum. Amounts with more than 6 decimals are now refused, with the message <field> exceeds supported precision for USDC (6 decimals), in these cases:
  • a margin transfer between accounts, a copy-trading allocation, or a spot-margin collateral transfer of a USDC variant
  • an order’s riskBucketCollateral
  • a margin order on a market whose quote asset has more than 6 decimals
The order price ceiling is now 100,000,000 per unit. Reported unrealized PnL is the risk engine’s own figure, on the same grid. Request and response shapes are unchanged. See Trade.

Margin through the mark

A margin limit order resting through the mark (a sell below the mark, or a buy above it) is charged at admission as if it filled now: its initial margin at the mark, plus the loss it would take against the mark, plus its maker fee. A sell below the mark was previously under-reserved, and a buy above it over-reserved. availableOrderCollateral and the automatic draw from the parent margin account follow the same rule. An order on its safe side of the mark is unchanged. See Perps.

Perp price band at entry

A perp limit order priced past the band on its aggressive side (a buy above the upper edge, or a sell below the lower edge) is now rejected at entry with INVALID_ORDER (“limit price is outside the price band”). This applies to every time in force, post-only orders and replacements. Deep passive prices are still allowed. A resting perp order that a mark move leaves past the band is cancelled in the same step, with terminalReason PRICE_BAND and its collateral released. See Perp price band.

Fixed

  • ACCOUNT_DEACTIVATED — a deactivated signing account is refused with 403 ACCOUNT_DEACTIVATED on /auth/verify and on any signed request. gRPC carries the same reason in google.rpc.ErrorInfo (domain auth.0xmonaco.com). On the WebSocket, an Error frame with code ACCOUNT_DEACTIVATED arrives on the handshake or on revalidation, and then the socket closes. The SDK stops reconnecting and calls onReauthenticationRequired. See Session loss.
  • Positions snapshot serves live state — the sdk.ws.positions subscribe-time snapshot builds an open position from the same live state its position_update frames carry, under the persisted row’s version. A snapshot taken while persistence lagged (for example just after an hourly funding settlement) no longer replaces newer values a client already holds. On an equal version, a snapshot row now wins on every field (it was isolatedMargin only). No field or wire shape changes. See Positions.
  • Order preview: no-fill IOC — simulateOrderRisk, simulateParentMarginOrderRisk and simulateRiskBucketOrderRisk report an IOC order that would not fill with rejectCode INSUFFICIENT_LIQUIDITY. They previously reported INVALID_ORDER.
  • Order preview: closing an isolated position flat — when that close retires the risk bucket (nothing else resting in it and no live TWAP order holding it open), the preview now reports the risk bucket as closed, with equityAfter, initialMarginRequiredAfter, maintenanceMarginRequiredAfter and freeCollateralAfter all "0". It previously failed. See Margin Accounts.

Upgrade

Treat ACCOUNT_DEACTIVATED as terminal rather than retrying.