Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from binance.client import Client
- import matplotlib.pyplot as plt
- import numpy as np
- from datetime import datetime
- import talib as ta
- import statsmodels.api as sm
- import os, sys
- class Trader:
- def __init__(self, file):
- self.connect(file)
- """ Creates Binance client """
- def connect(self,file):
- lines = [line.rstrip('\n') for line in open(file)]
- key = lines[0]
- secret = lines[1]
- self.client = Client(key, secret)
- """ Gets all account balances """
- def getBalances(self):
- prices = self.client.get_withdraw_history()
- return prices
- filename = 'credentials.txt'
- trader = Trader(filename)
- trading_pairs = [
- '1INCHUSDT','AAVEUSDT','ACMUSDT','ADAUSDT','ADXUSDT',
- 'AGLDUSDT','AIONUSDT','AKROUSDT','ALGOUSDT','ALICEUSDT',
- 'ALPACAUSDT','ALPHAUSDT','ANKRUSDT','ANTUSDT','ARDRUSDT',
- 'ARPAUSDT','ARUSDT','ASRUSDT','ATAUSDT','ATMUSDT',
- 'ATOMUSDT','AUCTIONUSDT','AUDIOUSDT','AUTOUSDT','AVAUSDT',
- 'AVAXUSDT','AXSUSDT','BADGERUSDT','BAKEUSDT','BALUSDT',
- 'BANDUSDT','BARUSDT','BATUSDT','BCHUSDT','BEAMUSDT',
- 'BELUSDT','BETAUSDT','BLZUSDT','BNBUSDT','BNTUSDT',
- 'BNXUSDT','BONDUSDT','BTCSTUSDT','BTCUSDT','BTGUSDT',
- 'BTSUSDT','BTTUSDT','BURGERUSDT','BZRXUSDT','C98USDT',
- 'CAKEUSDT','CELOUSDT','CELRUSDT','CFXUSDT','CHESSUSDT',
- 'CHRUSDT','CHZUSDT','CITYUSDT','CKBUSDT','CLVUSDT',
- 'COCOSUSDT','COMPUSDT','COSUSDT','COTIUSDT','CRVUSDT',
- 'CTKUSDT','CTSIUSDT','CTXCUSDT','CVCUSDT','CVPUSDT',
- 'DARUSDT','DASHUSDT','DATAUSDT','DCRUSDT','DEGOUSDT',
- 'DENTUSDT','DEXEUSDT','DFUSDT','DGBUSDT','DIAUSDT',
- 'DNTUSDT','DOCKUSDT','DODOUSDT','DOGEUSDT','DOTUSDT',
- 'DREPUSDT','DUSKUSDT','DYDXUSDT','EGLDUSDT','ELFUSDT',
- 'ENJUSDT','ENSUSDT','EOSUSDT','EPSUSDT','ERNUSDT',
- 'ETCUSDT','ETHUSDT','FARMUSDT','FETUSDT','FIDAUSDT',
- 'FILUSDT','FIOUSDT','FIROUSDT','FISUSDT','FLMUSDT',
- 'FLOWUSDT','FORTHUSDT','FORUSDT','FRONTUSDT','FTMUSDT',
- 'FTTUSDT','FUNUSDT','GALAUSDT','GHSTUSDT','GNOUSDT',
- 'GRTUSDT','GTCUSDT','GTOUSDT','GXSUSDT','HARDUSDT',
- 'HBARUSDT','HIVEUSDT','HNTUSDT','HOTUSDT','ICPUSDT',
- 'ICXUSDT','IDEXUSDT','ILVUSDT','INJUSDT','IOSTUSDT',
- 'IOTAUSDT','IOTXUSDT','IRISUSDT','JSTUSDT','JUVUSDT',
- 'KAVAUSDT','KEEPUSDT','KEYUSDT','KLAYUSDT','KMDUSDT',
- 'KNCUSDT','KSMUSDT','LAZIOUSDT','LINAUSDT','LINKUSDT',
- 'LITUSDT','LPTUSDT','LRCUSDT','LSKUSDT','LTCUSDT',
- 'LTOUSDT','LUNAUSDT','MANAUSDT','MASKUSDT','MATICUSDT',
- 'MBLUSDT','MBOXUSDT','MDTUSDT','MDXUSDT','MFTUSDT',
- 'MINAUSDT','MIRUSDT','MITHUSDT','MKRUSDT','MLNUSDT',
- 'MOVRUSDT','MTLUSDT','NANOUSDT','NBSUSDT','NEARUSDT',
- 'NEOUSDT','NKNUSDT','NMRUSDT','NULSUSDT','NUUSDT',
- 'OCEANUSDT','OGNUSDT','OGUSDT','OMGUSDT','OMUSDT',
- 'ONEUSDT','ONGUSDT','ONTUSDT','ORNUSDT','OXTUSDT',
- 'PAXGUSDT','PERLUSDT','PERPUSDT','PHAUSDT','PNTUSDT',
- 'POLSUSDT','POLYUSDT','PONDUSDT','PSGUSDT','PUNDIXUSDT',
- 'QNTUSDT','QTUMUSDT','QUICKUSDT','RADUSDT','RAMPUSDT',
- 'RAREUSDT','RAYUSDT','REEFUSDT','RENUSDT','REPUSDT',
- 'REQUSDT','RGTUSDT','RIFUSDT','RLCUSDT','ROSEUSDT',
- 'RSRUSDT','RUNEUSDT','RVNUSDT','SANDUSDT','SCUSDT',
- 'SFPUSDT','SHIBUSDT','SKLUSDT','SLPUSDT','SNXUSDT',
- 'SOLUSDT','SRMUSDT','STMXUSDT','STORJUSDT','STPTUSDT',
- 'STRAXUSDT','STXUSDT','SUNUSDT','SUPERUSDT','SUSHIUSDT',
- 'SXPUSDT','SYSUSDT','TCTUSDT','TFUELUSDT','THETAUSDT',
- 'TKOUSDT','TLMUSDT','TOMOUSDT','TORNUSDT','TRBUSDT',
- 'TRIBEUSDT','TROYUSDT','TRUUSDT','TRXUSDT','TVKUSDT',
- 'TWTUSDT','UMAUSDT','UNFIUSDT','UNIUSDT','UTKUSDT',
- 'VETUSDT','VIDTUSDT','VITEUSDT','VTHOUSDT','WANUSDT',
- 'WAVESUSDT','WAXPUSDT','WINGUSDT','WNXMUSDT','WRXUSDT',
- 'WTCUSDT','XECUSDT','XEMUSDT','XLMUSDT','XMRUSDT',
- 'XRPUSDT','XTZUSDT','XVGUSDT','XVSUSDT','YFIIUSDT',
- 'YFIUSDT','YGGUSDT','ZECUSDT','ZENUSDT','ZILUSDT',
- 'ZRXUSDT'
- ]
- filtered_pairs1 = []
- filtered_pairs2 = []
- filtered_pairs3 = []
- selected_pair = []
- selected_pairSINE = []
- def filter1(pair):
- interval = '1h'
- symbol = pair
- klines = trader.client.get_klines(symbol=symbol,interval=interval)
- open_time = [int(entry[0]) for entry in klines]
- close = [float(entry[4]) for entry in klines]
- close_array = np.asarray(close)
- print("on 1h timeframe " + symbol)
- print()
- x = close
- y = range(len(x))
- best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
- best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
- best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
- if x[-1] < best_fit_line3[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
- filtered_pairs1.append(symbol)
- print('found')
- #plt.figure(figsize=(8,6))
- #plt.grid(True)
- #plt.plot(x)
- #plt.plot(best_fit_line1, '--', color='r')
- #plt.plot(best_fit_line2, '--', color='r')
- #plt.plot(best_fit_line3, '--', color='r')
- #plt.show(block=False)
- #plt.pause(6)
- #plt.close()
- elif x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
- filtered_pairs1.append(symbol)
- print('found')
- #plt.figure(figsize=(8,6))
- #plt.grid(True)
- #plt.plot(x)
- #plt.plot(best_fit_line1, '--', color='r')
- #plt.plot(best_fit_line2, '--', color='r')
- #plt.plot(best_fit_line3, '--', color='r')
- #plt.show(block=False)
- #plt.pause(6)
- #plt.close()
- else:
- print('searching')
- def filter2(filtered_pairs1):
- interval = '15m'
- symbol = filtered_pairs1
- klines = trader.client.get_klines(symbol=symbol,interval=interval)
- open_time = [int(entry[0]) for entry in klines]
- close = [float(entry[4]) for entry in klines]
- close_array = np.asarray(close)
- print("on 15min timeframe " + symbol)
- print()
- x = close
- y = range(len(x))
- best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
- best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
- best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
- if x[-1] < best_fit_line3[-1] and best_fit_line1[0] < best_fit_line1[-1]:
- filtered_pairs2.append(symbol)
- print('found')
- #plt.figure(figsize=(8,6))
- #plt.grid(True)
- #plt.plot(x)
- #plt.plot(best_fit_line1, '--', color='r')
- #plt.plot(best_fit_line2, '--', color='r')
- #plt.plot(best_fit_line3, '--', color='r')
- #plt.show(block=False)
- #plt.pause(6)
- #plt.close()
- if x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
- filtered_pairs2.append(symbol)
- print('found')
- #plt.figure(figsize=(8,6))
- #plt.grid(True)
- #plt.plot(x)
- #plt.plot(best_fit_line1, '--', color='r')
- #plt.plot(best_fit_line2, '--', color='r')
- #plt.plot(best_fit_line3, '--', color='r')
- #plt.show(block=False)
- #plt.pause(6)
- #plt.close()
- def filter3(filtered_pairs2):
- interval = '5m'
- symbol = filtered_pairs2
- klines = trader.client.get_klines(symbol=symbol,interval=interval)
- open_time = [int(entry[0]) for entry in klines]
- close = [float(entry[4]) for entry in klines]
- close_array = np.asarray(close)
- print("on 5m timeframe " + symbol)
- #min = ta.MIN(close_array, timeperiod=30)
- #max = ta.MAX(close_array, timeperiod=30)
- #real = ta.HT_TRENDLINE(close_array)
- #wcl = ta.WCLPRICE(max, min, close_array)
- #print(close[-1])
- print()
- #print(min[-1])
- #print(max[-1])
- #print(real[-1])
- x = close
- y = range(len(x))
- best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
- best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
- best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
- if x[-1] < best_fit_line1[-1]:
- filtered_pairs3.append(symbol)
- print('found')
- #plt.figure(figsize=(8,6))
- #plt.title(symbol)
- #plt.grid(True)
- #plt.plot(close)
- #plt.plot(best_fit_line1, '--', color='r')
- #plt.plot(best_fit_line2, '--', color='r')
- #plt.plot(best_fit_line3, '--', color='r')
- #plt.plot(close)
- #plt.plot(min)
- #plt.plot(max)
- #plt.plot(real)
- #plt.show(block=False)
- #plt.pause(5)
- #plt.close()
- else:
- print('searching')
- def momentum(filtered_pairs3):
- interval = '1m'
- symbol = filtered_pairs3
- klines = trader.client.get_klines(symbol=symbol,interval=interval)
- open_time = [int(entry[0]) for entry in klines]
- close = [float(entry[4]) for entry in klines]
- close_array = np.asarray(close)
- print("on 1m timeframe " + symbol)
- #real = ta.CMO(close_array, timeperiod=14)
- #print(real[-1])
- sine, leadsine = ta.HT_SINE(close_array)
- if sine[-1] <= -0.5:
- print("found dip on time series sinewave")
- selected_pair.append(symbol)
- selected_pairSINE.append(sine[-1])
- print(sine[-1])
- #if real[-1] < -50:
- #print('oversold dip found')
- #selected_pair.append(symbol)
- #selected_pairCMO.append(real[-1])
- else:
- print('searching')
- for i in trading_pairs:
- output = filter1(i)
- print(filtered_pairs1)
- for i in filtered_pairs1:
- output = filter2(i)
- print(filtered_pairs2)
- for i in filtered_pairs2:
- output = filter3(i)
- print(filtered_pairs3)
- for i in filtered_pairs3:
- output = momentum(i)
- print(selected_pair)
- if len(selected_pair) > 1:
- print('dips are more then 1 on time series')
- print(selected_pair)
- #print(selected_pairCMO)
- if min(selected_pair) in selected_pairSINE:
- #print(selected_pairSINE.index(min(selected_pairSINE)))
- position = selected_pairSINE.index(min(selected_pairSINE))
- for id, value in enumerate(selected_pair):
- if id == position:
- print(selected_pair[id])
- #sys.exit()
- elif len(selected_pair) == 1:
- print('1 dip found')
- print(selected_pair)
- #sys.exit()
- else:
- print('no more dips for the moment, restart script...')
- print(selected_pair)
- #print(selected_pairCMO)
- #os.execl(sys.executable, sys.executable, *sys.argv)
- sys.exit(0)
- sys.exit()
- exit()
Add Comment
Please, Sign In to add comment