Skip to content

tahaabbas/binance-spot-trading-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Binance Spot Trading Bot (EMA Crossover Strategy)

This bot automates spot trading on Binance based on Exponential Moving Average (EMA) crossovers. When the short-term EMA crosses above the long-term EMA, it's an indication of upward momentum, and the bot places a buy order. Conversely, when the short-term EMA crosses below the long-term EMA, signaling potential downward momentum, the bot places a sell order.

How It Works:

In a continuous loop, the bot fetches the latest price for the given symbol and calculates the short and long EMAs.

Buy Order Logic:

If the short EMA is greater than the long EMA (indicating potential upward price movement) and the last action wasn't a buy, the bot places a buy order. After placing the buy order, the bot checks if the order was fully executed (FILLED status) before updating its last action.

Sell Order Logic:

If the short EMA is less than the long EMA (indicating potential downward price movement) and the last action wasn't a sell, the bot places a sell order. After placing the sell order, it checks if the order was fully executed before updating its last action.

Exception Handling:

If there's a timeout when communicating with Binance's API, the bot catches the exception and continues operation, ensuring the script doesn't terminate unexpectedly.

Usage

This bot is executed from the command line and requires the trading pair symbol, data-fetching interval, and the periods for the short and long EMAs as arguments. The bot then continually checks the EMA values and makes decisions based on the crossover strategy.

Requirments

  • Python3.x
  • Pip

Installation

pip install python-binance

Run

python run_bot.py <Symbol> <Interval> <Short EMA Period> <Long EMA Period>

Example: python run_bot.py BTCUSDT 1d 8 20

To Run in Background nohup python run_bot.py BTCUSDT 1d 8 20 &


The Above script was only tested on Ubuntu 18.04.6 LTS Distribution

Risk Warning

Remember, while the EMA crossover strategy is popular, it's essential to combine it with other indicators or methods for more robust trading signals. Always ensure you are comfortable with the risks before running any trading bot live.

Support This Project

First off, thank you for taking the time to consider supporting this project. It's built with a lot of hard work, dedication, and countless hours of coding.

If you've found any value in my work, and would like to support its continued development, consider making a donation. Every little bit helps in maintaining the project, covering costs, and encouraging further enhancements. Donate with Bitcoin (BTC)

Donate with BTC

Scan the QR code or send your donation to the address below:

BTC QR Code

BTC Address:

15AZJpmYEV2Q9fvf7DvQgTHcFgmNg2UcPz

Your generosity and support will always be appreciated!