Skip to main content

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)
React SDK:
  • 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
Use Cases:
  • 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
Example: WebSocket Balance Subscription
Example: React Hook
Event Structure:
Learn more about WebSocket API →

Batch Cancel API Split

The batchCancelOrders() method has been split into two dedicated methods for clearer intent and simpler usage. What Changed:
Core SDK:
  • 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
React SDK:
  • Both methods available in useTrade() hook
  • Same signatures as Core SDK
Example:
Migration Guide: Replace batchCancelOrders() calls with the appropriate new method:
Why this change:
  • 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
Learn more about trading API →

Technical Updates

viem Peer Dependency

The viem 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 viem directly
  • Prevents type duplication issues when consuming the SDK
  • Ensures consistent viem version across your entire application
Installation:

React Hook Count Correction

Monaco Protocol React SDK now has 14 hooks (not 13 as previously documented):
  1. useAuth - Authentication
  2. useFees - Fee simulation
  3. useMarket - Market data
  4. useMonacoSDK - SDK instance access
  5. useOHLCV - Real-time candlesticks
  6. useOrderbook - Real-time orderbook
  7. useProfile - User profile
  8. useTokenLifecycle - Token management
  9. useTrade - Trading operations
  10. useTradeFeed - Real-time trades
  11. useUserBalances - Real-time balances (NEW in v0.5.6)
  12. useUserMovements - Account movements
  13. useUserOrders - Real-time orders
  14. useVault - 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 UNIMPLEMENTED in this release
  • Aligned gRPC market pair filtering with the HTTP API by treating base_token and quote_token as token symbols instead of contract addresses
  • Removed transport-only source fields from account balance and movement responses so generated contracts match the HTTP API
  • Relaxed generated order status query constraints so comma-separated filters like FILLED,PARTIALLY_FILLED remain valid
  • Replaced a panic path in get_balance_by_asset with proper invalid_argument validation for malformed asset UUIDs

Vault Operations: Clear Error When No Account Available

Vault operations now throw a clear InvalidConfigError 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.
When This Error Occurs: This error is thrown when calling any vault operation if:
  • Wallet client is provided to SDK but account property is undefined or null
  • User has disconnected their wallet after SDK initialization
  • Wallet client was created without specifying an account
Affected Operations:
  • sdk.vault.deposit()
  • sdk.vault.withdraw()
  • sdk.vault.approve()
  • sdk.vault.getAllowance()
  • sdk.vault.needsApproval()
Error Details:
Why This Change:
  • 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
Error Handling Example:

Internal Improvements

This release includes internal code quality improvements:
  • Added TypeScript override keywords 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
These changes have no impact on the public API or usage patterns.

Upgrade Instructions

Install New Versions

Migration Steps

1. Ensure viem is installed

2. Update batch cancel calls

Find all occurrences of batchCancelOrders() 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

  1. Test batch cancel migrations: Verify updated calls work correctly
  2. Test viem dependency: Ensure your app builds with the peer dependency
  3. Test balance updates: Verify WebSocket balance subscriptions work in your environment
  4. 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.