Check out our code coverage report for more details.
BinanceBot is a multi-component automated trading system developed in .NET 8 to interact with the Binance API. The project is structured into several specialized modules enabling automated trading, machine learning analysis, simulation, and data feeding.
The project consists of 5 main modules:
The core of the automated trading system that implements real-time trading logic.
Features:
- Automated trading with technical indicators (RSI, Moving Averages, Volatility)
- Buy and sell order management
- API data validation with FluentValidation
- Transaction logging and monitoring
- Dependency injection-based architecture
Structure:
Abstraction/: Interfaces for service abstractionBinanceApi/: Binance API client and data modelsCore/: Main business logic (trading, pricing, actions)Utils/: Utilities (filesystem, HTTP, logging)
Complete test suite to validate the main system behavior.
Features:
- Service integration tests
- Unit tests with mocking (Moq)
- Trading logic tests
- Service configuration validation
Experimental analysis and prediction module using machine learning.
Features:
- Predictive model training on historical data
- Market trend analysis
- Integration with Binance real-time data
- AI-based automated decision making
Simulation and backtesting tool to test strategies without financial risk.
Features:
- Potential profit calculation
- Minimum margin simulation
- Strategy backtesting
- Performance analysis without using real funds
Market data feeding and collection service for ML training.
Features:
- Binance historical data collection
- CSV export for analysis
- Continuous dataset feeding
- Data preparation for machine learning
- Visual Studio 2022 or higher
- .NET 8 SDK
- Binance Account with API Key and Secret
- Git for repository cloning
git clone https://github.com/bogardt/BinanceBot.git
cd BinanceBotCreate an appsettings.json file in the root folder with your Binance keys:
{
"AppSettings": {
"Binance": {
"ApiKey": "your_binance_api_key",
"ApiSecret": "your_binance_secret"
}
},
"ConnectionStrings": {},
"Logging": {
"LogLevel": {
"Default": "Information"
}
}
}# Via Visual Studio
1. Open BinanceBot.sln
2. Set BinanceBot as startup project
3. Press F5 or Ctrl+F5
# Via command line
cd BinanceBot
dotnet run# Via Visual Studio
1. Open Test Explorer (Test > Test Explorer)
2. Click "Run All Tests"
# Via command line
cd BinanceBot.Tests
dotnet test
# With code coverage
dotnet test --collect:"XPlat Code Coverage"# Via Visual Studio
1. Set BinanceBotML as startup project
2. Run the project
# Via command line
cd BinanceBotML
dotnet run# Via Visual Studio
1. Set BinanceBotSimulation as startup project
2. Run the project
# Via command line
cd BinanceBotSimulation
dotnet run# Via Visual Studio
1. Set BinanceBotML.Feeder as startup project
2. Run the project
# Via command line
cd BinanceBotML.Feeder
dotnet run# Run all tests
dotnet test
# Tests with verbose details
dotnet test --verbosity normal
# Tests with code coverage
dotnet test --collect:"XPlat Code Coverage" --results-directory TestResults
# Tests for a specific project
dotnet test BinanceBot.Tests/BinanceBot.Tests.csproj# Generate a coverage report
dotnet test --collect:"XPlat Code Coverage" --results-directory TestResults
# The report will be generated in TestResults/# Build all projects
dotnet build BinanceBot.sln
# Build in Release mode
dotnet build BinanceBot.sln --configuration Release
# Build a specific project
dotnet build BinanceBot/BinanceBot.csprojBinanceBot/
├── Abstraction/ # Interfaces
│ ├── IApiValidatorService.cs
│ ├── IExchangeHttpClient.cs
│ ├── IMarketTradeHandler.cs
│ └── ...
├── BinanceApi/ # Binance API Client
│ ├── BinanceClient.cs
│ ├── Model/ # Data models
│ ├── Serializer/ # JSON serializers
│ └── Validation/ # FluentValidation validators
├── Core/ # Business logic
│ ├── MarketTradeHandler.cs # Trading handler
│ ├── PriceRetriever.cs # Price retrieval
│ └── TradeAction.cs # Trading actions
├── Utils/ # Utilities
│ ├── FileSystem.cs
│ ├── Logger.cs
│ └── HttpClientWrapper.cs
└── Program.cs # Entry point
- .NET 8 - Main framework
- Microsoft.Extensions.Hosting - Hosting and dependency injection
- FluentValidation - API data validation
- Newtonsoft.Json - JSON serialization
- MSTest - Unit testing framework
- Moq - Mocking framework for tests
- TradingCalculation - Technical indicators calculations
The BinanceBot solution consists of 6 interconnected projects, each serving a specific purpose in the automated trading ecosystem:
A foundational library that provides mathematical calculations and trading strategies.
Key Components:
ITechnicalIndicatorsCalculator- Interface for technical analysis calculationsTechnicalIndicatorsCalculator- Implementation of RSI, Moving Averages, Volatility calculationsTradingStrategy- Configurable trading strategy parametersStopLossStrategy- Risk management strategy implementation
Features:
- RSI (Relative Strength Index) calculation
- Moving averages computation
- Volatility analysis
- Profit/loss calculations
- Minimum selling price determination
- Stop-loss strategy management
Structure:
TradingCalculation/
├── ITechnicalIndicatorsCalculator.cs # Technical analysis interface
├── TechnicalIndicatorsCalculator.cs # Core calculations implementation
└── Strategy/
├── TradingStrategy.cs # Main trading parameters
└── StopLossStrategy.cs # Risk management settings
Advanced AI-powered trading analysis using Microsoft ML.NET framework.
Dependencies:
- Microsoft.ML (3.0.1)
- Microsoft.ML.FastTree (3.0.1)
- References BinanceBot project
Key Components:
AnalyzerML- ML model training and prediction engineTradingBot- AI-driven trading decision makerMarketData- Data model for market informationMarketPrediction- Prediction output model
Features:
- Historical data training with FastTree regression
- Real-time price prediction
- Automated buy/sell decision making
- Model performance evaluation (R², MAE, RMSE)
- Feature engineering with technical indicators
ML Pipeline:
- Data loading from CSV files
- Feature concatenation (Open, High, Low, Close, Volume, SMA)
- Data normalization (MinMax scaling)
- FastTree regression training
- Model evaluation and prediction
Structure:
BinanceBotML/
├── AnalyzerML.cs # ML training and prediction engine
├── TradingBot.cs # AI decision-making system
├── MarketData.cs # Input data model
├── MarketPrediction.cs # Prediction output model
└── Program.cs # ML module entry point
Risk-free trading simulation and performance analysis tool.
Dependencies:
- References BinanceBot project
- Uses TradingCalculation library
Key Components:
IMarketTradeHandlerSimulation- Simulation interfaceMarketTradeHandlerSimulation- Profit calculation and analysis engine
Features:
- Profit/loss simulation without real trading
- Minimum margin calculation for profitability
- Fee and discount impact analysis
- Risk assessment and strategy validation
- Performance metrics computation
Simulation Capabilities:
- Calculate potential profits between price points
- Determine minimum selling prices for target profits
- Account for trading fees and discounts
- Test different quantity and price scenarios
Structure:
BinanceBotSimulation/
├── MarketTradeHandlerSimulation.cs # Simulation engine
├── Program.cs # Simulation entry point
└── IMarketTradeHandlerSimulation # Simulation interface
Automated market data collection and preprocessing for ML training.
Dependencies:
- References BinanceBot project
- Uses BinanceKlineConverter for data serialization
Key Components:
IFeeder- Data feeding interfaceFeedCsv- CSV data collection and export service
Features:
- Historical market data retrieval from Binance API
- Configurable time intervals (1s, 1m, 1h, etc.)
- Batch data processing for large datasets
- CSV export for ML training
- Technical indicators calculation during data collection
Data Collection Modes:
Run()- Multi-day historical data collection (1-minute intervals)Run10Min()- High-frequency data collection (1-second intervals)- Batch processing to handle API rate limits
- Automatic CSV formatting for ML consumption
Structure:
BinanceBotML.Feeder/
├── FeedCsv.cs # Data collection and CSV export
├── IFeeder.cs # Feeding interface
└── Program.cs # Data feeder entry point
Complete unit and integration testing framework.
Dependencies:
- MSTest.TestFramework (3.1.1)
- Moq (4.20.70) - Mocking framework
- coverlet.collector (6.0.0) - Code coverage
- References BinanceBot project
Key Components:
ProgramTests- Main application flow testing- Service configuration validation
- Integration testing with mocked dependencies
Testing Coverage:
- Dependency injection container validation
- Service lifecycle testing
- Trading logic validation with mock data
- API interaction testing
- Error handling and edge cases
Structure:
BinanceBot.Tests/
├── ProgramTests.cs # Main test suite
├── Usings.cs # Global using directives
└── BinanceBot.Tests.csproj # Test project configuration
The core application that orchestrates all components for live trading.
Complete Architecture:
BinanceBot/
├── Abstraction/ # Service interfaces
│ ├── IApiValidatorService.cs
│ ├── IExchangeHttpClient.cs
│ ├── IFileSystem.cs
│ ├── IHttpClientWrapper.cs
│ ├── ILogger.cs
│ ├── IMarketTradeHandler.cs
│ ├── IPriceRetriever.cs
│ └── ITradeAction.cs
├── BinanceApi/ # Binance integration
│ ├── BinanceClient.cs
│ ├── Model/ # API data models
│ │ ├── Account.cs
│ │ ├── Balance.cs
│ │ ├── BinanceKline.cs
│ │ ├── Commission.cs
│ │ ├── Order.cs
│ │ └── TestOrder.cs
│ ├── Serializer/
│ │ └── BinanceKlineConverter.cs
│ └── Validation/ # FluentValidation
│ ├── ApiValidatorService.cs
│ └── Validator/
├── Core/ # Business logic
│ ├── MarketTradeHandler.cs
│ ├── PriceRetriever.cs
│ └── TradeAction.cs
├── Utils/ # Utility services
│ ├── FileSystem.cs
│ ├── Helper.cs
│ ├── HttpClientWrapper.cs
│ └── Logger.cs
└── Program.cs # Application entry point
graph TD
A[BinanceBot] --> B[TradingCalculation]
C[BinanceBot.Tests] --> A
D[BinanceBotML] --> A
E[BinanceBotSimulation] --> A
F[BinanceBotML.Feeder] --> A
D --> B
E --> B
cd BinanceBot
dotnet run
# Executes real-time trading with technical indicatorscd BinanceBotML
dotnet run
# Uses AI predictions for trading decisionscd BinanceBotSimulation
dotnet run
# Simulates trading strategies without real moneycd BinanceBotML.Feeder
dotnet run
# Collects historical data for ML trainingdotnet test
# Validates all components functionalityAll projects share the same appsettings.json configuration structure:
{
"AppSettings": {
"Binance": {
"ApiKey": "your_binance_api_key",
"ApiSecret": "your_binance_secret"
}
},
"ConnectionStrings": {},
"Logging": {
"LogLevel": {
"Default": "Information"
}
}
}Customize trading parameters in TradingStrategy.cs:
- TargetProfit: Desired profit per trade (default: 10 USDT)
- Quantity: Trading volume (default: 200 SOL)
- MaxRSI: RSI threshold for sell signals (default: 70)
- Symbol: Trading pair (default: "SOLUSDT")
- Period: Analysis timeframe (default: 900 seconds)
- Interval: Data collection frequency (default: "1s")
- StopLossPercentage: Maximum acceptable loss (default: 5%)
- VolatilityMultiplier: Dynamic stop-loss adjustment (default: 2x)
- FloorStopLossPercentage: Minimum stop-loss (default: 1.2%)
- CeilingStopLossPercentage: Maximum stop-loss (default: 2%)
- TestMode: Enable paper trading (no real orders)
- Simulation: Use BinanceBotSimulation for risk-free testing
- ML Validation: Validate predictions before live trading
- Fork the project
- Create a 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
This project is licensed. See the LICENSE file for more details.
This bot is provided for educational and research purposes. Cryptocurrency trading involves significant financial risks. Use this software at your own risk and never trade with funds you cannot afford to lose.