Monaco Protocol SDK v0.5.6
Real-Time Balance Updates & API Improvements
This release introduces real-time balance tracking via WebSocket, refines the batch cancel API with two dedicated methods for clearer usage, and improves error handling for vault operations.New Features
Real-Time Balance Updates via WebSocket
Track your account balances in real-time with the new WebSocket balance channel and React hook. Core SDK:- New Method:
sdk.ws.balances()for subscribing to live balance changes - Authenticated Channel: Requires valid JWT token (user-specific updates)
- Detailed Events: Includes available, locked, and total balances (both normalized and raw values)
- Update Reasons: Know why balances changed (lock, unlock, deposit, withdrawal, trade)
- New Hook:
useUserBalances()for real-time balance tracking - Hybrid Approach: Fetches initial balances via REST, then subscribes to WebSocket for live updates
- Manual Refresh: Built-in
refresh()function for on-demand balance reload - Connection Status: Track if WebSocket subscription is active
- Display live balance updates during trading
- Show real-time locked balance as orders execute
- Monitor deposits and withdrawals instantly
- Track fee deductions from trades
- Update balance UI without polling
Batch Cancel API Split
ThebatchCancelOrders() method has been split into two dedicated methods for clearer intent and simpler usage.
What Changed:
- New Method:
batchCancel(orderIds: string[])- Cancel specific orders by ID - New Method:
batchCancelAll(tradingPairId?: string)- Cancel all active orders, optionally filtered by trading pair - Clearer Intent: Method names explicitly indicate what they do
- Simpler Parameters: No more object wrappers - just pass the array or trading pair ID
- Both methods available in
useTrade()hook - Same signatures as Core SDK
batchCancelOrders() calls with the appropriate new method:
- Clearer API: Method names explicitly describe the action
- Simpler Usage: No need to wrap parameters in objects
- Better TypeScript: Type inference works better with direct parameters
- Trading Pair Filter: New capability to cancel all orders for a specific pair
Technical Updates
viem Peer Dependency
Theviem package has been moved from a direct dependency to a peer dependency (version ^2.45.2) in both @0xmonaco/core and @0xmonaco/types packages.
What this means:
- Your application must now install
viemdirectly - Prevents type duplication issues when consuming the SDK
- Ensures consistent
viemversion across your entire application
React Hook Count Correction
Monaco Protocol React SDK now has 14 hooks (not 13 as previously documented):useAuth- AuthenticationuseFees- Fee simulationuseMarket- Market datauseMonacoSDK- SDK instance accessuseOHLCV- Real-time candlesticksuseOrderbook- Real-time orderbookuseProfile- User profileuseTokenLifecycle- Token managementuseTrade- Trading operationsuseTradeFeed- Real-time tradesuseUserBalances- Real-time balances (NEW in v0.5.6)useUserMovements- Account movementsuseUserOrders- Real-time ordersuseVault- Vault operations
Bug Fixes
Proto-Generated API Contract Alignment
This release also fixes several mismatches between the proto-generated API surface and the live service behavior. What Changed:- Implemented gRPC market metadata so the published contract no longer points to an unimplemented endpoint
- Defined gRPC batch order operations for batch create, batch replace, batch cancel, and cancel-all flows in the published contract; server-side handlers remain stubbed and return
UNIMPLEMENTEDin this release - Aligned gRPC market pair filtering with the HTTP API by treating
base_tokenandquote_tokenas token symbols instead of contract addresses - Removed transport-only
sourcefields from account balance and movement responses so generated contracts match the HTTP API - Relaxed generated order
statusquery constraints so comma-separated filters likeFILLED,PARTIALLY_FILLEDremain valid - Replaced a panic path in
get_balance_by_assetwith properinvalid_argumentvalidation for malformed asset UUIDs
Vault Operations: Clear Error When No Account Available
Vault operations now throw a clearInvalidConfigError when the wallet client has no account connected, instead of failing with an unclear error message later in the transaction flow.
What Changed:
Previously, if you initialized the SDK with a wallet client but no account was connected, vault operations would fail with unclear errors during transaction execution. Now, you’ll receive an immediate, actionable error.
- Wallet client is provided to SDK but
accountproperty isundefinedornull - User has disconnected their wallet after SDK initialization
- Wallet client was created without specifying an account
sdk.vault.deposit()sdk.vault.withdraw()sdk.vault.approve()sdk.vault.getAllowance()sdk.vault.needsApproval()
- Earlier Detection: Catch configuration issues before attempting blockchain transactions
- Clearer Errors: Specific error message indicates exactly what’s wrong
- Better DX: Developers can handle this case explicitly and provide better UX
- Actionable Suggestions: Error includes suggestion on how to fix the issue
Internal Improvements
This release includes internal code quality improvements:- Added TypeScript
overridekeywords to error class methods for better type safety - Improved null safety checks in React hooks (
useOHLCV,useUserOrders,useUserBalances) - Simplified network URL resolution logic
- Updated build tooling and linting configuration
Upgrade Instructions
Install New Versions
Migration Steps
1. Ensure viem is installed
2. Update batch cancel calls
Find all occurrences ofbatchCancelOrders() and replace with the appropriate method:
3. (Optional) Add balance tracking
Take advantage of the new real-time balance updates:4. (Optional) Improve vault error handling
Add explicit error handling for vault operations:Testing Recommendations
- Test batch cancel migrations: Verify updated calls work correctly
- Test viem dependency: Ensure your app builds with the peer dependency
- Test balance updates: Verify WebSocket balance subscriptions work in your environment
- Test vault error handling: Confirm improved error messages display correctly
For complete documentation, see the WebSocket API guide, Trading guide, Vault Operations guide, and Error Handling guide.

