metacritical / Binance-Futures-Trading-Bot

Technical Analysis driven Trading bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Binance-Futures-Trading-Bot Tweet


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

  • Add option to overwrite saved price data so you don't have to manually delete the old data.
  • Maybe Provide a standard bot strategy for Bot...
  • GUI if people were interested (could take a while I've no experience here)
  • Speed up Data Set aligner in Backtester with multiprocessing
  • Fix trailing Stop, think its causing some rounding errors.

Strategy suggestions:


Latest Changes (if any):

  • 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)
  • Added some backtest results. (27/12/21)
  • Mainly Bug fixes lately no new features.

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

Join My 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
  • Min version = python 3.7

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 API_keys.py.

YouTube Channels with Strategy Ideas:

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.

Golden Cross 15m candles


Triple EMA Stochastic RSI 15m candles


Triple EMA 4hr candles

Back test strategies in Backtester.py


  • 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.
  • Ignore the pair-trading section and ensure pair_Trading = 0, if you are executing a TA strategy
  • The data is split into an in-sample set and a test set, the flag test_set decides which set we are running the strategy on, both sets are in same units as test_set_length but we adjust time_period variable to change the in-sample data set length. The reason for splitting the data like this is to optimize parameters on the in-sample set and then once optimized run the strategy on the test-set to see if you have overfit your model by cherry picking values for parameters that suit the in-sample data.
  • The time_period variable is the length of time in the past from today excluding the test-set, to run the strategy on. This is in the same units as the test_set_length.
  • The TIME_INTERVAL variable is the interval for the candlesticks we want to trade on.
  • Settings are found at the top of the script, line 50.
  • Trailing Stop: 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 293 , uncomment a strategy or call a new strategy you have written yourself here, the 'prediction' 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
  • Some of the pre-coded strategies return a 'Type' variable, if a strategy returns the 'Type' variable you must call the SetSLTP() function from TradingStrats.py in order to set the corresponding Stop loss value, and Take profit value, this function is found in TradingStrats.py
  • Now just run the script and wait a few minutes for it to pull the data and begin backtesting
  • use_heikin_ashi is a flag line 59 that will create the heikin ashi candles for use, Called CloseStream_H, OpenStream_H, LowStream_H, HighStream_H which can be referenced or passed to Strategies.

Using Downloaded data for backtesting


  • Reason to do this is to speed up backtesting
  • Create a folder on the desktop called price_data.
  • In download_Data.py change the path to f"C:\Users\your_name\Desktop\price_data
    replacing your_name with the user that you are logged into.
  • Switch load_data on in Backtester.py on line 120, now when you run the script it will load from the folder & if the specified candlestick data isn't present in the folder then it will be downloaded and saved for future use.
    NOTE: this data is static so if you want up to date data in future you will have to manually delete the data from the folder on your desktop and then run the script again. Otherwise you can just turn load_data off and pull data from the server everytime you want to run a backtest.

Strategy_Tester.py


This script will run a strategy on every coin on Binance & then generate graphs and statistics which are saved to a folder on the desktop.

  • Line 29 to Line 43 are the settings which should be clear with the comments I've provided
  • Create a folder on the desktop called Strategy_tester with another folder matching the Strategy_name variable, this is where the data will be stored when you run.
  • Change path1 on line 44 to reflect the location of the Strategy_tester folder you've just created.
  • Uncomment a strategy after line 258 or else call your custom strategy here, following the same guidelines layed out in the backtesting section above.
  • Now run the script with the settings you've chosen and check up on the graphs and statistics that are created soon after.

Run strategies live in 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

  • In Bot.py on line 341 are the settings.
  • Choose the Interval you want to trade and the buffer of candlesticks your strategy will need.
  • leverage and order_size should be changed acording 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.
    Strategies are implemented in Data_Set.py as a function named Make_decision() in the Data_set class
  • Make_decision() must return Trade_Direction,stoplossval,takeprofitval for the strategy to work properly
  • You might draw inspiration for a strategy from one In TradingStrats.py

(Depreciated) Run strategies live in Bot__(depreciated).py

Contact me Tweet

About

Technical Analysis driven Trading bot


Languages

Language:Python 100.0%