Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from binance.client import Client
- from binance.enums import *
- import pandas as pd
- # Load API key and secret from credentials.txt
- with open('credentials.txt', 'r') as f:
- lines = f.readlines()
- api_key = lines[0].strip()
- api_secret = lines[1].strip()
- # Connect to Binance Futures API
- client = Client(api_key, api_secret, testnet=False)
- # Retrieve price data for USDTM on all timeframes
- symbols = ['BTCUSDT']
- timeframes = ['1d', '4h', '1h', '15m', '5m']
- prices = {}
- for symbol in symbols:
- for timeframe in timeframes:
- klines = client.futures_klines(symbol=symbol, interval=timeframe, limit=1000)
- df = pd.DataFrame(klines, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume', 'close_time', 'quote_asset_volume', 'trades', 'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume', 'ignore'])
- df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
- df.set_index('timestamp', inplace=True)
- prices[(symbol, timeframe)] = df
- # Perform polynomial fit analysis for all timeframes
- for symbol in symbols:
- for timeframe in timeframes:
- df = prices[(symbol, timeframe)]
- x = df['close'].astype(float).values
- y = np.arange(len(x)).astype(float)
- best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
- best_fit_line2 = np.poly1d(np.polyfit(y, x, 1))(y) * 1.01
- best_fit_line3 = np.poly1d(np.polyfit(y, x, 1))(y) * 0.99
- # Determine if the close price is below the lowest line
- if df['close'].astype(float)[-1] < min(best_fit_line1[-1], best_fit_line2[-1], best_fit_line3[-1]):
- print(f"{symbol} {timeframe}: DIP")
- else:
- print(f"{symbol} {timeframe}: TOP")
Advertisement