Endpoint Details
- URL:
wss://api.mobula.io - Event Type:
positions(plural)
Subscription Format
Thepositions endpoint allows you to subscribe to all positions of a specific wallet on a blockchain, providing real-time updates whenever any trade occurs on any of the wallet’s tokens.
Subscribe to All Wallet Positions
Parameters
wallet(required): The wallet address to track. Addresses will be automatically checksummedblockchain(optional, default:"evm:1"): Blockchain identifier (e.g.,"evm:1"for Ethereum,"evm:56"for BSC,"solana:solana"for Solana)subscriptionId(optional): Custom identifier for your WebSocket connection. Auto-generated if not providedsubscriptionTracking(optional, default:false): Include subscription details in response logs for debugging
Difference from
position stream: The positions (plural) stream tracks all tokens in a wallet automatically, while position (singular) tracks only one specific token. Use positions for portfolio monitoring and position for single-token tracking.Update Flow
Initial Snapshot
Upon subscription, you receive a complete snapshot of all current positions (with balance > 0):Real-Time Updates
After the initial snapshot, you receive incremental updates whenever:- A trade occurs on any market involving one of the tracked tokens
- Position balance changes (buy/sell)
- Price updates affect unrealized P&L
Position Fields
| Field | Type | Description |
|---|---|---|
wallet | string | Wallet address |
token | string | Token contract address |
chainId | string | Blockchain identifier |
balance | number | Current token balance (formatted) |
rawBalance | string | Raw balance (with decimals as string) |
amountUSD | number | Current value in USD |
buys | number | Total number of buy transactions |
sells | number | Total number of sell transactions |
volumeBuyToken | number | Total volume bought (in token units) |
volumeSellToken | number | Total volume sold (in token units) |
volumeBuy | number | Total volume bought (in USD) |
volumeSell | number | Total volume sold (in USD) |
avgBuyPriceUSD | number | Average buy price in USD |
avgSellPriceUSD | number | Average sell price in USD |
realizedPnlUSD | number | Realized profit/loss in USD |
unrealizedPnlUSD | number | Unrealized profit/loss in USD |
totalPnlUSD | number | Total profit/loss (realized + unrealized) |
firstDate | string | null | Date of first trade |
lastDate | string | null | Date of most recent trade |
tokenDetails | object | Token metadata (name, symbol, logo, price, etc.) |
Automatic Filtering
Quote Token Filtering: Native tokens (ETH, SOL, etc.) and stablecoins used as quote tokens are automatically filtered out from the positions list to focus on actual trading positions.
- Only positions with
balance > 0are included - Historical data from database + real-time RPC balance checks
- 10-second Redis cache for high-frequency updates
Data Sources
- Historical Data: Loaded from database (trade history, P&L calculations)
- Real-Time Balances: Fetched from RPC nodes for accurate current balances
- Redis Cache: 10-second TTL cache for frequently updated positions
- PubSub Feed: Real-time swap events trigger position updates
Performance Metrics
- Initial Load: ~200-500ms depending on number of positions
- Update Latency: Less than 100ms from swap execution to client update
- Cache Hit Rate: ~95% for active trading sessions
Example Implementation
Use Cases
Portfolio Monitoring
Track all positions of a wallet in real-time for portfolio management dashboards
Risk Management
Monitor exposure across all tokens with instant P&L updates
Trading Bots
Build automated trading strategies based on complete position data
Analytics
Analyze trading performance across multiple tokens in real-time
Error Handling
Common Errors
Best Practices
- Reconnection: Implement exponential backoff for reconnections
- Subscription Tracking: Use
subscriptionTracking: trueto confirm subscriptions - Duplicate Detection: Use deterministic
subscriptionIdto avoid duplicate subscriptions - Memory Management: Unsubscribe when no longer needed to free resources
Rate Limits
- Max Concurrent Subscriptions: 100 per connection
- Rate Limiting: Standard WebSocket rate limits apply
- Position Limit: No limit on number of positions per wallet
Related Streams
Position Stream (Single Token)
Track a single token position for a wallet
Fast Trades
Real-time trade feed for specific tokens
Holders Stream
Monitor token holder analytics
Token Details
Real-time token metadata updates
FAQ
What's the difference between 'position' and 'positions' streams?
What's the difference between 'position' and 'positions' streams?
position(singular): Tracks one specific token for a wallet. You need to specify both wallet and token address.positions(plural): Tracks all tokens for a wallet automatically. You only specify the wallet address, and all positions are tracked.
positions for portfolio monitoring and position for focused single-token tracking.Are native tokens (ETH, SOL) included in positions?
Are native tokens (ETH, SOL) included in positions?
No, native tokens and stablecoins used as quote tokens are automatically filtered out to focus on actual trading positions (base tokens).
How quickly are updates sent after a trade?
How quickly are updates sent after a trade?
Updates are typically delivered within 100ms of trade execution, thanks to our optimized PubSub feed and Redis caching layer.
Can I track positions across multiple blockchains?
Can I track positions across multiple blockchains?
You need separate subscriptions for each blockchain. Each
positions subscription tracks all tokens for a wallet on one specific chain.What happens when a position goes to zero?
What happens when a position goes to zero?
Positions with zero balance are automatically removed from the positions list in subsequent updates.