make-j64 / Binance-Futures-Trading-Bot

Technical Analysis driven Trading bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binance-Futures-Trading-Bot Tweet


Technical Analysis driven Crypto Trading bot on Binance Futures πŸ“ˆ β‚Ώ πŸš€ Tweet

Join My public Discord Server & Follow The Twitter

  • Utilizes python-Binance Client to execute orders and pull data from Binance
  • Utilizes ta library for Technical indicators
  • Write your own functions/classes to implement your TA strategies.
  • There is no default Strategy implemented you must do this in Data_Set.py as specified below.
  • Comes with some pre-coded strategies found in TradingStrats.py
  • If you enjoy the repo please share it around to friends & tweet about it using the tweet button above πŸ˜ƒ
    or Buy me a Coffee
  • Want Coding Assistance, Custom Strategies & Custom Features? Sponsor Me for access to all these from my private discord channel.
  • One time payment for custom strategies available also.
  • Min version = Python 3.7
  • Max version = Python 3.9.x
  • Recommended version = Python 3.8.10 (one I use and have no issues with)
  • Set up windows to sync time once a day if you don't do this binance will eventually reject orders with a timestamp error.

Run strategies live on Binance from Live_Bot.py


Run strategies at your own risk I am not responsible for your trading decisions, futures are risky and proper risk management should be adhered to at all times, always have a stoploss

There is no set strategy, You can select one by uncommenting it in make_Decision() inside Bot_Class.py , These Strategies are from Trading_Strats.py and should be backtested thoroughly/ Altered to make more profitable

  • Settings are in Config_File.py
  • Trade a single position at a time by setting Max_Margin = 0, to trade multiple coins just change this value to suit your desired Max Margin for your positions i.e. Max_Margin = .15 will allow the bot to open positions until you have used up 15% of your account as margin.
  • Choose the Interval you want to trade and the buffer of candlesticks your strategy will need this will be dependent on indicators you need to ensure you have a sufficient buffer, or you will get errors.
  • Leverage and order_size should be changed according to your preference
  • symbol[] is a list of the symbols you wish to trade, the default is all the coins on the exchange currently.
  • Trailing stop: set use_trailing_stop to 1 and change trailing_stop_percent to suit your strategy to use the trailing stop (Min val .001 i.e .1%, Max 5 i.e. 5%). The trailing stop will be placed when the takeprofitval margin of increase/decrease is reached from your strategy.

Creating Custom Strategies:

Strategies are implemented in Bot_Class.py as a function named Make_decision() in the Bot class

  • Make_decision() must return Trade_Direction,stop_loss_val,take_profit_val for the strategy to work properly
  • You might draw inspiration for a strategy from one in TradingStrats.py
  • I recommend using the backtester first.

YouTube Channels with Strategy Ideas:

Back test strategies in Backtester.py


  • Create a 'price_data' folder on the desktop and change the path variable in Helper.py to suit your machine. Data pulled from Binance will be stored in this folder and automatically loaded from memory in future.
  • Create a list named 'symbol' of coin/coins you wish to run a strategy on ie. symbol = ['BTCUSDT' , 'ETHUSDT'] , this would run your strategy on BTC and ETH. Whereas symbol = ['BTCUSDT'] would run the strategy on BTC only.
  • Settings are found at the top of the script, line 44.
  • Trailing Stop (NOT FUNCTIONING CORRECTLY): turn the use_trailing_stop flag on, specify the trailing_stop_distance in decimal, now when a takeprofit margin target is hit the trailing stop will be placed and automatically & adjusted based off new Lows or Highs in price and the trailing_stop_distance you've specified.
  • Next we want to choose our TA strategy, this is done after line 175 , uncomment a strategy or call a new strategy you have written yourself here, the 'Trade_Direction' variable is used to tell the script to go short (0), go long (1), or go flat (-99). This should be returned by custom strategy functions/classes you write for the strategy to be executed correctly
  • Now just run the script and wait a few minutes for it to pull the data and begin backtesting
  • Heikin Ashi Candles are available under: CloseStream_H, OpenStream_H, LowStream_H, HighStream_H which can be referenced or passed to Strategies.

Back Test top performers:


Not indicative of future returns

  • Check out the other backtests although results were poor on some that was due to transaction fees in many cases so maybe altering to take less trades or add confirmation could work.
  • All of the strategies can be improved on but this is just a good place to start.
  • Try removing some coins from the list traded, the tests below were on all coins available at the time.

Golden Cross 15m candles


Triple EMA Stochastic RSI 15m candles


Triple EMA 4hr candles

To-Do list: (suggest something and I'll add it) πŸ˜ƒ

  • Update Backtester to Open multiple positions, and Improve similarities to live Bot.
  • Add check that removes trades that the user manually closed, currently the bot monitors orderId's so If you manualy close a trade it won't know.
  • Add option to create csv file of trades with keys: "long/short | date | strike price | candle high | candle low".
  • Fix trailing Stop in Back Tester, think its causing some floating point rounding errors (think I know a fix just need time to implement).
  • GUI if people were interested (could take a while I've no experience here)

Latest Changes (if any):

  • Added Functionality for opening and managing multiple positions. (20/03/22)
  • Simplified the system to be more user friendly, removed code that was obsolete. (11/03/22)
  • Added support in the live Bot environment for some of the strategies in Trading_strats.py , To make use of a strategy in Bot.py just uncomment it inside Make_Decision() inside Data_set.py (11/02/2022).
  • Added support for Heikin Ashi candles in Bot.py, there is now a switch in settings use_heikin_ashi. If switched on you may reference self.Open_H, self.Close_H etc. from make_Decision() in Data_set.py (17/01/22).
  • Updated Backtester to make it more user friendly & changed naming convention for saved data (14/01/22).
  • At the end of a backtest you can see the date & time that every trade was taken. So you can debug strategies by checking on tradingview/binance (07/01/22).

Binance Setup


  • Create a Binance Account (This link uses my referral which gives you 5% kickback on trades & would be greatly appreciated)
  • Enable Two-factor Authentication in the security section to keep your crypto safe.
  • Create a new API key under the API Management section.
  • [βœ“] Read Info [βœ“] Enable Trading [βœ“] Enable Futures [X] Enable Withdrawals
  • Whitelist your IP address to further secure your account, and so that your API keys don't expire after 1 month.
  • Fill in your api keys into api_secret and api_key in Config_File.py
  • Set up windows to sync time once a day if you don't do this binance will eventually reject orders with a timestamp error.

Contact me Tweet

About

Technical Analysis driven Trading bot


Languages

Language:Python 100.0%