π€ Binance Trading Bot
A powerful, automated C# trading bot for Binance that implements sophisticated moving average strategies with comprehensive risk management features. Built for both beginners and experienced traders looking to automate their trading strategies.
β οΈ IMPORTANT DISCLAIMER
Trading cryptocurrencies involves substantial risk of loss and is not suitable for every investor. This bot is for educational purposes and does not guarantee profits. You can lose money. Always trade responsibly and never invest more than you can afford to lose.
β¨ Features
- π― Automated Trading - Hands-free trading with configurable strategies
- π Moving Average Strategy - Simple yet effective technical analysis
- π‘οΈ Risk Management - Built-in stop-loss and take-profit mechanisms
- π° Balance Monitoring - Real-time account balance tracking
- π Secure API Integration - Safe connection to Binance API
- β‘ Real-time Execution - Fast market order processing
- π Comprehensive Logging - Detailed operation tracking
- ποΈ Configurable Parameters - Customizable trading settings
π Quick Start
Prerequisites
- .NET 5.0 or later
- Binance account with API access
- Basic understanding of cryptocurrency trading
Installation
- Clone the repository
git clone https://github.com/guibranco/binance-trading-bot.git cd binance-trading-bot - Install dependencies
dotnet add package Newtonsoft.Json -
Set up your Binance API credentials
Windows:
setx BINANCE_API_KEY "your_api_key_here" setx BINANCE_API_SECRET "your_api_secret_here"Linux/macOS:
export BINANCE_API_KEY="your_api_key_here" export BINANCE_API_SECRET="your_api_secret_here" - Run the bot
dotnet run
π§ Configuration
API Setup
- Go to Binance API Management
- Create a new API key
- Enable βEnable Tradingβ permission
- Set IP restrictions for enhanced security
- Save your API key and secret securely
Bot Parameters
Customize the bot behavior by modifying these parameters in the code:
private readonly decimal _initialStake = 100m; // Starting amount
private readonly decimal _targetProfitPercent = 0.10m; // 10% profit target
private readonly string _tradingPair = "BTCUSDT"; // Trading pair
private readonly decimal _maxLossPercent = 0.05m; // 5% max loss per trade
private readonly decimal _takeProfitPercent = 0.02m; // 2% take profit per trade
π Trading Strategy
The bot implements a Simple Moving Average Crossover Strategy:
- Buy Signal: When 10-period MA crosses above 30-period MA
- Sell Signal: When 10-period MA crosses below 30-period MA
- Threshold: 0.5% buffer to avoid false signals
Risk Management
- Position Sizing: Uses 90% of available balance
- Stop Loss: Configurable maximum loss percentage
- Take Profit: Automatic profit-taking at target levels
- Market Orders: Fast execution to minimize slippage
π Usage Example
// Initialize the bot
var bot = new BinanceBot(apiKey, apiSecret);
// Start automated trading
await bot.StartBotAsync();
The bot will:
- Monitor the specified trading pair
- Analyze price movements using moving averages
- Execute buy/sell orders based on signals
- Track progress toward profit targets
- Apply risk management rules
π Security Best Practices
- β Never hardcode API credentials in your source code
- β Use environment variables for sensitive information
- β Enable IP restrictions on your Binance API key
- β Start with small amounts for testing
- β Use Binance Testnet for initial development
- β Regularly rotate API keys
π§ͺ Testing
Binance Testnet
Before using real funds, test your bot on Binance Testnet:
- Create testnet account at testnet.binance.vision
- Generate testnet API credentials
- Update the base URL to
https://testnet.binance.vision
Backtesting (Recommended)
Implement backtesting to validate your strategy:
// Example backtesting framework integration
var backtester = new StrategyBacktester();
var results = await backtester.TestStrategy(strategy, historicalData);
π Roadmap
- WebSocket Integration - Real-time data streaming
- Multiple Strategy Support - RSI, MACD, Bollinger Bands
- Portfolio Management - Multi-coin trading
- Advanced Risk Management - Dynamic position sizing
- GUI Interface - User-friendly control panel
- Backtesting Framework - Historical strategy validation
- Notification System - Email/SMS alerts
- Database Integration - Trade history storage
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
β οΈ Risk Warning
Cryptocurrency trading is highly speculative and involves substantial risk of loss. Past performance does not guarantee future results. This software is provided βas isβ without warranty of any kind. The authors are not responsible for any losses incurred through the use of this bot.
π Support
- π§ Email: trading@straccini.com
- π Issues: GitHub Issues
- π Documentation: Wiki
π Show Your Support
Give a βοΈ if this project helped you!