Getting Started
Set up and run the Binance Crypto trading strategies.
Prerequisites
- Node.js 18+
- npm or yarn
- Binance account
- TypeScript knowledge (optional)
Installation
# Navigate to project
cd binance-crypto
# Install dependencies
npm install
# Build TypeScript
npm run buildConfiguration
Environment Setup
Create a .env file:
BINANCE_API_KEY=your_api_key
BINANCE_API_SECRET=your_api_secret
BINANCE_TESTNET=trueConfiguration File
Edit config/default.json:
{
"exchange": {
"name": "binance",
"testnet": true,
"recvWindow": 5000
},
"trading": {
"symbols": ["BTCUSDT", "ETHUSDT"],
"timeframe": "1h",
"riskPerTrade": 0.02
},
"strategy": {
"type": "momentum",
"params": {
"rsiPeriod": 14,
"rsiOverbought": 70,
"rsiOversold": 30
}
}
}Running Strategies
Development Mode
# Run with hot reload
npm run devProduction Mode
# Build first
npm run build
# Run production
npm startBacktesting
# Run backtest
npm run backtest -- --symbol BTCUSDT --start 2023-01-01 --end 2024-01-01TypeScript Usage
Creating a Custom Strategy
import { Strategy, Signal, Candle } from './types';
import { RSI, MACD } from './indicators';
export class CustomStrategy implements Strategy {
private rsi: RSI;
private macd: MACD;
constructor(config: StrategyConfig) {
this.rsi = new RSI(config.rsiPeriod);
this.macd = new MACD(config.macdFast, config.macdSlow, config.macdSignal);
}
analyze(candles: Candle[]): Signal | null {
const rsiValue = this.rsi.calculate(candles);
const macdValue = this.macd.calculate(candles);
if (rsiValue < 30 && macdValue.histogram > 0) {
return { type: 'LONG', strength: 'STRONG' };
}
if (rsiValue > 70 && macdValue.histogram < 0) {
return { type: 'SHORT', strength: 'STRONG' };
}
return null;
}
}API Connection Test
# Test API connection
npm run test:connection
# Expected output:
# Connected to Binance API
# Account balance: $10,000.00
# Server time sync: OKProject Scripts
| Script | Description |
|---|---|
npm run dev | Development with hot reload |
npm run build | Compile TypeScript |
npm start | Run compiled strategy |
npm run backtest | Historical backtesting |
npm test | Run tests |
npm run lint | ESLint check |
Troubleshooting
TypeScript Errors
# Clear build cache
rm -rf dist/
npm run buildAPI Issues
| Error | Solution |
|---|---|
| Invalid API key | Check .env file |
| Timestamp error | Sync system time |
| Rate limited | Reduce request frequency |
Next Steps
Last updated on