Monaco Protocol SDK v0.5.4
Real-Time User Movements & Trade Feed Improvements
This release introduces real-time user movement events via WebSocket and refactors theuseTradeFeed React hook for better performance and shared state management.
New Features
Real-Time User Movements WebSocket
Track real-time user ledger movements (deposits, withdrawals, trades, fees, and balance changes) with the new movements WebSocket channel. Core SDK:- New WebSocket Method:
sdk.ws.movements(handler)for subscribing to authenticated balance change events - New Event Types:
UserMovementEventandUserMovementEventDatafor ledger movement events - Track deposits, withdrawals, trades, fees, locks, and unlocks in real-time
- New Hook:
useUserMovements()with automatic deduplication and configurable history limit - Seamless integration with
MonacoProviderfor automatic connection management - Built-in state management for movement history
- Display real-time balance updates in your UI
- Show live transaction feeds
- Track deposit confirmations instantly
- Monitor trade settlements in real-time
Breaking Changes
useTradeFeed Hook Refactored
The useTradeFeed React hook has been refactored to share WebSocket subscriptions and state across components, improving performance and eliminating duplicate connections.
What Changed:
maxTradesparameter (now fixed at 50 trades)clearErrorfunction
- Shared Subscriptions: Multiple components using the same
tradingPairIdnow share both the WebSocket connection and trade state - Optimized Performance: Initial trades are fetched only once when the first component subscribes
- Automatic Cleanup: Reference-counted subscriptions automatically clean up when the last subscriber unmounts
- TradeFeedProvider: Wrapped by
MonacoProviderto manage shared trade feed subscriptions
maxTrades:
clearError:
Bug Fixes
Core SDK:- Fixed self-referential import in
useOrderbookhook - Fixed circular dependency between provider and hooks modules
- WebSocket now supports multiple handlers per channel, enabling shared subscriptions across consumers
- Subscribe/Unsubscribe messages are only sent on first subscriber and last unsubscriber for each channel
Technical Details
WebSocket Enhancements:- Multiple handlers per channel support
- Improved subscription management
- Better error handling and connection state management
- Reduced message overhead by batching subscribe/unsubscribe operations
TradeFeedProviderautomatically wrapped byMonacoProvider- Shared state management across all trade feed consumers
- Reference counting for automatic resource cleanup
- Optimized initial data fetching
Upgrade Instructions
- Update your dependencies:
-
Update
useTradeFeedusage:- Remove
maxTradesparameter - Remove
clearErrorusage - Handle trade limiting in your UI if needed
- Remove
-
Test WebSocket connections:
- Multiple components with the same
tradingPairIdshould share the same connection - Verify automatic cleanup when components unmount
- Multiple components with the same
-
Explore new movements WebSocket:
- Try the new
sdk.ws.movements()method - Use
useUserMovements()hook in React applications
- Try the new
API Reference
New Types:UserMovementEvent- WebSocket event structure for movementsUserMovementEventData- Detailed movement data including balances, amounts, and references
useTradeFeed- Shared subscription pattern with fixed trade limituseUserMovements- New hook for real-time ledger movements
sdk.ws.movements(handler)- Subscribe to user movement events
For complete documentation, see the WebSocket API reference and React SDK documentation.

