Skip to content

tecrade/Trading-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ BTC Trading Bot

An automated Bitcoin trading bot built using the Binance API and Telegram Bot API.

This project demonstrates how algorithmic trading systems can analyze market data, generate trading signals using technical indicators, execute trades automatically, and provide real-time monitoring through Telegram.

⚠️ Educational Purpose Only

This project was developed for educational and learning purposes to demonstrate the fundamentals of automated trading systems and algorithmic trading workflows. It is not intended to be used as financial advice or as a production-ready trading solution.


πŸš€ Features

  • Automated BTCUSDT trading
  • Binance Testnet integration
  • Real-time market monitoring
  • Telegram bot integration
  • Buy and sell signal generation
  • Automated order execution
  • ATR-based Stop Loss
  • ATR-based Take Profit
  • Market status reporting
  • Account balance monitoring
  • Multi-threaded architecture

πŸ—οΈ System Overview

The bot continuously monitors BTCUSDT market data and evaluates trading opportunities using a combination of traditional technical indicators.

The workflow consists of:

  1. Fetching market candlestick data from Binance.
  2. Calculating technical indicators.
  3. Generating BUY or SELL signals.
  4. Executing market orders.
  5. Managing risk using Stop Loss and Take Profit levels.
  6. Sending updates and alerts through Telegram.

βš™οΈ Trading Strategy

The bot uses a traditional rule-based strategy that combines multiple technical indicators.

Indicators Used

Exponential Moving Averages (EMA)

  • EMA 50
  • EMA 200

Used to identify long-term market trends.

MACD

Moving Average Convergence Divergence is used to confirm momentum shifts.

RSI

Relative Strength Index is used to avoid entering trades during overbought or oversold conditions.

VWAP

Volume Weighted Average Price helps determine whether the current market price is trading above or below the average traded price.

ATR

Average True Range is used to calculate dynamic Stop Loss and Take Profit levels based on market volatility.


πŸ“Š Buy Conditions

A BUY signal is generated when:

  • EMA50 > EMA200
  • MACD > Signal Line
  • RSI is between 30 and 70
  • Current Price > VWAP

πŸ“‰ Sell Conditions

A SELL signal is generated when:

  • EMA50 < EMA200
  • MACD < Signal Line
  • RSI is between 30 and 70
  • Current Price < VWAP

πŸ›‘οΈ Risk Management

The bot uses ATR-based risk management.

Stop Loss

Entry Price - (1.5 Γ— ATR)

Take Profit

Entry Price + (2 Γ— ATR)

This allows the system to adapt to changing market volatility.


πŸ€– Telegram Integration

The bot can be monitored through Telegram commands.

Available Commands

/start

Displays the bot startup status and account information.

/market

Displays:

  • Current BTC price
  • Latest market signal
  • Latest candle information

/status

Displays:

  • Current position
  • Stop Loss
  • Take Profit
  • Latest trade information

/indicators

Displays:

  • EMA50
  • EMA200
  • MACD
  • Signal Line
  • RSI
  • VWAP
  • ATR

/balance

Displays current account balances and profit information.


πŸ“Έ Screenshots

Server Terminal

Server Terminal

Telegram Bot Working

Telegarm Bot Telegarm Bot Telegarm Bot


πŸ“‚ Project Structure

TradingBot/
β”‚
β”œβ”€β”€ btc-bot.py
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
β”‚
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ thumbnail.png
β”‚   β”œβ”€β”€ server.png
β”‚   β”œβ”€β”€ telegram1.png
β”‚   β”œβ”€β”€ telegram2.png
β”‚   └── telegram3.png
β”‚
└── .env

πŸ”§ Installation

Clone the repository:

git clone https://github.com/yourusername/trading-bot.git
cd trading-bot

Install dependencies:

pip install -r requirements.txt

πŸ”‘ Setting Up Binance Testnet API

