disparity.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import time
  2. import requests
  3. from binance.client import Client
  4. # Binance API credentials
  5. api_key = 'YOUR_BINANCE_API_KEY'
  6. api_secret = 'YOUR_BINANCE_API_SECRET'
  7. # Initialize Binance client
  8. client = Client(api_key, api_secret)
  9. # Define the threshold for disparity (e.g., 0.05 for 5%)
  10. DISPARITY_THRESHOLD = 0.05
  11. # Function to fetch current prices of BTC and ETH
  12. def get_prices():
  13. btc_price = float(client.get_symbol_ticker(symbol='BTCUSDT')['price'])
  14. eth_price = float(client.get_symbol_ticker(symbol='ETHUSDT')['price'])
  15. return btc_price, eth_price
  16. # Function to calculate disparity
  17. def calculate_disparity(btc_price, eth_price):
  18. parity = eth_price / btc_price
  19. return parity
  20. # Function to send alert (e.g., via webhook, email, etc.)
  21. def send_alert(message):
  22. webhook_url = 'YOUR_WEBHOOK_URL' # Replace with your webhook URL
  23. payload = {'text': message}
  24. requests.post(webhook_url, json=payload)
  25. print(f"Alert sent: {message}")
  26. # Main monitoring loop
  27. def monitor_disparity():
  28. while True:
  29. try:
  30. btc_price, eth_price = get_prices()
  31. parity = calculate_disparity(btc_price, eth_price)
  32. print(f"BTC Price: {btc_price}, ETH Price: {eth_price}, Parity: {parity}")
  33. if parity > (1 + DISPARITY_THRESHOLD):
  34. send_alert(f"ETH is overvalued compared to BTC! Parity: {parity}")
  35. elif parity < (1 - DISPARITY_THRESHOLD):
  36. send_alert(f"ETH is undervalued compared to BTC! Parity: {parity}")
  37. time.sleep(60) # Check every 60 seconds
  38. except Exception as e:
  39. print(f"Error: {e}")
  40. time.sleep(60)
  41. if __name__ == "__main__":
  42. monitor_disparity()