import time
import requests
from binance.client import Client

# Binance API credentials
api_key = 'YOUR_BINANCE_API_KEY'
api_secret = 'YOUR_BINANCE_API_SECRET'

# Initialize Binance client
client = Client(api_key, api_secret)

# Define the threshold for disparity (e.g., 0.05 for 5%)
DISPARITY_THRESHOLD = 0.05

# Function to fetch current prices of BTC and ETH
def get_prices():
    btc_price = float(client.get_symbol_ticker(symbol='BTCUSDT')['price'])
    eth_price = float(client.get_symbol_ticker(symbol='ETHUSDT')['price'])
    return btc_price, eth_price

# Function to calculate disparity
def calculate_disparity(btc_price, eth_price):
    parity = eth_price / btc_price
    return parity

# Function to send alert (e.g., via webhook, email, etc.)
def send_alert(message):
    webhook_url = 'YOUR_WEBHOOK_URL'  # Replace with your webhook URL
    payload = {'text': message}
    requests.post(webhook_url, json=payload)
    print(f"Alert sent: {message}")

# Main monitoring loop
def monitor_disparity():
    while True:
        try:
            btc_price, eth_price = get_prices()
            parity = calculate_disparity(btc_price, eth_price)
            
            print(f"BTC Price: {btc_price}, ETH Price: {eth_price}, Parity: {parity}")
            
            if parity > (1 + DISPARITY_THRESHOLD):
                send_alert(f"ETH is overvalued compared to BTC! Parity: {parity}")
            elif parity < (1 - DISPARITY_THRESHOLD):
                send_alert(f"ETH is undervalued compared to BTC! Parity: {parity}")
            
            time.sleep(60)  # Check every 60 seconds
        
        except Exception as e:
            print(f"Error: {e}")
            time.sleep(60)

if __name__ == "__main__":
    monitor_disparity()