This project uses the Binance Spot Test Network to perform paper trading without risking real funds.

Step 1: Create a Binance Testnet Account

Visit:

https://testnet.binance.vision/

Login using your GitHub account.


Step 2: Generate API Credentials

After logging in:

  1. Navigate to API Management.

  2. Click Generate HMAC_SHA256 Key.

  3. Copy:

    • API Key
    • Secret Key

Store these credentials securely.


Step 3: Configure Environment Variables

Create a .env file in the project root:

BINANCE_API_KEY=YOUR_API_KEY
BINANCE_API_SECRET=YOUR_SECRET_KEY


Important Notes

  • This project uses Binance Testnet for educational and testing purposes.
  • Testnet funds are simulated and have no real monetary value.
  • API credentials generated from Testnet cannot be used on the live Binance exchange.

πŸ€– Setting Up Telegram Notifications

The bot uses Telegram to send trade execution alerts, account information, and market updates.


Step 1: Create a Telegram Bot

Open Telegram and search for:

@BotFather

Start a conversation and run:

/newbot

BotFather will ask:

  1. Bot Name

Example:

BTC Trading Bot

  1. Bot Username

Must end with:

bot

Example:

btc_trading_bot_2026_bot

After creation, BotFather will provide a Bot Token:

123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ

Save this token securely.


Step 2: Get Your Chat ID

The bot needs your Telegram Chat ID to know where to send notifications.

Method

  1. Search for your newly created bot.
  2. Click Start.
  3. Search Telegram for:
@userinfobot

or

@raw_data_bot

  1. Click Start.

The bot will reply with your account details:

Id: 987654321

Copy this number.


Step 3: Add Telegram Credentials

Update your .env file:

BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN
CHAT_ID=YOUR_CHAT_ID

Example:

BINANCE_API_KEY=xxxxxxxx
BINANCE_API_SECRET=xxxxxxxx

BOT_TOKEN=123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ
CHAT_ID=987654321


πŸ“„ Complete .env Example

BINANCE_API_KEY=YOUR_API_KEY
BINANCE_API_SECRET=YOUR_SECRET_KEY

BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN
CHAT_ID=YOUR_CHAT_ID

▢️ Running the Bot

python btc-bot.py

The application starts:

  • Trading Engine Thread
  • Telegram Bot Thread

Both services run simultaneously.

Open Telegram bot chat and test:

/start

⚠️ Important Disclaimer

This project is intended solely for educational and demonstration purposes.

The trading strategy implemented in this project is based on traditional technical analysis indicators such as EMA, MACD, RSI, VWAP, and ATR. While these indicators are commonly used in algorithmic trading systems, they are not guaranteed to produce profitable results.

Financial markets are highly dynamic, noisy, and influenced by countless unpredictable factors. As a result:

  • Historical performance does not guarantee future performance.
  • Market behavior can change rapidly.
  • False signals frequently occur.
  • Significant financial losses may occur if the strategy is used without sufficient expertise and risk management.

This implementation should be viewed as a learning tool for understanding automated trading workflows rather than a reliable investment system.

Always perform extensive backtesting, paper trading, and risk assessment before deploying any automated trading strategy in a live environment.


πŸ“š Learning Outcomes

This project demonstrates:

  • Binance API Integration
  • Telegram Bot Development
  • Algorithmic Trading Concepts
  • Technical Indicator Calculation
  • Risk Management Techniques
  • Multi-threaded Python Applications
  • Real-time Financial Data Processing

🚧 Future Improvements

  • Backtesting Framework
  • Web Dashboard
  • Performance Analytics
  • Multiple Trading Pairs
  • Portfolio Management
  • Machine Learning Based Signal Generation
  • Advanced Risk Management
  • Cloud Deployment

About

Automated BTC trading bot using Binance Testnet and Telegram, featuring EMA, MACD, RSI, VWAP, and ATR-based algorithmic trading strategies.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages