import requests import time import ccxt # Biblioteca para conectar com exchanges
def get_bitcoin_price(): url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd" response = requests.get(url) if response.status_code == 200: data = response.json() return data["bitcoin"]["usd"] else: print("Erro ao obter o preço do Bitcoin") return None
def sell_bitcoin(exchange, symbol, amount): try: order = exchange.create_market_sell_order(symbol, amount) print(f"Venda realizada: {order}") except Exception as e: print(f"Erro ao vender Bitcoin: {e}")
def monitor_price(threshold, exchange, symbol, amount): while True: price = get_bitcoin_price() if price: print(f"Preço atual do Bitcoin: ${price}") if price >= threshold: print(f"\nALERTA! O preço do Bitcoin atingiu ${price}, ultrapassando o limite de ${threshold}! Realizando venda...\n") sell_bitcoin(exchange, symbol, amount) time.sleep(30) # Aguarda 30 segundos antes de verificar novamente
if name == "main": exchange = ccxt.binance({ 'apiKey': 'SUA_API_KEY', 'secret': 'SUA_SECRET_KEY' }) symbol = 'BTC/USDT' amount = 0.001 # Quantidade de BTC para vender threshold_price = float(input("Defina um preço limite para a venda automática: ")) monitor_price(threshold_price, exchange, symbol, amount)