pakhuong / Binance-Futures-Bot

A Technical Analysis Bot that trades leveraged USDT futures markets on Binance.

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

  • Create a Binance Account (This link uses my referral which gives you 5% kickback on trades & would be greatly appreciated)
  • Want me to host a Bot for you on AWS, I have a monthly tier available for this join & I'll get in touch to get you set up πŸ˜ƒ
  • 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.
  • 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 (private repo coming soon)
  • 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 Number_Of_Trades = 1, to trade multiple coins just increment this value.
  • 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 = 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 take profit value margin of increase/decrease is reached from your strategy.
  • To close a trade based off a condition check_close_pos() must return a close_pos flag, and you must ensure self.use_close_pos = True in Bot_Class also.
  • Want me to host a Bot for you on AWS, I have a monthly tier available for this join & I'll get in touch to get you set up πŸ˜ƒ

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 13.
  • Trailing Stop: turn the use_trailing_stop flag on, specify the trailing_stop_callback in decimal, now when a take profit 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_callback you've specified.
  • Next we want to choose our TA strategy, this is done in Bot_Class.py in Make_decision() , 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
  • Trade_All_Symbols flag will run the strategy on all the coins on binance if True.
  • Trade_Each_Coin_With_Separate_Accounts flag will run the strategy with isolated account Balances for each coin you list if True. (Useful to see which coins the strategy works on before combining the trades to a single account)
  • generate_heikin_ashi flag will make Heikin Ashi candles available to be consumed by your strategy make_decision() in the Bot Class.
  • Generate a csv file of all the trades taken over a backtest by setting print_to_csv to True and setting csv_name to a unique name, will throw an error if the file already exists.
  • Flag variable plot_graphs_to_folder, When active the equity curves will be plotted to a folder instead of displayed.
  • To close a trade based off a condition check_close_pos() must return a close_pos flag, and you must ensure self.use_close_pos = True in Bot_Class also.
  • Want me to host a Bot for you on AWS, I have a monthly tier available for this join & I'll get in touch to get you set up πŸ˜ƒ

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.

Triple EMA RUNEUSDT 01-04-22 to 28-04-22 (labelling is wrong)

Golden Cross 15m candles


Triple EMA 4hr candles

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

  • GUI if people were interested (could take a while I've no experience here)
  • Data Cleaning task to run every x amount of minutes, ensuring the Live Bot hasn't lost any candles
  • Option to give config in shell flags (Not sure yet but this was requested)
  • Refactor happening soon to make the bot easier to use, and update the README

Latest Changes (if any):

  • Changed the Data structure (making old data obsolete apologies), new structure will have faster downloads and Now all candles are constructed from the 1m candles so if you run a backtest over a period you will now have data for all candles over that same period.(28/04/22)
  • New flag plot_graphs_to_folder, When active the equity curves will be plotted to a folder instead of displayed. (28/04/22)
  • Added Trailing Stop into the backtester. (25/04/22)
  • Added feature which can close a position based on a condition, by returning a flag close_pos from a strategy. (24/04/22)
  • Added feature to trade each coin with an isolated account balance in Backtester, activated with new flag variable 'Trade_Each_Coin_With_Separate_Accounts'. (19/04/22)
  • Added option to create a csv file from a backtest Line 33. (19/04/22)
  • Updated Backtester to Open multiple positions, and Improved similarities to live Bot. (15/04/22)
  • Added a check that removes trades that the user manually closed by the user. (15/04/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

A Technical Analysis Bot that trades leveraged USDT futures markets on Binance.


Languages

Language:Python 100.0%