Skip to main content

Monaco Protocol SDK v1.0.94

This release narrows the production region gate to writes, adds a subscribe-time snapshot to the orderbook channel, and makes the WebSocket client replace a connection that stays open but stops delivering data. Action items: a frontend serving a restricted region can keep reads, the WebSocket API, sign-in and withdrawals working, and should hide only trading; match a refusal on the REGION_RESTRICTED code, not on its message, which changed; pass an onSnapshot to sdk.ws.orderbook to seed the book on subscribe, and keep the REST read for when the channel answers SNAPSHOT_UNAVAILABLE instead.

Changed

The region gate refuses writes only

In production, a caller from a restricted region now keeps every read (GET, HEAD and OPTIONS on any endpoint: market data, balances, positions, orders, withdrawal lists), the WebSocket API, signing in (POST /api/v1/auth/challenge, /auth/verify, /auth/refresh, /auth/revoke) and withdrawing (POST /api/v1/withdrawals). Before, every request but the region status read was refused, and /ws refused the upgrade. Every other write is still refused with HTTP 451 and the error code REGION_RESTRICTED: placing, replacing or cancelling orders, closing positions, deposits (POST /api/v1/sweeper/register), transfers and account changes. The message is now Trading is not available in your region., was Monaco is not available in your region.. gRPC mirrors REST: read RPCs, AuthService Challenge / Verify / Refresh / Revoke and WithdrawalsService.InitiateWithdrawal pass, and other RPCs fail with PERMISSION_DENIED and a google.rpc.ErrorInfo reason REGION_RESTRICTED. GetRegionStatusResponse.restricted from sdk.compliance.getRegionStatus() (GET /api/v1/compliance/region; gRPC ComplianceService.GetRegionStatus) now means trading is unavailable in the caller’s region. Its shape is unchanged. The testnet environments never restrict a region. See Region Status.

@0xmonaco/types is built with TypeScript 7

The package is now built with the native TypeScript 7 compiler, and its @0xmonaco/types/wire declarations (paths, components, operations) are generated in-repo. Every wire schema, path and operation type is the same as in v1.0.93. The declarations still type-check in consumers on TypeScript 5.0 and later.

Added

Orderbook subscribe-time snapshot

sdk.ws.orderbook(pairId, tradingMode, magnitude, qMode, handler, onSnapshot?) takes an optional trailing onSnapshot that receives the current book as soon as you subscribe. It gets an array of one OrderbookEvent, the same shape the live handler gets, read from the matching engine with the top 20 levels per side and grouped and quoted like the live events, so both can share one setter. Its sequence is 0. A market or mode with no book gets []. Each live event restates the whole book, so keep whichever arrived last. When the server cannot read the book it sends a SNAPSHOT_UNAVAILABLE error for the channel and onSnapshot does not fire; the subscription stays active, so seed the book from sdk.orderbook.getOrderbook then, and never block on onSnapshot. @0xmonaco/types declares it as SnapshotHandler<OrderbookEvent> on MonacoWebSocket.orderbook. Raw clients get it as a Snapshot frame on the orderbook channel. See Subscribe-time snapshots and Orderbook.

idleTimeoutMs

MonacoWebSocketConfig gains idleTimeoutMs, how long an open connection may deliver nothing before the client treats it as dead, in milliseconds (default 30000). Pass it in the ws config of new MonacoSDK({ ... }) or to createMonacoWebSocket. See WebSockets.

Fixed

A silent WebSocket reconnects

The WebSocket client now notices a connection that stays open but stops delivering data. If nothing arrives for idleTimeoutMs, not even the Pong to its Ping, the client closes the socket, reconnects and fires onResync. It sends a Ping every 10 seconds, or every third of idleTimeoutMs if that is shorter, so one lost Pong does not drop a live connection. Before, such a socket kept reporting connected while prices, the order book and positions froze. See Heartbeat and keepalive.

Upgrade