DeepBook Trading Skill
Overview
DeepBook is a decentralized order book exchange (CLOB DEX) on the Sui blockchain. This skill helps Claude Code use the DeepBook V3 SDK to execute trading operations and query market data.
Quick Start
1. Install Dependencies
pnpm add @mysten/deepbook-v3 @mysten/sui
2. Initialize Client
3. Execute Operations
Use the simplified wrapper interfaces provided by this skill.
Core Functionality
Trading Execution
- Limit Orders: Place limit buy/sell orders with price and quantity
- Market Orders: Execute orders at current market price
- Order Cancellation: Cancel existing orders
- Asset Swaps: Swap between Base and Quote assets
- Flash Loans: Borrow assets for arbitrage opportunities
Market Data Queries
- Order Book: Level 2 order book data with depth control
- Account Information: User positions, open orders, locked balances
- Pool Status: Vault balances, trading parameters, fee information
- Price Feeds: Real-time price data from Pyth oracle
Fund Management
- BalanceManager: Deposit/withdraw funds from exchange
- Balance Checks: Query available balances across coins
- Referral System: Manage referral codes and fee sharing
Advanced Features
- Margin Trading: Leveraged trading with risk management
- Governance: Participate in pool governance and voting
- Admin Functions: Pool creation and parameter adjustment (admin only)
Detailed Documentation
Trading Functions
See Transaction Wrapper Reference for complete trading API.
Query Functions
See Query Wrapper Reference for market data queries.
Flash Loan Functions
See Flash Loan Wrapper Reference for arbitrage strategies.
Fund Management Functions
See Balance Manager Wrapper Reference for fund operations.
Code Templates
Market Maker Template
market-maker.ts - Automated market making with spread control
Arbitrage Bot Template
arbitrage-bot.ts - Flash loan arbitrage between pools
Data Monitor Template
data-monitor.ts - Real-time market data monitoring
Liquidation Bot Template
liquidation-bot.ts - Automated liquidation detection
Portfolio Manager Template
portfolio-manager.ts - Multi-pool portfolio management
Common Task Workflows
Place Limit Order Workflow
- Initialize trading client with SuiClient and address
- Query current market price and order book
- Determine order price and quantity
- Execute
placeLimitOrderwith appropriate parameters - Verify order status using
getOrderoraccountOpenOrders
Execute Flash Loan Arbitrage Workflow
- Identify arbitrage opportunity (price discrepancy between pools)
- Borrow asset using
borrowAssetfrom flash loan pool - Execute profitable trade in target pool
- Return borrowed asset using
returnAsset - Calculate net profit after fees
Fund Management Workflow
- Create BalanceManager for user using
createBalanceManager - Deposit funds into BalanceManager using
deposit - Execute trades using the BalanceManager key
- Withdraw profits using
withdraw - Monitor balances using
checkBalance
Best Practices
Transaction Safety
- Always check transaction fees and gas budget
- Use try-catch blocks for transaction failure handling
- Verify sufficient balances before executing trades
- Set appropriate slippage tolerance for swaps
Data Accuracy
- Regularly update price info objects (max age: 5 minutes)
- Validate pool keys and coin types before queries
- Handle network latency in real-time operations
- Cache frequently accessed data where appropriate
Risk Management
- Monitor account risk ratios for margin trading
- Implement stop-loss mechanisms for automated strategies
- Diversify across multiple pools and assets
- Regular portfolio rebalancing
Error Handling
Common Errors and Solutions
Transaction Failed: Insufficient Balance
Solution: Check account balance using checkBalance before trading
Query Failed: Invalid Pool Key
Solution: Verify pool key exists in config using available pools list
Price Info Object Expired
Solution: Call getPriceInfoObject to refresh price data
Network Connection Issues
Solution: Implement retry logic with exponential backoff
Gas Estimation Errors
Solution: Increase gas budget or simplify transaction complexity
Configuration Reference
Environment Setup
// Mainnet configuration
const mainnetConfig = {
suiClient: new SuiClient({ url: getFullnodeUrl('mainnet') }),
address: '0xYourAddress',
environment: 'mainnet' as const,
};
// Testnet configuration
const testnetConfig = {
suiClient: new SuiClient({ url: getFullnodeUrl('testnet') }),
address: '0xYourTestAddress',
environment: 'testnet' as const,
};
Default Pools and Coins
The skill includes predefined configurations for:
- Mainnet: SUI_USDC, SUI_DBUSDC, DEEP_USDC pools
- Testnet: Test pools with test assets
- Devnet: Development pools for testing
Performance Optimization
Query Optimization
- Batch multiple queries where possible
- Use pagination for large datasets
- Implement client-side caching
- Subscribe to real-time updates for active monitoring
Transaction Optimization
- Combine multiple operations in single transaction
- Use batch processing for high-frequency trading
- Optimize gas usage through transaction batching
- Implement circuit breakers for failed transactions
Security Considerations
Private Key Management
- Never hardcode private keys in source code
- Use environment variables or secure vaults
- Implement key rotation policies
- Use hardware wallets for production funds
Smart Contract Interactions
- Verify contract addresses before interactions
- Audit transaction payloads for correctness
- Implement multi-signature for large transactions
- Regular security audits of trading strategies
Data Privacy
- Encrypt sensitive configuration data
- Secure API keys and access tokens
- Implement access controls for different user roles
- Regular security compliance checks
Troubleshooting Guide
Debugging Transactions
- Check transaction digest for execution details
- Verify input parameters match expected format
- Confirm gas budget is sufficient
- Check network status and RPC endpoint
Debugging Queries
- Validate query parameters and types
- Check network connectivity
- Verify pool and coin configurations
- Test with simplified queries first
Performance Issues
- Monitor network latency
- Check RPC endpoint health
- Optimize query complexity
- Implement rate limiting if needed
References
Official Documentation
Example Code
Community Resources
Last Updated: 2026-01-09 Skill Version: 1.0.0 Compatible with: DeepBook V3 SDK 0.22+, Sui SDK 1.45+