xmd79

dip finder 4h 2h 1h 15min && 5min tfs

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