A 24/7 crypto trading bot powered by DeepSeek AI that makes autonomous trading decisions every 3 minutes. The bot enforces strict risk management, position exclusivity (no hedging), and always uses OCO (stop-loss + take-profit) orders.
- AI-Powered Decisions: Uses DeepSeek AI to analyze market data and make trading decisions
- 24/7 Operation: Runs continuously with 3-minute decision cycles
- Risk Management: Enforces strict risk limits (2% max account risk, 0.5% per trade)
- Position Exclusivity: Never holds both long and short positions on the same symbol
- OCO Orders: All positions include stop-loss and take-profit orders
- Flip Logic: Automatically closes opposite positions before opening new ones
- Comprehensive State: Analyzes prices, indicators, funding, OI, and account data
src/
├── config/
│ ├── config.js # Configuration management
│ └── prompts.js # AI system prompt and tool definitions
├── broker/
│ └── broker.js # Exchange interface with position exclusivity
├── ai/
│ └── deepseek.js # DeepSeek AI integration
├── data/
│ └── stateGenerator.js # Market data and state payload generation
├── trading/
│ └── tradingLoop.js # Main trading loop with cron scheduling
├── utils/
│ └── logger.js # Logging utility
├── index.js # Main application entry point
└── test.js # Test suite
-
Install Dependencies
npm install
-
Configure Environment
cp env.example .env # Edit .env with your API keys and settings -
Set Up Environment Variables
# Required DEEPSEEK_API_KEY=your_deepseek_api_key_here # Optional (with defaults) DEEPSEEK_BASE_URL=https://api.deepseek.com ACCOUNT_VALUE_USD=10000 MAX_ACCOUNT_RISK_PCT=2.0 PER_TRADE_RISK_PCT=0.5 TRADING_ENABLED=false
-
Test the Setup
npm test -
Run the Bot
npm start
| Variable | Description | Default | Required |
|---|---|---|---|
DEEPSEEK_API_KEY |
DeepSeek AI API key | - | Yes |
DEEPSEEK_BASE_URL |
DeepSeek API base URL | https://api.deepseek.com |
No |
ACCOUNT_VALUE_USD |
Account value in USD | 10000 |
No |
MAX_ACCOUNT_RISK_PCT |
Max account risk percentage | 2.0 |
No |
PER_TRADE_RISK_PCT |
Max risk per trade percentage | 0.5 |
No |
TRADING_ENABLED |
Enable actual trading | false |
No |
LOG_LEVEL |
Logging level | info |
No |
- Account Risk: Maximum 2% of account value at risk across all positions
- Per Trade Risk: Maximum 0.5% of account value per individual trade
- Position Exclusivity: Only one direction per symbol (no hedging)
- OCO Orders: All positions must have stop-loss and take-profit orders
The bot uses DeepSeek AI with a comprehensive system prompt that includes:
- Long Signals: Price > EMA20 AND (MACD momentum up OR RSI(7) crosses up from <30)
- Short Signals: Price < EMA20 AND (MACD momentum down OR RSI(7) crosses down from >70)
- Trend Filter: If 4h trend conflicts with intraday bias, halve position size
- Exclusivity: Never hold both long and short on the same symbol
- Flip Logic: Close existing position before opening opposite direction
- Invalidation: Exit positions when invalidation conditions are met
- Size Limits: Respect maximum risk per trade and account
- Funding Filter: Avoid entries when funding is against the trade
- Liquidity Filter: Consider open interest changes
Every 3 minutes, the bot generates a comprehensive state payload including:
- Account Info: Value, balance, PnL, position count
- Current Positions: Symbol, side, size, entry price, PnL, SL/TP
- Market Data: Prices, technical indicators (EMA, RSI, MACD), funding rates
- Risk Metrics: Total risk, account risk percentage, utilization
- Market Microstructure: Open interest, volume, volatility
The AI can execute these functions:
get_positions()- Retrieve current positionsplace_order()- Place new order with OCOclose_position()- Close existing positionmodify_orders()- Adjust stop-loss/take-profitflip_position()- Close and open opposite position atomicallylog_note()- Log decision rationaleset_risk()- Update risk parameters
- Mock Broker: Currently uses mock implementation for testing
- Real Exchange Integration: Replace
src/broker/broker.jswith actual exchange API - Market Data: Replace mock data in
src/data/stateGenerator.jswith real market feeds
# Run all tests
npm test
# Test specific components
node src/test.js- Implement exchange-specific broker in
src/broker/ - Update configuration in
src/config/config.js - Add exchange-specific market data in
src/data/stateGenerator.js
- Trading Disabled by Default: Set
TRADING_ENABLED=trueto enable - Position Exclusivity: Enforced both in AI prompt and broker code
- Risk Limits: Hard-coded limits prevent excessive risk
- Error Handling: Continues operation despite individual cycle failures
- Graceful Shutdown: Handles SIGINT/SIGTERM signals
The bot logs all activities including:
- Trading cycle execution
- AI decisions and tool calls
- Order placements and modifications
- Position changes
- Error conditions
MIT License - see LICENSE file for details.
This software is for educational purposes only. Trading cryptocurrencies involves substantial risk of loss. Use at your own risk.