Advertisement
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
- import pandas as pd
- 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)
- # request info on all spot symbols
- # exchange_info = trader.get_exchange_info()
- # trading_pairs = [info['symbol'] for info in exchange_info['symbols']]
- trading_pairs = [
- '1INCHUSDT','AAVEUSDT','ACAUSDT','ACHUSDT','ACMUSDT',
- 'ADAUSDT','ADXUSDT','AGLDUSDT','AIONUSDT','AKROUSDT',
- 'ALCXUSDT','ALGOUSDT','ALICEUSDT','ALPACAUSDT','ALPHAUSDT',
- 'ALPINEUSDT','AMPUSDT','ANCUSDT','ANKRUSDT','ANTUSDT',
- 'APEUSDT','API3USDT','ARDRUSDT','ARPAUSDT','ARUSDT',
- 'ASRUSDT','ASTRUSDT','ATAUSDT','ATMUSDT','ATOMUSDT',
- 'AUCTIONUSDT','AUDIOUSDT','AUTOUSDT','AVAUSDT',
- 'AVAXUSDT','AXSUSDT','BADGERUSDT','BAKEUSDT','BALUSDT',
- 'BANDUSDT','BARUSDT','BATUSDT','BCHUSDT','BEAMUSDT',
- 'BELUSDT','BETAUSDT','BICOUSDT','BLZUSDT','BNBUSDT',
- 'BNTUSDT','BNXUSDT','BONDUSDT','BSWUSDT','BTCSTUSDT',
- 'BTCUSDT','BTGUSDT','BTSUSDT','BTTCUSDT','BURGERUSDT',
- 'C98USDT','CAKEUSDT','CELOUSDT','CELRUSDT','CFXUSDT',
- 'CHESSUSDT','CHRUSDT','CHZUSDT','CITYUSDT','CKBUSDT',
- 'CLVUSDT','COCOSUSDT','COMPUSDT','COSUSDT','COTIUSDT',
- 'CRVUSDT','CTKUSDT','CTSIUSDT','CTXCUSDT','CVCUSDT',
- 'CVPUSDT','CVXUSDT','DARUSDT','DASHUSDT','DATAUSDT',
- 'DCRUSDT','DEGOUSDT','DENTUSDT','DEXEUSDT','DFUSDT',
- 'DGBUSDT','DIAUSDT','DNTUSDT','DOCKUSDT','DODOUSDT',
- 'DOGEUSDT','DOTUSDT','DREPUSDT','DUSKUSDT','DYDXUSDT',
- 'EGLDUSDT','ELFUSDT','ENJUSDT','ENSUSDT','EOSUSDT',
- 'EPXUSDT','ERNUSDT','ETCUSDT','ETHUSDT','FARMUSDT',
- 'FETUSDT','FIDAUSDT','FILUSDT','FIOUSDT','FIROUSDT',
- 'FISUSDT','FLMUSDT','FLOWUSDT','FLUXUSDT','FORTHUSDT',
- 'FORUSDT','FRONTUSDT','FTMUSDT','FTTUSDT','FUNUSDT',
- 'FXSUSDT','GALAUSDT','GALUSDT','GHSTUSDT','GLMRUSDT',
- 'GMTUSDT','GNOUSDT','GRTUSDT','GTCUSDT','GTOUSDT',
- 'HARDUSDT','HBARUSDT','HIGHUSDT','HIVEUSDT','HNTUSDT',
- 'HOTUSDT','ICPUSDT','ICXUSDT','IDEXUSDT','ILVUSDT',
- 'IMXUSDT','INJUSDT','IOSTUSDT','IOTAUSDT','IOTXUSDT',
- 'IRISUSDT','JASMYUSDT','JOEUSDT','JSTUSDT','JUVUSDT',
- 'KAVAUSDT','KDAUSDT','KEYUSDT','KLAYUSDT','KMDUSDT',
- 'KNCUSDT','KP3RUSDT','KSMUSDT','LAZIOUSDT','LDOUSDT',
- 'LINAUSDT','LINKUSDT','LITUSDT','LOKAUSDT','LPTUSDT',
- 'LRCUSDT','LSKUSDT','LTCUSDT','LTOUSDT','MANAUSDT',
- 'MASKUSDT','MATICUSDT','MBLUSDT','MBOXUSDT','MCUSDT',
- 'MDTUSDT','MDXUSDT','MFTUSDT','MINAUSDT','MIRUSDT',
- 'MITHUSDT','MKRUSDT','MLNUSDT','MOBUSDT','MOVRUSDT',
- 'MTLUSDT','MULTIUSDT','NBSUSDT','NEARUSDT','NEOUSDT',
- 'NEXOUSDT','NKNUSDT','NMRUSDT','NULSUSDT','OCEANUSDT',
- 'OGNUSDT','OGUSDT','OMGUSDT','OMUSDT','ONEUSDT',
- 'ONGUSDT','ONTUSDT','OOKIUSDT','ORNUSDT','OXTUSDT',
- 'PAXGUSDT','PEOPLEUSDT','PERLUSDT','PERPUSDT','PHAUSDT',
- 'PLAUSDT','PNTUSDT','POLSUSDT','POLYUSDT','PONDUSDT',
- 'PORTOUSDT','POWRUSDT','PSGUSDT','PUNDIXUSDT','PYRUSDT',
- 'QIUSDT','QNTUSDT','QTUMUSDT','QUICKUSDT','RADUSDT',
- 'RAMPUSDT','RAREUSDT','RAYUSDT','REEFUSDT','REIUSDT',
- 'RENUSDT','REPUSDT','REQUSDT','RIFUSDT','RLCUSDT',
- 'RNDRUSDT','ROSEUSDT','RSRUSDT','RUNEUSDT','RVNUSDT',
- 'SANDUSDT','SANTOSUSDT','SCRTUSDT','SCUSDT','SFPUSDT',
- 'SHIBUSDT','SKLUSDT','SLPUSDT','SNXUSDT','SOLUSDT',
- 'SPELLUSDT','SRMUSDT','STMXUSDT','STORJUSDT','STPTUSDT',
- 'STRAXUSDT','STXUSDT','SUNUSDT','SUPERUSDT','SUSHIUSDT',
- 'SXPUSDT','SYSUSDT','TCTUSDT','TFUELUSDT','THETAUSDT',
- 'TKOUSDT','TLMUSDT','TOMOUSDT','TORNUSDT','TRBUSDT',
- 'TRIBEUSDT','TROYUSDT','TRUUSDT','TRXUSDT','TUSDT',
- 'TVKUSDT','TWTUSDT','UMAUSDT','UNFIUSDT','UNIUSDT',
- 'UTKUSDT','VETUSDT','VGXUSDT','VIDTUSDT','VITEUSDT',
- 'VOXELUSDT','VTHOUSDT','WANUSDT','WAVESUSDT','WAXPUSDT',
- 'WINGUSDT','WINUSDT','WNXMUSDT','WOOUSDT','WRXUSDT',
- 'WTCUSDT','XECUSDT','XEMUSDT','XLMUSDT','XMRUSDT',
- 'XNOUSDT','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 = '2h'
- 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 2h 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 = '1h'
- 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 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_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 = '15m'
- 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 15m 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 = '5m'
- 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 5m 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])
- real = ta.CMO(close_array, timeperiod=14)
- print(real[-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)
- 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])
- #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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement