Binance Telegram Bot is an automated trading bot that integrates Binance's trading capabilities with signals received from Telegram channels. It executes trades on Binance based on signals from Telegram, ensuring automated and timely responses to market changes.
- Signal Processing
- Trade Execution
- Configurable Settings
- Detailed Logging and Monitoring
- Robust Error Handling
- Java 11
- Maven
- Binance account
- Telegram account
- Clone the repo:
git clone https://github.com/ozgen/binance-telegram-bot.git
- Navigate to the directory:
cd binance-telegram-bot
- Build with Maven:
mvn clean install
Configure the application using environment variables or a .env
file. Here are the key variables you need to set:
spring.datasource.url
: URL to the Azure databasespring.datasource.username
: Azure database usernamespring.datasource.password
: Azure database password
azure.keyvault.uri
: Azure keyvault URIazure.keyvault.client-id
: Azure keyvault client IDazure.keyvault.client-key
: Azure keyvault client keyazure.keyvault.tenant-id
: Azure keyvault tenant ID
bot.telegram.token
: Telegram bot tokenbot.telegram.enabled
: Enable Telegram bot (true
orfalse
)
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation
: Hibernate setting for LOB creationspring.jpa.hibernate.ddl-auto
: Hibernate DDL auto strategy (create
,create-drop
,validate
,update
)
app.bot.investment.currency
: Investment currency (e.g.,BTC
)app.bot.investment.amount
: Total investment amountapp.bot.investment.perAmount
: Amount per tradeapp.bot.investment.currencyRate
: Currency rate for conversion (e.g.,BTCUSD
)app.bot.investment.percentageInc
: Percentage increase for buyingapp.bot.investment.profitPercentage
: Profit percentage target
app.bot.schedule.buyError
: Schedule interval for buy error in msapp.bot.schedule.sellError
: Schedule interval for sell error in msapp.bot.schedule.insufficient
: Schedule interval for insufficient balance in msapp.bot.schedule.notInRange
: Schedule interval for not in range status in msapp.bot.schedule.tradingSignal
: Schedule interval for trading signals in msapp.bot.schedule.openSellOrder
: Schedule interval for open sell orders in msapp.bot.schedule.openBuyOrder
: Schedule interval for open buy orders in msapp.bot.schedule.monthBefore
: Number of months before for date calculations
bot.telegram.error.enabled
: Set totrue
to enable error reporting on Telegram.
Start the bot with:
java -jar target/binance-telegram-bot-0.0.1-SNAPSHOT.jar
To ensure the system functions correctly, follow these setup requirements:
- Create a Telegram Bot: Follow the instructions on Telegram's official documentation to create a new bot.
- Generate a Bot Token: Use this guide to generate a token for your Telegram bot.
- Create a new bot for error reporting following the steps above.
- Create a troubleshooting channel on Telegram and add the error bot as an admin.
- Start the system, then send a message to the troubleshooting channel to initialize the error bot correctly.
- Make sure the bot is an admin of the Telegram channel you want to monitor.
- This setup uses Azure Key Vault and Azure SQL Database. For local or alternative databases, update the
application.properties
file accordingly.
- Create an Azure Key Vault: Follow the steps outlined here.
- Connect to Azure Key Vault: Use the instructions provided here to connect.
- Create an Azure SQL Database: Detailed instructions can be found here. Opting for a serverless configuration is cost-effective.
- Connect to Azure SQL Database: Follow these steps to connect.
Set up the following environment variables for your application:
AZURE_DB_PASSWORD=<db-password>
AZURE_DB_URL=<azure-db-url>
AZURE_DB_USERNAME=<db-user-name>
AZURE_KEYVAULT_CLIENT_ID=<azure-keyvault-client-id>
AZURE_KEYVAULT_CLIENT_KEY=<azure-keyvault-client-key>
AZURE_KEYVAULT_TENANT_ID=<azure-keyvault-tenant-id>
AZURE_KEYVAULT_URL=<keyvault-url>
TELEGRAM_ERROR_TOKEN=<telegram-error-token>
TELEGRAM_TOKEN=<telegram-channel-token>
TELEGRAM_USERNAME=<telegram-bot-username>
TELEGRAM_ERROR_USERNAME=<telegram-error-bot-username>
Replace the placeholder values with your actual configuration details.
Ensure all prerequisites are met for the system to run smoothly.
The bot monitors specified Telegram channels for trading signals and executes corresponding trades on Binance. Here's an example of a trading signal the bot can process:
Trading Signal Example:
NKNBTC
ENTRY: 0.00000260 - 0.00000290
TP1: 0.00000315
TP2: 0.00000360
TP3: 0.00000432
TP4: 0.00000486
TP5: 0.00000550
TP6: 0.00000666
TP7: 0.00000741
STOP: Close weekly below 0.00000240
Execute the test suite using Maven:
mvn test
After running the tests, generate a coverage report using JaCoCo (Java Code Coverage Library):
mvn jacoco:report
The coverage report can be found in target/site/jacoco/index.html
. Open it in a web browser to view detailed coverage statistics.
This project is licensed under the MIT License - see LICENSE.md for details.
- Binance API
- Telegram API