Agent skill
deepbook-trading
Helps Claude Code understand DeepBook V3 SDK usage for order book trading, flash loans, fund management, and market data queries on Sui blockchain. Use when operating DeepBook DEX, executing trading strategies, or querying market data.
Install this agent skill to your Project
npx add-skill https://github.com/RandyPen/sui-eco-skills/tree/main/deepbook-trading
SKILL.md
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
See Basic Setup Example
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
- Basic Setup
- Limit Order Example
- Market Order Example
- Flash Loan Example
Community Resources
Last Updated: 2026-01-09 Skill Version: 1.0.0 Compatible with: DeepBook V3 SDK 0.22+, Sui SDK 1.45+
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
sui-transaction-building
Helps Claude Code understand Sui blockchain transaction building, providing guidelines and examples for Transaction class, commands, input types, gas configuration, and serialization. Use when building blockchain transactions on Sui or when the user mentions transaction building, Transaction class, or Move calls.
sui-keypair-cryptography
Helps Claude Code understand Sui blockchain keypair and cryptography operations, providing guidelines and examples for key generation, signing, verification, address derivation, and multi-signature scheme support. Use when working with cryptography in Sui development or when the user mentions keypairs, cryptography, signing, or verification.
working-with-ferra-dlmm
Helps developers work with the Ferra DLMM SDK for Discrete Liquidity Market Maker operations on Sui blockchain. Provides guidance on SDK initialization, pair creation, liquidity management, token swaps, and position handling. Use when working with DLMM pairs, adding/removing liquidity, creating trading pairs, or performing token swaps in the ferra-sdks monorepo.
deepbook-margin-trading-skill
Guides developers through using DeepBook V3 Margin Trading SDK for leverage trading, borrowing, lending, liquidation operations, and risk management on Sui blockchain. Use when working with DeepBook margin trading, margin pools, margin managers, take profit/stop loss orders, or liquidation functionality.
sui-client
Interact with Sui blockchain using @mysten/sui SDK. Use when building transactions, reading chain data, or managing staking positions on Sui.
cetus-dlmm-interface
Enables Claude to effectively work with the Cetus Dynamic Liquidity Market Maker (DLMM) protocol on Sui blockchain. This skill provides comprehensive knowledge of the DLMM architecture, Move smart contracts, Rust SDK, and development workflows. Claude can assist with building, testing, and modifying DLMM contracts, creating swap simulations, implementing new features, and debugging protocol issues. The skill covers all 15 Move modules, multi-bin architecture, reward distribution, ACL system, and flash swap functionality. Trigger contexts include: working with Sui Move smart contracts for decentralized exchanges, implementing dynamic liquidity management, creating multi-bin AMM protocols, building swap simulations with Rust SDK, modifying DLMM protocol parameters, debugging pool operations, implementing reward systems, and working with Cetus DLMM interface codebase.
Didn't find tool you were looking for?