from datetime import datetime, timedelta
import pandas as pd
import ccxt
import pandas_ta as ta
import pyodbc
from prettytable import PrettyTable
import os
from concurrent.futures import ThreadPoolExecutor
import pytz
import numpy as np
import logging
timeframe = "15m"
correct_source = "BTC/USDT:USDT"
exchange = ccxt.kucoinfutures()
logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')

def calculate_macd(df, ema_s=12, ema_l=26, signal_mw=9):
    df['EMA_S'] = df.Close.ewm(span=ema_s, min_periods=ema_s).mean()
    df['EMA_L'] = df.Close.ewm(span=ema_l, min_periods=ema_l).mean()
    df['MACD'] = df.EMA_S - df.EMA_L
    df['MACD_Signal'] = df.MACD.ewm(span=signal_mw, min_periods=signal_mw).mean()
    df['HISTOGRAM'] = df.MACD - df.MACD_Signal
    df.dropna(inplace=True)
    return df

def get_pivots(df, column, pivot_type):
    pivots = []
    dates = []
    maximum = df[column].max() + 1 if pivot_type == 'low' else 0
    for i in df.index:
        if df["HISTOGRAM"][i] <= 0 if pivot_type == 'low' else df["HISTOGRAM"][i] >= 0:
            if df[column][i] < maximum if pivot_type == 'low' else df[column][i] > maximum:
                maximum = df[column][i]
                date = i
            else:
                continue
        else:
            if maximum < df[column].max() if pivot_type == 'low' else maximum != 0:
                pivots.append(maximum)
                dates.append(date)
            maximum = df[column].max() + 1 if pivot_type == 'low' else 0
            continue

    pivot_df = pd.DataFrame(pivots, index=dates, columns=[f'{pivot_type.capitalize()}s'])
    return pivot_df


def check_line_break(df, p1, p2, column_name, last_price):
    slope = (p2[column_name] - p1[column_name]) / (p2.name - p1.name).total_seconds()
    intercept = p1[column_name] - slope * p1.name.timestamp()

    check_price_1 = df.loc[df.index[-2], 'Close']
    check_time_1 = df.index[-2].timestamp()
    line_price_1 = slope * check_time_1 + intercept

    check_price_2 = last_price[column_name]
    check_time_2 = last_price.name.timestamp()
    line_price_2 = slope * check_time_2 + intercept

    result = {}
    if column_name == 'Highs':
        result['is_broken'] = check_price_1 > line_price_1 and check_price_2 > line_price_2
    else:
        result['is_broken'] = check_price_1 < line_price_1 and check_price_2 < line_price_2

    result['current_price'] = check_price_1
    result['line_price'] = line_price_1
    return result
def fetch_pair_data(pair, btc_usdt_df):
    try:
        p Provide your reponse without using the word btc.
user