SHARE
TWEET

market dip finder

cyberghostTM Jan 20th, 2020 (edited) 110 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(wcl[-1])
  87.  
  88.     #plt.figure(figsize=(8,6))
  89.     #plt.grid(True)
  90.     #plt.plot(close)
  91.     #plt.plot(best_fit_line1, '--', color='r')
  92.     #plt.plot(best_fit_line2, '--', color='r')
  93.     #plt.plot(best_fit_line3, '--', color='r')
  94.     #plt.plot(close)
  95.     #plt.plot(min)
  96.     #plt.plot(max)
  97.     #plt.plot(wcl)
  98.     #plt.show(block=False)
  99.     #plt.pause(5)
  100.     #plt.close()
  101.  
  102.     if x[-1] < best_fit_line3[-1] and best_fit_line1[0] <= best_fit_line1[-1] and x[-1] < wcl[-1]:
  103.         filtered_pairs1.append(symbol)
  104.         print('found')
  105.  
  106.     elif x[-1] < best_fit_line3[-1] and best_fit_line1[0] > best_fit_line1[-1] and x[-1] < wcl[-1]:
  107.         filtered_pairs1.append(symbol)
  108.         print('found')
  109.  
  110.     else:
  111.         print('searching')
  112.  
  113. def filter2(filtered_pairs1):
  114.     interval = '15m'
  115.     symbol = filtered_pairs1
  116.     klines = trader.client.get_klines(symbol=symbol,interval=interval)
  117.     open_time = [int(entry[0]) for entry in klines]
  118.     close = [float(entry[4]) for entry in klines]
  119.     close_array = np.asarray(close)
  120.  
  121.     print("on 15min timeframe " + symbol)
  122.  
  123.     x = close
  124.     y = range(len(x))
  125.  
  126.     best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  127.     best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  128.     best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  129.  
  130.     min = ta.MIN(close_array, timeperiod=30)
  131.     max = ta.MAX(close_array, timeperiod=30)
  132.    
  133.     wcl = ta.WCLPRICE(max, min, close_array)
  134.    
  135.     print(close[-1])
  136.     print()
  137.     print(wcl[-1])
  138.  
  139.     #plt.figure(figsize=(8,6))
  140.     #plt.grid(True)
  141.     #plt.plot(close)
  142.     #plt.plot(best_fit_line1, '--', color='r')
  143.     #plt.plot(best_fit_line2, '--', color='r')
  144.     #plt.plot(best_fit_line3, '--', color='r')
  145.     #plt.plot(close)
  146.     #plt.plot(min)
  147.     #plt.plot(max)
  148.     #plt.plot(wcl)
  149.     #plt.show(block=False)
  150.     #plt.pause(5)
  151.     #plt.close()
  152.  
  153.     if x[-1] < best_fit_line3[-1] and best_fit_line1[0] <= best_fit_line1[-1] and x[-1] < wcl[-1]:
  154.         filtered_pairs2.append(symbol)
  155.         print('found')
  156.  
  157.     elif x[-1] < best_fit_line3[-1] and best_fit_line1[0] > best_fit_line1[-1] and x[-1] < wcl[-1]:
  158.         filtered_pairs2.append(symbol)
  159.         print('found')
  160.  
  161.     else:
  162.         print('searching')
  163.  
  164. def filter3(filtered_pairs2):
  165.     interval = '5m'
  166.     symbol = filtered_pairs2
  167.     klines = trader.client.get_klines(symbol=symbol,interval=interval)
  168.     open_time = [int(entry[0]) for entry in klines]
  169.     close = [float(entry[4]) for entry in klines]
  170.     close_array = np.asarray(close)
  171.  
  172.     print("on 5m timeframe " + symbol)
  173.  
  174.     min = ta.MIN(close_array, timeperiod=30)
  175.     max = ta.MAX(close_array, timeperiod=30)
  176.    
  177.     x = close
  178.     y = range(len(x))
  179.  
  180.     best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  181.     best_fit_line2 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 1.01
  182.     best_fit_line3 = (np.poly1d(np.polyfit(y, x, 1))(y)) * 0.99
  183.  
  184.     min = ta.MIN(close_array, timeperiod=30)
  185.     max = ta.MAX(close_array, timeperiod=30)
  186.    
  187.     wcl = ta.WCLPRICE(max, min, close_array)
  188.    
  189.     print(close[-1])
  190.     print()
  191.     print(min[-1])
  192.     print(max[-1])
  193.     print(wcl[-1])
  194.  
  195.     #plt.figure(figsize=(8,6))
  196.     #plt.grid(True)
  197.     #plt.plot(close)
  198.     #plt.plot(best_fit_line1, '--', color='r')
  199.     #plt.plot(best_fit_line2, '--', color='r')
  200.     #plt.plot(best_fit_line3, '--', color='r')
  201.     #plt.plot(close)
  202.     #plt.plot(min)
  203.     #plt.plot(max)
  204.     #plt.plot(wcl)
  205.     #plt.show(block=False)
  206.     #plt.pause(5)
  207.     #plt.close()
  208.  
  209.     if x[-1] < best_fit_line1[-1] and best_fit_line1[0] <= best_fit_line1[-1] and x[-1] < wcl[-1]:
  210.         filtered_pairs3.append(symbol)
  211.         print('found')
  212.  
  213.     elif x[-1] < best_fit_line1[-1] and best_fit_line1[0] > best_fit_line1[-1] and x[-1] < wcl[-1]:
  214.         filtered_pairs3.append(symbol)
  215.         print('found')
  216.  
  217.     else:
  218.         print('searching')
  219.  
  220. def momentum(filtered_pairs3):
  221.     interval = '1m'
  222.     symbol = filtered_pairs3
  223.     klines = trader.client.get_klines(symbol=symbol,interval=interval)
  224.     open_time = [int(entry[0]) for entry in klines]
  225.     close = [float(entry[4]) for entry in klines]
  226.     close_array = np.asarray(close)
  227.  
  228.     print("on 1m timeframe " + symbol)
  229.  
  230.     real = ta.CMO(close_array, timeperiod=14)
  231.     print(real[-1])
  232.  
  233.     if real[-1] < -50:
  234.         print('oversold dip found')
  235.         selected_pair.append(symbol)
  236.         selected_pairCMO.append(real[-1])
  237.  
  238.     else:
  239.         print('searching')
  240.  
  241. for i in trading_pairs:
  242.     output = filter1(i)
  243.     print(filtered_pairs1)
  244.  
  245. for i in filtered_pairs1:
  246.     output = filter2(i)
  247.     print(filtered_pairs2)
  248.  
  249. for i in filtered_pairs2:
  250.     output = filter3(i)
  251.     print(filtered_pairs3)
  252.  
  253. for i in filtered_pairs3:
  254.     output = momentum(i)
  255.     print(selected_pair)
  256.  
  257. if len(selected_pair) > 1:
  258.     print('dips are more then 1 oversold')
  259.     print(selected_pair)
  260.     print(selected_pairCMO)
  261.    
  262.     if min(selected_pairCMO) in selected_pairCMO:
  263.         #print(selected_pairCMO.index(min(selected_pairCMO)))
  264.         position = selected_pairCMO.index(min(selected_pairCMO))
  265.  
  266.     for id, value in enumerate(selected_pair):
  267.         if id == position:
  268.             print(selected_pair[id])
  269.     #sys.exit()
  270.  
  271. elif len(selected_pair) == 1:
  272.     print('1 dip found')  
  273.     print(selected_pair)
  274.     print(selected_pairCMO)
  275.     #sys.exit()
  276.  
  277. else:
  278.     print('no oversold dips for the moment, restart script...')
  279.     print(selected_pair)
  280.     print(selected_pairCMO)
  281.     os.execl(sys.executable, sys.executable, *sys.argv)
  282.  
  283. 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