Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from binance.client import Client
- import numpy as np
- import matplotlib.pyplot as plt
- class Trader:
- def __init__(self, file):
- self.connect(file)
- def connect(self, file):
- lines = [line.rstrip('\n') for line in open(file)]
- self.key = lines[0]
- self.secret = lines[1]
- self.client = Client(self.key, self.secret)
- class TechnicalAnalyzer:
- def __init__(self, client):
- self.client = client
- def get_historical_data(self, symbol, interval):
- klines = self.client.get_historical_klines(symbol, interval, '1 year ago')
- close_prices = [float(entry[4]) for entry in klines]
- return close_prices
- def fit_line(self, data):
- y = np.array(data)
- x = np.arange(len(y))
- z = np.polyfit(x, y, 1)
- p = np.poly1d(z)
- return p(x)
- def identify_dip(self, symbol):
- close_prices = self.get_historical_data(symbol, '1d')
- fit_line = self.fit_line(close_prices)
- if close_prices[-1] < fit_line[-1] and fit_line[0] <= fit_line[-1]:
- print(f'{symbol}: Dip found on daily timeframe')
- return True
- return False
- def identify_top(self, symbol):
- close_prices = self.get_historical_data(symbol, '1d')
- fit_line = self.fit_line(close_prices)
- if close_prices[-1] > fit_line[-1] and fit_line[0] >= fit_line[-1]:
- print(f'{symbol}: Top found on daily timeframe')
- return True
- return False
- filename = 'credentials.txt'
- trader = Trader(filename)
- analyzer = TechnicalAnalyzer(trader.client)
- trading_pairs = ['BTCBUSD', 'BNBBUSD', 'DOGEBUSD', 'AVAXBUSD', 'ADABUSD', 'SOLBUSD']
- for pair in trading_pairs:
- if analyzer.identify_dip(pair):
- if analyzer.identify_dip(pair):
- print(f'{pair}: Dip confirmed on 4h timeframe')
- elif analyzer.identify_top(pair):
- if analyzer.identify_top(pair):
- print(f'{pair}: Top confirmed on 4h timeframe')
Advertisement
Add Comment
Please, Sign In to add comment