Building on LFG Perp
LFG Perp provides developers with powerful tools to build decentralized trading applications, automated strategies, and custom interfaces for perpetual futures trading.What You Can Build
Trading Bots
Automated strategies that execute trades based on your algorithms and market
conditions
Portfolio Managers
Applications for managing multiple positions, subaccounts, and risk across
markets
Market Makers
High-frequency bots that provide liquidity and capture spreads
Analytics Dashboards
Custom UIs for tracking positions, PnL, funding rates, and market data
Arbitrage Bots
Tools to capitalize on price differences across markets and exchanges
Risk Management Tools
Applications for monitoring margin health, liquidation risks, and exposure
Development Stack
TypeScript/JavaScript SDK
The official@oraichain/lfg-client-js SDK provides:
- Core Features
- Market Data
- Trading
- Account Management
- CompositeClient: Unified interface combining Indexer (read) + Validator (write) - LocalWallet: Wallet management with mnemonic and private key support - SubaccountInfo: Manage multiple trading subaccounts - Type Safety: Full TypeScript support with comprehensive type definitions
Architecture Components
LFG Perp’s architecture consists of three main components:Indexer
Indexer
Purpose: Fast read-only access to market and account dataProvides:
- Orderbooks
- Market prices and statistics
- Account balances and positions
- Trade history
- Funding rate history
Validator
Validator
Purpose: Blockchain interaction for transactionsProvides:
- Order placement
- Order cancellation
- Deposits and withdrawals
- Account queries
- Block information
CompositeClient
CompositeClient
Purpose: Unified SDK that combines both Indexer and ValidatorBenefits:
- Single interface for all operations
- Automatic routing to appropriate endpoint
- Connection management
- Error handling
Development Workflow
1. Setup & Installation
2. Configuration
Choose your network and configure endpoints:3. Wallet Setup
Create or import a wallet:4. Build & Deploy
Implement your trading logic and deploy:Development Environments
- Staging (Testnet)
- Mainnet (Production)
Use for: Development, testing, and experimentation Characteristics:
- Test tokens with no real value - Same features as mainnet - Freely
available test USDC - Safe to experiment
typescript const network = Network.staging();
Common Use Cases
Trading Bot Example
Best Practices
Security
Security
- Never hardcode private keys or mnemonics
- Use environment variables for sensitive data
- Implement proper key management
- Use separate keys for different purposes
Error Handling
Error Handling
- Implement retry logic for network failures
- Handle rate limits gracefully
- Validate responses before processing
- Log errors for debugging
Performance
Performance
- Cache account numbers for faster transactions
- Use WebSocket for real-time data
- Batch operations when possible
- Monitor API rate limits
Testing
Testing
- Always test on staging first
- Use small amounts for initial tests
- Monitor margin health in tests
- Implement automated testing
Resources
Quickstart
Build your first trading bot
SDK Setup
Install and configure the SDK
Trading Guides
Learn trading operations
API Reference
Complete SDK documentation
Community & Support
Ready to start building? Head to the Quickstart
Guide to build your first application!