Injective Trader
Injective Trader is a professional-grade framework that provides a high-performance, reliable foundation for developing and deploying algorithmic trading strategies on the Injective blockchain. It bridges the gap between algorithmic trading strategies and blockchain execution, eliminating technical barriers. The framework takes care of the heavy lifting - real-time data streaming, order execution, reconnection/recovery, transaction batching, and analytics This frees up traders to focus solely on strategy development rather than blockchain complexities. You can use it to import existing strategies or create new ones that:- Place orders automatically based on your logic
- Monitor markets 24/7 and react to price changes
- Manage risk with built-in limits and safety features
- Handle multiple markets simultaneously
- Provide detailed logs of all trading activity
Core Capabilities
Simplified Strategy Development- No SDK expertise required - focus purely on trading logic
- Rapid strategy deployment with minimal technical overhead
- Event-driven architecture enabling intuitive strategy implementation
- Automated reconnection and recovery mechanisms
- Transaction validation before execution
- Comprehensive error handling and retry logic
- Intelligent transaction batching for cost reduction
- Automatic fee management and optimization
- Multi-account support for scale
- Complete position and PnL tracking
- Risk management capabilities
- Detailed performance analytics
Injective trader transacts assets with real value, as such security is paramount. Be sure to use the following as a security baseline, and also take further measures to protect your assets.
- Never share private keys or commit them to Git.
- Store secrets in a local
.envfile and load via environment variables. - For extra safety, consider using AuthZ to grant trading rights without exposing your main account.
Quick Start (5 minutes)
1. Get Your Injective Account Ready (and Funded)
- Create an account on Injective using Keplr or
injectived. - If using Keplr, export your private key for the
.envfile.- Tip: With AuthZ, you can grant limited permissions to a trading account for better security.
- Fund your account with USDT by sending from another Injective address, or via bridge.injective.network.
- EVM tip: You can derive your
injaddress with the TS SDK and bridge USDT from Ethereum to Injective without even setting up an Injective account.
- EVM tip: You can derive your
2. Download and Setup
injective-trader is not yet compatible with injective-py v1.11.
3. Configure Your Strategy
Edit the preexistingconfig.yaml:
4. Set Your Private Key
Instead of a singleINJECTIVE_PRIVATE_KEY, use bot-scoped environment variables in .env (matches the framework defaults):
5. Run Your Strategy
IDE set up
If you are using VS code or compatible IDEs (such as Cursor), consider adding the following configuration for easy debugging..vscode/launch.json:
Architecture
System Architecture Diagram
Core Design Patterns
- Mediator Pattern: Centralizes communication between components, enabling a decoupled architecture where components interact without direct dependencies.
- Component Pattern: Standardizes lifecycle management (initialize, run, terminate) for all system components, ensuring consistent behavior.
- State Pattern: Manages component lifecycle through well-defined states (Idle, Running, Terminated), providing predictable transitions and error handling.
- Task Management Pattern: Coordinates asynchronous tasks with automated monitoring and recovery, ensuring reliable execution in an event-driven environment.
- Observer Pattern: Enables strategies to react to specific update events through specialized event handlers, creating a flexible strategy development approach.
Key Components
Exchange-Specific Agents- Initializer: Sets up exchange connections, accounts, and markets
- ChainListener: Streams real-time blockchain data with automatic reconnection
- MessageBroadcaster: Handles transaction creation and broadcasting with retry logic
- Liquidator: Monitors and executes liquidations for undercollateralized positions
- MarketManager: Processes market data and maintains orderbook integrity
- AccountManager: Tracks balances, positions, and order state
- StrategyManager: Routes market events to appropriate strategy implementations
- RiskManager: Enforces position limits and risk controls
- TaskManager: Orchestrates and monitors asynchronous task execution
- Market: Represents trading pairs with orderbooks and metadata
- Account: Manages account balances, deposits, and subaccounts
- Positions: Tracks derivative positions with P&L calculations
- Order: Order state tracking with execution history
- Oracle Prices: Real-time price feeds with timestamp tracking
- Strategy Base: Template for implementing custom strategies
- Update Handlers: Event-specific processors for market data events
- Performance Metrics: Statistics and P&L tracking
- Risk Models: Customizable risk management rules
