def main(argv): chart = BotChart( "poloniex", "BTC_GRC", 60, False) # the period is for back testing, so actually obsolete strategy = BotStrategy() # strategy_FLDC = BotStrategy_FLDC() candlesticks = [] developingCandlestick = BotCandlestick(period=60) while True: try: developingCandlestick.tick(chart.getCurrentPrice()) except urllib2.URLError: time.sleep(int(30)) developingCandlestick.tick(chart.getCurrentPrice()) if developingCandlestick.isClosed(): candlesticks.append(developingCandlestick) strategy.tick(developingCandlestick) # strategy_FLDC.tick() developingCandlestick = BotCandlestick(period=60) # strategy.evaluatePositions_raw_gap() time.sleep(int(30))
def main(argv): startTime = False endTime = False try: opts, args = getopt.getopt(argv, "hp:c:n:s:e:", ["period=", "currency=", "points="]) except getopt.GetoptError: print 'trading-bot.py -p <period length> -c <currency pair> -n <period of moving average>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'trading-bot.py -p <period length> -c <currency pair> -n <period of moving average>' sys.exit() elif opt in ("-p", "--period"): if (int(arg) in [300, 900, 1800, 7200, 14400, 86400]): period = arg else: print 'Poloniex requires periods in 300,900,1800,7200,14400, or 86400 second increments' sys.exit(2) elif opt in ("-c", "--currency"): pair = arg elif opt in ("-n", "--points"): lengthOfMA = int(arg) elif opt in ("-s"): startTime = arg elif opt in ("-e"): endTime = arg if (startTime): chart = BotChart("poloniex", "BTC_PIVX", 300) strategy = BotStrategy() for candlestick in chart.getPoints(): strategy.tick(candlestick) else: chart = BotChart("poloniex", "BTC_PIVX", 300, False) strategy = BotStrategy() candlesticks = [] developingCandlestick = BotCandlestick() while True: try: developingCandlestick.tick(chart.getCurrentPrice()) except urllib2.URLError: time.sleep(int(30)) developingCandlestick.tick(chart.getCurrentPrice()) if (developingCandlestick.isClosed()): candlesticks.append(developingCandlestick) strategy.tick(developingCandlestick) developingCandlestick = BotCandlestick() time.sleep(int(30))
def main(argv): pair = "USDT_ETH" debut = '2017-08-01 14:00:00' fin = '2018-08-01 20:53:20' period = 14400 chart = BotChart("poloniex", pair, period, backtest=False) strategy = stratRsi2() candlesticks = [] developingCandlestick = BotCandlestick() while True: try: developingCandlestick.tick(chart.getCurrentPrice()) except urllib2.URLError: time.sleep(int(30)) developingCandlestick.tick(chart.getCurrentPrice()) if (developingCandlestick.isClosed()): candlesticks.append(developingCandlestick) strategy.tick(developingCandlestick) developingCandlestick = BotCandlestick() time.sleep(int(30))
def main(argv): #Trades using the btc to xmr currency chart = BotChart("poloniex","BTC_XMR",300,False) #Function from bot strategy, which is a class containeing various datas #such as opening price for the tick, closing price for the tick. strategy = BotStrategy() #Empty array holding the candlestick data candlesticks = [] developingCandlestick = BotCandlestick() #Loop that continues indefinately while True: try: developingCandlestick.tick(chart.getCurrentPrice()) except urllib2.URLError: time.sleep(int(30)) #Sleep function so that we dont overload the server with requests. Which #can result in the account or our ip getting banned. developingCandlestick.tick(chart.getCurrentPrice()) #check if it is closing price, if it is the append to the array if (developingCandlestick.isClosed()): candlesticks.append(developingCandlestick) strategy.tick(developingCandlestick) developingCandlestick = BotCandlestick() time.sleep(int(30))
def main(argv): chart = BotChart("poloniex","BTC_XMR",300,False) strategy = BotStrategy() while True: candlestick = chart.getCurrentPrice() strategy.tick(candlestick) time.sleep(int(10))
def main(argv): chart = BotChart("poloniex","BTC_LTC",300,False) strategy = BotStrategy() candlesticks = [] developingCandlestick = BotCandlestick() while True: try: developingCandlestick.tick(chart.getCurrentPrice()) except urllib2.URLError: time.sleep(int(30)) developingCandlestick.tick(chart.getCurrentPrice()) if (developingCandlestick.isClosed()): candlesticks.append(developingCandlestick) strategy.tick(developingCandlestick) developingCandlestick = BotCandlestick() time.sleep(int(30))
def main(argv): startTime = False endTime = False live = False movingAverageLength = 20 try: opts, args = getopt.getopt(argv,"ht:c:n:s:e",["timeframe=","currency=","exchange=","live"]) except getopt.GetoptError: print('trading-bot.py -t <timeframe> -c <currency pair>') sys.exit(2) for opt, arg in opts: if opt == '-h': print('trading-bot.py -t <timeframe> -c <currency pair>') sys.exit() elif opt in ("-s"): startTime = str(arg) elif opt in ("-e"): endTime = str(arg) elif opt in ("-t", "--timeframe"): timeframe = str(arg) shared.strategy['timeframe'] = timeframe elif opt in ("-c", "--currency"): pair = str(arg) shared.exchange['pair'] = pair shared.exchange['market'] = pair.split("/")[1] shared.exchange['coin'] = pair.split("/")[0] elif opt in ("--exchange"): exchange = str(arg) shared.exchange['name'] = exchange elif opt == "--live": print("You're going live... All loss are your reponsability only!") live = True # startTime specified: we are in backtest mode if (startTime): chart = BotChart(timeframe, startTime, endTime) strategy = BotStrategy() strategy.showPortfolio() for candlestick in chart.getPoints(): strategy.tick(candlestick) chart.drawChart(strategy.candlesticks, strategy.trades, strategy.movingAverages) strategy.showPortfolio() else: chart = BotChart(timeframe, False, False, False) strategy = BotStrategy(False, live) strategy.showPortfolio() candlestick = BotCandlestick() x = 0 while True: try: currentPrice = chart.getCurrentPrice() candlestick.tick(currentPrice) strategy.tick(candlestick) except ccxt.NetworkError as e: print(type(e).__name__, e.args, , 'Exchange error (ignoring)') except ccxt.ExchangeError as e: print(type(e).__name__, e.args, , 'Exchange error (ignoring)') except ccxt.DDoSProtection as e: print(type(e).__name__, e.args, 'DDoS Protection (ignoring)') except ccxt.RequestTimeout as e: print(type(e).__name__, e.args, 'Request Timeout (ignoring)') except ccxt.ExchangeNotAvailable as e: print(type(e).__name__, e.args, 'Exchange Not Available due to downtime or maintenance (ignoring)') except ccxt.AuthenticationError as e: print(type(e).__name__, e.args, 'Authentication Error (missing API keys, ignoring)') drawingCandles = copy.copy(strategy.candlesticks) if not candlestick.isClosed(): drawingCandles.append(copy.copy(candlestick)) drawingCandles[-1].close = candlestick.currentPrice chart.drawChart(drawingCandles, strategy.trades, strategy.movingAverages) if candlestick.isClosed(): candlestick = BotCandlestick() x+=1 time.sleep(int(10))
def main(argv): startTime = False endTime = False try: opts, args = getopt.getopt(argv,"hp:c:n:s:e:a:",["period=","currency=","points="]) except getopt.GetoptError: print 'trading-bot.py -p <period length> -c <currency pair> -n <period of moving average>' sys.exit(2) print(opts) for opt, arg in opts: if opt == '-h': print 'trading-bot.py -p <period length> -c <currency pair> -n <period of moving average>' sys.exit() elif opt in ("-p", "--period"): if (int(arg) in [300,900,1800,7200,14400,86400]): period = arg else: print 'Poloniex requires periods in 300,900,1800,7200,14400, or 86400 second increments' sys.exit(2) elif opt in ("-c", "--currency"): pair = arg elif opt in ("-n", "--points"): lengthOfMA = int(arg) elif opt in ("-s"): startTime = arg elif opt in ("-e"): endTime = arg elif opt in ("-a"): auto = arg if (startTime): chart = BotChart("poloniex","BTC_XMR",300,True,startTime,endTime) chart2 = BotChart("poloniex","USDT_BTC",300,True,startTime,endTime) chart3 = BotChart("poloniex","USDC_BTC",300,True,startTime,endTime) chart4 = BotChart("poloniex","BTC_ETH",300,True,startTime,endTime) strategy = BotStrategy() strategy2 = BotStrategy() strategy3 = BotStrategy() strategy4 = BotStrategy() print("start1") for candlestick in chart.getPoints(): total = strategy.tick(candlestick) print("Total is: " + str(total)) print("start2") for candlestick in chart2.getPoints(): total = strategy2.tick(candlestick) print("Total is: " + str(total)) print("start3") for candlestick in chart3.getPoints(): total = strategy3.tick(candlestick) print("Total is: " + str(total)) print("start4") for candlestick in chart4.getPoints(): total = strategy4.tick(candlestick) print("Total is: " + str(total)) elif(auto): time = BotTime(10) endTime = time.startDate() startTime = time.endDate() chart = BotChart("poloniex","BTC_XMR",300,True,startTime,endTime) chart2 = BotChart("poloniex","USDT_BTC",300,True,startTime,endTime) chart3 = BotChart("poloniex","USDC_BTC",300,True,startTime,endTime) chart4 = BotChart("poloniex","BTC_ETH",300,True,startTime,endTime) strategy = BotStrategy() strategy2 = BotStrategy() strategy3 = BotStrategy() strategy4 = BotStrategy() print("chart1") for candlestick in chart.getPoints(): total = strategy.tick(candlestick) print("Total is: " + str((total*6972.90))) print("chart2") for candlestick in chart2.getPoints(): total = strategy2.tick(candlestick) print("Total is: " + str((total*0.80))) print("chart3") for candlestick in chart3.getPoints(): total = strategy3.tick(candlestick) print("Total is: " + str((total*0.80))) print("chart4") for candlestick in chart4.getPoints(): total = strategy4.tick(candlestick) print("Total is: " + str((total*6972.90))) else: chart = BotChart("poloniex","BTC_XMR",300,False) strategy = BotStrategy() candlesticks = [] developingCandlestick = BotCandlestick() while True: try: developingCandlestick.tick(chart.getCurrentPrice()) except urllib2.URLError: time.sleep(int(30)) developingCandlestick.tick(chart.getCurrentPrice()) if (developingCandlestick.isClosed()): candlesticks.append(developingCandlestick) strategy.tick(developingCandlestick) developingCandlestick = BotCandlestick() time.sleep(int(30))
def main(argv): # debut = '2016-11-02 14:00:00' # fin = '2018-08-14 20:53:20' try: parser = argparse.ArgumentParser() parser.add_argument("-p", "--period", help="Period length in seconds, 14400 by default", type=int, choices=[300, 900, 1800, 7200, 14400, 86400], default=14400) parser.add_argument("-c", "--currency", help="Currency pair | Ex: USDT_ETH", default='USDT_ETH') parser.add_argument("-b", "--backtest", help="Mode Backtest", action="store_true") parser.add_argument( "-s", "--start", help= "Start time in YYYY-MM-DD HH:MM:SS (for backtesting), '2016-11-02 14:00:00' by default", default='2016-11-02 14:00:00') parser.add_argument( "-e", "--end", help= "End time in YYYY-MM-DD HH:MM:SS (for backtesting), '2018-12-14 20:53:20' by default", default='2018-12-14 20:53:20') parser.add_argument("-S", "--short", help="Enable Short Mode", action="store_true") args = vars(parser.parse_args()) except: print "ArgumentParser Error type -h for help" sys.exit(2) pair = args["currency"] period = args["period"] short_mode = args["short"] if (args["backtest"]): debut = args['start'] fin = args['end'] chart = BotChart("poloniex", pair, period, debut, fin) strategy = stratRsi(period=period, short_mode=short_mode) for candlestick in chart.getPoints(): strategy.tick(candlestick) graphe = PlotGraphe(chart, strategy) graphe.plotChart() try: sigma = chart.getSigma() * float(chart.compteur)**0.5 perf = graphe.perf sharpeRatio = perf / sigma print("\n Perforance: " + str(perf)) print("\n Ratio de Sharpe: " + str(sharpeRatio) + "\n") except Exception as e: pass else: chart = BotChart("poloniex", pair, period, backtest=False) strategy = stratRsi(period, short_mode, backtest=False) candlesticks = [] developingCandlestick = BotCandlestick() while True: try: developingCandlestick.tick(chart.getCurrentPrice()) except urllib2.URLError: time.sleep(int(30)) developingCandlestick.tick(chart.getCurrentPrice()) if (developingCandlestick.isClosed()): candlesticks.append(developingCandlestick) strategy.tick(developingCandlestick) developingCandlestick = BotCandlestick() time.sleep(int(30))
def main(argv): startTime = False endTime = False forwardTest = True movingAverageLength = 20 try: opts, args = getopt.getopt( argv, "hp:c:n:s:e", ["period=", "currency=", "exchange=", "live"]) except getopt.GetoptError: print('trading-bot.py -p <period length> -c <currency pair>') sys.exit(2) for opt, arg in opts: if opt == '-h': print('trading-bot.py -p <period length> -c <currency pair>') sys.exit() elif opt in ("-s"): startTime = float(arg) elif opt in ("-e"): endTime = float(arg) elif opt in ("-p", "--period"): period = int(arg) elif opt in ("-c", "--currency"): pair = str(arg) shared.exchange['pair'] = pair shared.exchange['market'] = pair.split("_")[0] shared.exchange['coin'] = pair.split("_")[1] elif opt in ("--exchange"): if str(arg) not in ['', 'poloniex', 'kraken']: print("Only poloniex and kraken are supported for now") sys.exit() exchange = str(arg) shared.exchange['name'] = exchange elif opt == "--live": print( "You're going live... All losts are your reponsability only!") forwardTest = False if shared.exchange['name'] == "kraken": shared.exchange['pair'] = str(shared.exchange['coin']) + str( shared.exchange['market']) # startTime specified: we are in backtest mode if (startTime): chart = BotChart(period, startTime, endTime) strategy = BotStrategy() strategy.showPortfolio() for candlestick in chart.getPoints(): strategy.tick(candlestick) chart.drawChart(strategy.candlesticks, strategy.movingAverages, strategy.trades) strategy.showPortfolio() else: chart = BotChart(period, False, False, False) strategy = BotStrategy(False, forwardTest) strategy.showPortfolio() candlestick = BotCandlestick(float(period)) x = 0 while True: try: currentPrice = chart.getCurrentPrice() except Exception as e: print(e) print("Error fetching current price") return try: candlestick.tick(currentPrice) except Exception as e: print(e) print("Error fetching tick") return strategy.tick(candlestick) drawingCandles = copy.copy(strategy.candlesticks) if not candlestick.isClosed(): drawingCandles.append(copy.copy(candlestick)) drawingCandles[-1].close = candlestick.currentPrice chart.drawChart(drawingCandles, strategy.movingAverages, strategy.trades) if candlestick.isClosed(): candlestick = BotCandlestick(float(period)) x += 1 time.sleep(int(10))
def main(argv): live = False try: opts, args = getopt.getopt(argv, "", ["live"]) except getopt.GetoptError: print('trading-bot.py') sys.exit(2) for opt, arg in opts: if opt == "--live": print("You're going live... Losses are your responsibility only!") live = True # START_DATE specified: we are in backtest mode if shared.strategy['start_date']: chart = BotChart() strategy = BotStrategy() strategy.showPortfolio() for candlestick in chart.getPoints(): strategy.tick(candlestick) chart.drawChart(strategy.candlesticks, strategy.trades, strategy.movingAverages) strategy.showPortfolio() else: chart = BotChart(False) strategy = BotStrategy(False, live) strategy.showPortfolio() candlestick = BotCandlestick() x = 0 while True: try: currentPrice = chart.getCurrentPrice() candlestick.tick(currentPrice) strategy.tick(candlestick) except ccxt.NetworkError as e: print(type(e).__name__, e.args, 'Exchange error (ignoring)') except ccxt.ExchangeError as e: print(type(e).__name__, e.args, 'Exchange error (ignoring)') except ccxt.DDoSProtection as e: print(type(e).__name__, e.args, 'DDoS Protection (ignoring)') except ccxt.RequestTimeout as e: print(type(e).__name__, e.args, 'Request Timeout (ignoring)') except ccxt.ExchangeNotAvailable as e: print( type(e).__name__, e.args, 'Exchange Not Available due to downtime or maintenance (ignoring)' ) except ccxt.AuthenticationError as e: print( type(e).__name__, e.args, 'Authentication Error (missing API keys, ignoring)') drawingCandles = copy.copy(strategy.candlesticks) if not candlestick.isClosed(): drawingCandles.append(copy.copy(candlestick)) drawingCandles[-1].close = candlestick.currentPrice chart.drawChart(drawingCandles, strategy.trades, strategy.movingAverages) if candlestick.isClosed(): candlestick = BotCandlestick() x += 1 time.sleep(shared.exchange['interval'])