xmd79

dip finder 4h 2h 15min 5min tfs

Dec 15th, 2022
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.58 KB | None | 0 0
  1. from binance.client import Client
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. from datetime import datetime
  5. import talib as ta
  6. #import statsmodels.api as sm
  7. import os, sys
  8.  
  9. import asyncio
  10.  
  11.  
  12. class Trader:
  13. def __init__(self, file):
  14. self.connect(file)
  15.  
  16. """ Creates Binance client """
  17. def connect(self,file):
  18. lines = [line.rstrip('\n') for line in open(file)]
  19. key = lines[0]
  20. secret = lines[1]
  21. self.client = Client(key, secret)
  22.  
  23. """ Gets all account balances """
  24. def getBalances(self):
  25. prices = self.client.get_withdraw_history()
  26. return prices
  27.  
  28. filename = 'credentials.txt'
  29. trader = Trader(filename)
  30.  
  31.  
  32.  
  33. filtered_pairs1 = []
  34. filtered_pairs2 = []
  35. filtered_pairs3 = []
  36. selected_pair = []
  37. selected_pairCMO = []
  38.  
  39.  
  40. trading_pairs = [
  41. '1INCHUSDT','AAVEUSDT','ACAUSDT','ACHUSDT','ACMUSDT',
  42. 'ADAUSDT','ADXUSDT','AGLDUSDT','AIONUSDT','AKROUSDT',
  43. 'ALCXUSDT','ALGOUSDT','ALICEUSDT','ALPACAUSDT','ALPHAUSDT',
  44. 'ALPINEUSDT','AMPUSDT','ANCUSDT','ANKRUSDT','ANTUSDT',
  45. 'APEUSDT','API3USDT','APTUSDT','ARDRUSDT','ARPAUSDT','ARUSDT',
  46. 'ASRUSDT','ASTRUSDT','ATAUSDT','ATMUSDT','ATOMUSDT',
  47. 'AUCTIONUSDT','AUDIOUSDT','AUTOUSDT','AVAUSDT',
  48. 'AVAXUSDT','AXSUSDT','BADGERUSDT','BAKEUSDT','BALUSDT',
  49. 'BANDUSDT','BARUSDT','BATUSDT','BCHUSDT','BEAMUSDT',
  50. 'BELUSDT','BETAUSDT','BICOUSDT','BIFIUSDT','BLZUSDT','BNBUSDT',
  51. 'BNTUSDT','BNXUSDT','BONDUSDT','BSWUSDT',
  52. 'BTCUSDT','BTSUSDT','BTTCUSDT','BURGERUSDT',
  53. 'C98USDT','CAKEUSDT','CELOUSDT','CELRUSDT','CFXUSDT',
  54. 'CHESSUSDT','CHRUSDT','CHZUSDT','CITYUSDT','CKBUSDT',
  55. 'CLVUSDT','COCOSUSDT','COMPUSDT','COSUSDT','COTIUSDT',
  56. 'CRVUSDT','CTKUSDT','CTSIUSDT','CTXCUSDT','CVCUSDT',
  57. 'CVPUSDT','CVXUSDT','DARUSDT','DASHUSDT','DATAUSDT',
  58. 'DCRUSDT','DEGOUSDT','DENTUSDT','DEXEUSDT','DFUSDT',
  59. 'DGBUSDT','DIAUSDT','DOCKUSDT','DODOUSDT',
  60. 'DOGEUSDT','DOTUSDT','DREPUSDT','DUSKUSDT','DYDXUSDT',
  61. 'EGLDUSDT','ELFUSDT','ENJUSDT','ENSUSDT','EOSUSDT',
  62. 'EPXUSDT','ERNUSDT','ETCUSDT','ETHUSDT','FARMUSDT',
  63. 'FETUSDT','FIDAUSDT','FILUSDT','FIOUSDT','FIROUSDT',
  64. 'FISUSDT','FLMUSDT','FLOWUSDT','FLUXUSDT','FORTHUSDT',
  65. 'FORUSDT','FRONTUSDT','FTMUSDT','FUNUSDT',
  66. 'FXSUSDT','GALAUSDT','GALUSDT','GHSTUSDT','GLMRUSDT',
  67. 'GMTUSDT','GNOUSDT','GRTUSDT','GTCUSDT','GTOUSDT',
  68. 'HARDUSDT','HBARUSDT','HFTUSDT','HIGHUSDT','HIVEUSDT',
  69. 'HOTUSDT','ICPUSDT','ICXUSDT','IDEXUSDT','ILVUSDT',
  70. 'IMXUSDT','INJUSDT','IOSTUSDT','IOTAUSDT','IOTXUSDT',
  71. 'IRISUSDT','JASMYUSDT','JOEUSDT','JSTUSDT','JUVUSDT',
  72. 'KAVAUSDT','KDAUSDT','KEYUSDT','KLAYUSDT','KMDUSDT',
  73. 'KNCUSDT','KP3RUSDT','KSMUSDT','LAZIOUSDT','LDOUSDT','LEVERUSDT',
  74. 'LINAUSDT','LINKUSDT','LITUSDT','LOKAUSDT','LPTUSDT',
  75. 'LRCUSDT','LSKUSDT','LTCUSDT','LTOUSDT','LUNAUSDT','LUNCUSDT','MANAUSDT',
  76. 'MASKUSDT','MATICUSDT','MBLUSDT','MBOXUSDT','MCUSDT',
  77. 'MDTUSDT','MDXUSDT','MFTUSDT','MINAUSDT','MIRUSDT',
  78. 'MITHUSDT','MKRUSDT','MLNUSDT','MOBUSDT','MOVRUSDT',
  79. 'MTLUSDT','MULTIUSDT','NEBLUSDT','NEARUSDT','NEOUSDT',
  80. 'NEXOUSDT','NKNUSDT','NMRUSDT','NULSUSDT','OCEANUSDT',
  81. 'OGNUSDT','OGUSDT','OMGUSDT','OMUSDT','ONEUSDT',
  82. 'ONGUSDT','ONTUSDT','OOKIUSDT','ORNUSDT','OSMOUSDT','OXTUSDT',
  83. 'PAXGUSDT','PEOPLEUSDT','PERLUSDT','PERPUSDT','PHAUSDT','PHBUSDT',
  84. 'PLAUSDT','PNTUSDT','POLSUSDT','POLYXUSDT','PONDUSDT',
  85. 'PORTOUSDT','POWRUSDT','PSGUSDT','PUNDIXUSDT','PYRUSDT',
  86. 'QIUSDT','QNTUSDT','QTUMUSDT','QUICKUSDT','RADUSDT',
  87. 'RAREUSDT','RAYUSDT','REEFUSDT','REIUSDT',
  88. 'RENUSDT','REPUSDT','REQUSDT','RIFUSDT','RLCUSDT',
  89. 'RNDRUSDT','ROSEUSDT','RSRUSDT','RUNEUSDT','RVNUSDT',
  90. 'SANDUSDT','SANTOSUSDT','SCRTUSDT','SCUSDT','SFPUSDT',
  91. 'SHIBUSDT','SKLUSDT','SLPUSDT','SNXUSDT','SOLUSDT',
  92. 'SPELLUSDT','SRMUSDT','STEEMUSDT','STGUSDT','STMXUSDT','STORJUSDT','STPTUSDT',
  93. 'STRAXUSDT','STXUSDT','SUNUSDT','SUPERUSDT','SUSHIUSDT',
  94. 'SXPUSDT','SYSUSDT','TFUELUSDT','THETAUSDT',
  95. 'TKOUSDT','TLMUSDT','TOMOUSDT','TORNUSDT','TRBUSDT',
  96. 'TRIBEUSDT','TROYUSDT','TRUUSDT','TRXUSDT','TUSDT',
  97. 'TVKUSDT','TWTUSDT','UMAUSDT','UNFIUSDT','UNIUSDT',
  98. 'UTKUSDT','VETUSDT','VGXUSDT','VIDTUSDT','VITEUSDT',
  99. 'VOXELUSDT','VTHOUSDT','WANUSDT','WAVESUSDT','WAXPUSDT',
  100. 'WINGUSDT','WINUSDT','WNXMUSDT','WOOUSDT','WRXUSDT',
  101. 'WTCUSDT','XECUSDT','XEMUSDT','XLMUSDT','XMRUSDT',
  102. 'XNOUSDT','XRPUSDT','XTZUSDT','XVGUSDT','XVSUSDT',
  103. 'YFIIUSDT','YFIUSDT','YGGUSDT','ZECUSDT','ZENUSDT',
  104. 'ZILUSDT','ZRXUSDT'
  105. ]
  106.  
  107.  
  108.  
  109. def filter1(pair):
  110.  
  111. interval = '4h'
  112. symbol = pair
  113. klines = trader.client.get_klines(symbol=symbol,interval=interval)
  114. open_time = [int(entry[0]) for entry in klines]
  115. close = [float(entry[4]) for entry in klines]
  116. close_array = np.asarray(close)
  117.  
  118. print("on 4h timeframe " + symbol)
  119.  
  120. x = close
  121. y = range(len(x))
  122.  
  123. best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  124. best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  125. best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  126.  
  127. if x[-1] < best_fit_line3[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
  128. filtered_pairs1.append(symbol)
  129. print('found')
  130.  
  131. #plt.figure(figsize=(8,6))
  132. #plt.grid(True)
  133. #plt.plot(x)
  134. #plt.plot(best_fit_line1, '--', color='r')
  135. #plt.plot(best_fit_line2, '--', color='r')
  136. #plt.plot(best_fit_line3, '--', color='r')
  137. #plt.show(block=False)
  138. #plt.pause(6)
  139. #plt.close()
  140.  
  141. elif x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
  142. filtered_pairs1.append(symbol)
  143. print('found')
  144.  
  145. #plt.figure(figsize=(8,6))
  146. #plt.grid(True)
  147. #plt.plot(x)
  148. #plt.plot(best_fit_line1, '--', color='r')
  149. #plt.plot(best_fit_line2, '--', color='r')
  150. #plt.plot(best_fit_line3, '--', color='r')
  151. #plt.show(block=False)
  152. #plt.pause(6)
  153. #plt.close()
  154.  
  155. else:
  156. print('searching')
  157.  
  158. def filter2(filtered_pairs1):
  159. interval = '2h'
  160. symbol = filtered_pairs1
  161. klines = trader.client.get_klines(symbol=symbol,interval=interval)
  162. open_time = [int(entry[0]) for entry in klines]
  163. close = [float(entry[4]) for entry in klines]
  164. close_array = np.asarray(close)
  165.  
  166. print("on 2h " + symbol)
  167.  
  168. x = close
  169. y = range(len(x))
  170.  
  171. best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  172. best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  173. best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  174.  
  175. if x[-1] < best_fit_line3[-1] and best_fit_line1[0] < best_fit_line1[-1]:
  176. filtered_pairs2.append(symbol)
  177. print('found')
  178.  
  179. #plt.figure(figsize=(8,6))
  180. #plt.grid(True)
  181. #plt.plot(x)
  182. #plt.plot(best_fit_line1, '--', color='r')
  183. #plt.plot(best_fit_line2, '--', color='r')
  184. #plt.plot(best_fit_line3, '--', color='r')
  185. #plt.show(block=False)
  186. #plt.pause(6)
  187. #plt.close()
  188.  
  189. if x[-1] < best_fit_line3[-1] and best_fit_line1[0] >= best_fit_line1[-1]:
  190. filtered_pairs2.append(symbol)
  191. print('found')
  192.  
  193. #plt.figure(figsize=(8,6))
  194. #plt.grid(True)
  195. #plt.plot(x)
  196. #plt.plot(best_fit_line1, '--', color='r')
  197. #plt.plot(best_fit_line2, '--', color='r')
  198. #plt.plot(best_fit_line3, '--', color='r')
  199. #plt.show(block=False)
  200. #plt.pause(6)
  201. #plt.close()
  202.  
  203. def filter3(filtered_pairs2):
  204. interval = '15m'
  205. symbol = filtered_pairs2
  206. klines = trader.client.get_klines(symbol=symbol,interval=interval)
  207. open_time = [int(entry[0]) for entry in klines]
  208. close = [float(entry[4]) for entry in klines]
  209. close_array = np.asarray(close)
  210.  
  211. print("on 15m timeframe " + symbol)
  212.  
  213. #min = ta.MIN(close_array, timeperiod=30)
  214. #max = ta.MAX(close_array, timeperiod=30)
  215.  
  216. #real = ta.HT_TRENDLINE(close_array)
  217. #wcl = ta.WCLPRICE(max, min, close_array)
  218.  
  219. print(close[-1])
  220. print()
  221. #print(min[-1])
  222. #print(max[-1])
  223. #print(real[-1])
  224.  
  225. x = close
  226. y = range(len(x))
  227.  
  228. best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  229. best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  230. best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  231.  
  232. if x[-1] < best_fit_line1[-1]:
  233. filtered_pairs3.append(symbol)
  234. print('found')
  235.  
  236. #plt.figure(figsize=(8,6))
  237. #plt.title(symbol)
  238. #plt.grid(True)
  239. #plt.plot(close)
  240. #plt.plot(best_fit_line1, '--', color='r')
  241. #plt.plot(best_fit_line2, '--', color='r')
  242. #plt.plot(best_fit_line3, '--', color='r')
  243. #plt.plot(close)
  244. #plt.plot(min)
  245. #plt.plot(max)
  246. #plt.plot(real)
  247. #plt.show(block=False)
  248. #plt.pause(5)
  249. #plt.close()
  250.  
  251. else:
  252. print('searching')
  253.  
  254.  
  255. def momentum(filtered_pairs3):
  256. interval = '5m'
  257. symbol = filtered_pairs3
  258. klines = trader.client.get_klines(symbol=symbol,interval=interval)
  259. open_time = [int(entry[0]) for entry in klines]
  260. close = [float(entry[4]) for entry in klines]
  261. close_array = np.asarray(close)
  262.  
  263. print()
  264. print("on 5m timeframe " + symbol)
  265.  
  266. real = ta.CMO(close_array, timeperiod=14)
  267. #print(real[-1])
  268.  
  269. if real[-1] < -50:
  270. print('oversold dip found')
  271. selected_pair.append(symbol)
  272. selected_pairCMO.append(real[-1])
  273.  
  274. else:
  275. print('searching')
  276.  
  277.  
  278. for i in trading_pairs:
  279. output = filter1(i)
  280. print(filtered_pairs1)
  281.  
  282. for i in filtered_pairs1:
  283. output = filter2(i)
  284. print(filtered_pairs2)
  285.  
  286. for i in filtered_pairs2:
  287. output = filter3(i)
  288. print(filtered_pairs3)
  289.  
  290. for i in filtered_pairs3:
  291. output = momentum(i)
  292. print(selected_pair)
  293.  
  294. if len(selected_pair) > 1:
  295. print('dips are more then 1 oversold')
  296. print(selected_pair)
  297. #print(selected_pairCMO)
  298.  
  299. if min(selected_pairCMO) in selected_pairCMO:
  300. #print(selected_pairCMO.index(min(selected_pairCMO)))
  301. position = selected_pairCMO.index(min(selected_pairCMO))
  302.  
  303. for id, value in enumerate(selected_pair):
  304. if id == position:
  305. print(selected_pair[id])
  306. #sys.exit()
  307.  
  308. elif len(selected_pair) == 1:
  309. print('1 dip found')
  310. print(selected_pair)
  311. #print(selected_pairCMO)
  312. #sys.exit()
  313.  
  314. else:
  315. print('no oversold dips for the moment, rescan dips...')
  316.  
  317. #print(selected_pair)
  318. #print(selected_pairCMO)
  319. #os.execl(sys.executable, sys.executable, *sys.argv)
  320.  
  321.  
  322.  
  323. sys.exit(0)
  324. sys.exit()
  325. exit()
  326.  
  327.  
Advertisement
Add Comment
Please, Sign In to add comment