SHARE
TWEET

market dip finder

cyberghostTM Jan 17th, 2020 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. #from pandas.plotting import register_matplotlib_converters
  7. #register_matplotlib_converters()
  8. #import pandas as pd
  9. import statsmodels.api as sm
  10. import os, sys
  11.  
  12.  
  13. class Trader:
  14.     def __init__(self, file):
  15.         self.connect(file)
  16.  
  17.     """ Creates Binance client """
  18.     def connect(self,file):
  19.         lines = [line.rstrip('\n') for line in open(file)]
  20.         key = lines[0]
  21.         secret = lines[1]
  22.         self.client = Client(key, secret)
  23.  
  24.     """ Gets all account balances """
  25.     def getBalances(self):
  26.         prices = self.client.get_withdraw_history()
  27.         return prices
  28.  
  29. filename = 'credentials.txt'
  30. trader = Trader(filename)
  31.  
  32. trading_pairs = [
  33.     'ADAUSDT','ALGOUSDT','ANKRUSDT','ARPAUSDT',
  34.     'ATOMUSDT','BANDUSDT','BATUSDT','BCHUSDT',
  35.     'BEAMUSDT','BNBUSDT','BTCUSDT','BTTUSDT',
  36.     'CELRUSDT','CHZUSDT','COCOSUSDT','COSUSDT',
  37.     'CTXCUSDT','CVCUSDT','DASHUSDT','DENTUSDT',
  38.     'DOCKUSDT','DOGEUSDT','DUSKUSDT','ENJUSDT',
  39.     'EOSUSDT','ERDUSDT','ETCUSDT','ETHUSDT',
  40.     'FETUSDT','FTMUSDT','FTTUSDT','FUNUSDT',
  41.     'GTOUSDT','HBARUSDT','HCUSDT','HOTUSDT',
  42.     'ICXUSDT','IOSTUSDT','IOTAUSDT','IOTXUSDT',
  43.     'KAVAUSDT','KEYUSDT','LINKUSDT','LTCUSDT',
  44.     'MATICUSDT','MCOUSDT','MFTUSDT','MITHUSDT',
  45.     'MTLUSDT','NANOUSDT','NEOUSDT','NKNUSDT',
  46.     'NPXSUSDT','NULSUSDT','OMGUSDT','ONEUSDT',
  47.     'ONGUSDT','ONTUSDT','PERLUSDT','QTUMUSDT',
  48.     'RENUSDT','RLCUSDT','RVNUSDT','STORMUSDT',
  49.     'STXUSDT','TFUELUSDT','THETAUSDT','TOMOUSDT',
  50.     'TROYUSDT','TRXUSDT','VETUSDT','VITEUSDT',
  51.     'WANUSDT','WAVESUSDT','WINUSDT','XLMUSDT',
  52.     'XMRUSDT','XRPUSDT','XTZUSDT','ZECUSDT',
  53.     'ZILUSDT','ZRXUSDT'
  54.     ]
  55.  
  56. filtered_pairs1 = []
  57. filtered_pairs2 = []
  58. filtered_pairs3 = []
  59. selected_pair = []
  60. selected_pairCMO = []
  61.  
  62. def filter1(pair):
  63.     interval = '1h'
  64.     symbol = pair
  65.     klines = trader.client.get_klines(symbol=symbol,interval=interval)
  66.     open_time = [int(entry[0]) for entry in klines]
  67.     close = [float(entry[4]) for entry in klines]
  68.     close_array = np.asarray(close)
  69.  
  70.     print("on 1h timeframe " + symbol)
  71.  
  72.     x = close
  73.     y = range(len(x))
  74.  
  75.     best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  76.     best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  77.     best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  78.  
  79.     min = ta.MIN(close_array, timeperiod=30)
  80.     max = ta.MAX(close_array, timeperiod=30)
  81.    
  82.     wcl = ta.WCLPRICE(max, min, close_array)
  83.    
  84.     print(close[-1])
  85.     print()
  86.     print(min[-1])
  87.     print(max[-1])
  88.     print(wcl[-1])
  89.  
  90.     #plt.figure(figsize=(8,6))
  91.     #plt.grid(True)
  92.     #plt.plot(close)
  93.     #plt.plot(best_fit_line1, '--', color='r')
  94.     #plt.plot(best_fit_line2, '--', color='r')
  95.     #plt.plot(best_fit_line3, '--', color='r')
  96.     #plt.plot(close)
  97.     #plt.plot(min)
  98.     #plt.plot(max)
  99.     #plt.plot(wcl)
  100.     #plt.show(block=False)
  101.     #plt.pause(5)
  102.     #plt.close()
  103.  
  104.     if x[-1] < best_fit_line1[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
  105.         filtered_pairs1.append(symbol)
  106.         print('found')
  107.  
  108.     elif x[-1] < best_fit_line1[-1] and best_fit_line1[0] > best_fit_line1[-1]:
  109.         filtered_pairs1.append(symbol)
  110.         print('found')
  111.  
  112.     elif x[-1] == min[-1]:
  113.         filtered_pairs1.append(symbol)
  114.         print('found')
  115.  
  116.     elif x[-1] < wcl[-1]:
  117.         filtered_pairs1.append(symbol)
  118.         print('found')
  119.  
  120.     else:
  121.         print('searching')
  122.  
  123. def filter2(filtered_pairs1):
  124.     interval = '15m'
  125.     symbol = filtered_pairs1
  126.     klines = trader.client.get_klines(symbol=symbol,interval=interval)
  127.     open_time = [int(entry[0]) for entry in klines]
  128.     close = [float(entry[4]) for entry in klines]
  129.     close_array = np.asarray(close)
  130.  
  131.     print("on 15min timeframe " + symbol)
  132.  
  133.     x = close
  134.     y = range(len(x))
  135.  
  136.     best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  137.     best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  138.     best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  139.  
  140.     min = ta.MIN(close_array, timeperiod=30)
  141.     max = ta.MAX(close_array, timeperiod=30)
  142.    
  143.     wcl = ta.WCLPRICE(max, min, close_array)
  144.    
  145.     print(close[-1])
  146.     print()
  147.     print(min[-1])
  148.     print(max[-1])
  149.     print(wcl[-1])
  150.  
  151.     #plt.figure(figsize=(8,6))
  152.     #plt.grid(True)
  153.     #plt.plot(close)
  154.     #plt.plot(best_fit_line1, '--', color='r')
  155.     #plt.plot(best_fit_line2, '--', color='r')
  156.     #plt.plot(best_fit_line3, '--', color='r')
  157.     #plt.plot(close)
  158.     #plt.plot(min)
  159.     #plt.plot(max)
  160.     #plt.plot(wcl)
  161.     #plt.show(block=False)
  162.     #plt.pause(5)
  163.     #plt.close()
  164.  
  165.     if x[-1] < best_fit_line1[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
  166.         filtered_pairs2.append(symbol)
  167.         print('found')
  168.  
  169.     elif x[-1] < best_fit_line1[-1] and best_fit_line1[0] > best_fit_line1[-1]:
  170.         filtered_pairs2.append(symbol)
  171.         print('found')
  172.  
  173.     elif x[-1] == min[-1]:
  174.         filtered_pairs2.append(symbol)
  175.         print('found')
  176.  
  177.     elif x[-1] < wcl[-1]:
  178.         filtered_pairs2.append(symbol)
  179.         print('found')
  180.  
  181.     else:
  182.         print('searching')
  183.  
  184. def filter3(filtered_pairs2):
  185.     interval = '5m'
  186.     symbol = filtered_pairs2
  187.     klines = trader.client.get_klines(symbol=symbol,interval=interval)
  188.     open_time = [int(entry[0]) for entry in klines]
  189.     close = [float(entry[4]) for entry in klines]
  190.     close_array = np.asarray(close)
  191.  
  192.     print("on 5m timeframe " + symbol)
  193.  
  194.     min = ta.MIN(close_array, timeperiod=30)
  195.     max = ta.MAX(close_array, timeperiod=30)
  196.    
  197.     x = close
  198.     y = range(len(x))
  199.  
  200.     best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  201.     best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  202.     best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  203.  
  204.     min = ta.MIN(close_array, timeperiod=30)
  205.     max = ta.MAX(close_array, timeperiod=30)
  206.    
  207.     wcl = ta.WCLPRICE(max, min, close_array)
  208.    
  209.     print(close[-1])
  210.     print()
  211.     print(min[-1])
  212.     print(max[-1])
  213.     print(wcl[-1])
  214.  
  215.     #plt.figure(figsize=(8,6))
  216.     #plt.grid(True)
  217.     #plt.plot(close)
  218.     #plt.plot(best_fit_line1, '--', color='r')
  219.     #plt.plot(best_fit_line2, '--', color='r')
  220.     #plt.plot(best_fit_line3, '--', color='r')
  221.     #plt.plot(close)
  222.     #plt.plot(min)
  223.     #plt.plot(max)
  224.     #plt.plot(wcl)
  225.     #plt.show(block=False)
  226.     #plt.pause(5)
  227.     #plt.close()
  228.  
  229.     if x[-1] < best_fit_line1[-1] and best_fit_line1[0] <= best_fit_line1[-1]:
  230.         filtered_pairs3.append(symbol)
  231.         print('found')
  232.  
  233.     elif x[-1] < best_fit_line1[-1] and best_fit_line1[0] > best_fit_line1[-1]:
  234.         filtered_pairs3.append(symbol)
  235.         print('found')
  236.  
  237.     elif x[-1] == min[-1]:
  238.         filtered_pairs3.append(symbol)
  239.         print('found')
  240.  
  241.     elif x[-1] < wcl[-1]:
  242.         filtered_pairs3.append(symbol)
  243.         print('found')
  244.  
  245.     else:
  246.         print('searching')
  247.  
  248. def momentum(filtered_pairs3):
  249.     interval = '1m'
  250.     symbol = filtered_pairs3
  251.     klines = trader.client.get_klines(symbol=symbol,interval=interval)
  252.     open_time = [int(entry[0]) for entry in klines]
  253.     close = [float(entry[4]) for entry in klines]
  254.     close_array = np.asarray(close)
  255.  
  256.     print("on 1m timeframe " + symbol)
  257.  
  258.     real = ta.CMO(close_array, timeperiod=14)
  259.     print(real[-1])
  260.  
  261.     if real[-1] < -50:
  262.         print('oversold dip found')
  263.         selected_pair.append(symbol)
  264.         selected_pairCMO.append(real[-1])
  265.  
  266.     else:
  267.         print('searching')
  268.  
  269. for i in trading_pairs:
  270.     output = filter1(i)
  271.     print(filtered_pairs1)
  272.  
  273. for i in filtered_pairs1:
  274.     output = filter2(i)
  275.     print(filtered_pairs2)
  276.  
  277. for i in filtered_pairs2:
  278.     output = filter3(i)
  279.     print(filtered_pairs3)
  280.  
  281. for i in filtered_pairs3:
  282.     output = momentum(i)
  283.     print(selected_pair)
  284.  
  285. if len(selected_pair) > 1:
  286.     print('dips are more then 1 oversold')
  287.     print(selected_pair)
  288.     print(selected_pairCMO)
  289.    
  290.     if min(selected_pairCMO) in selected_pairCMO:
  291.         #print(selected_pairCMO.index(min(selected_pairCMO)))
  292.         position = selected_pairCMO.index(min(selected_pairCMO))
  293.  
  294.     for id, value in enumerate(selected_pair):
  295.         if id == position:
  296.             print(selected_pair[id])
  297.     #sys.exit()
  298.  
  299. elif len(selected_pair) == 1:
  300.     print('1 dip found')  
  301.     print(selected_pair)
  302.     print(selected_pairCMO)
  303.     #sys.exit()
  304.  
  305. else:
  306.     print('no oversold dips for the moment, restart script...')
  307.     print(selected_pair)
  308.     print(selected_pairCMO)
  309.     os.execl(sys.executable, sys.executable, *sys.argv)
  310.  
  311. sys.exit(0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top