From d93e7ddda576bc069916819327c9c1d57a0e8285 Mon Sep 17 00:00:00 2001 From: juanlf Date: Mon, 16 Jun 2025 20:35:35 +0000 Subject: [PATCH] =?UTF-8?q?Prueba=20de=20conexi=C3=B3n=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conexion.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 conexion.py diff --git a/conexion.py b/conexion.py new file mode 100644 index 0000000..5c41f30 --- /dev/null +++ b/conexion.py @@ -0,0 +1,58 @@ +import time +import hmac +import hashlib +import base64 +import requests +import json + +# === TUS CREDENCIALES === +API_KEY = "bg_28730a088b4b71c307ed5773b84d8267" +API_SECRET = "f7e4872f828c99612df009c3641421fc41d9dfb9cfc56dce3311fdaae70f5b29" +PASSPHRASE = "cQTVzepB6KuFWgWLgCpB6kW84iiqJr3u" +BASE_URL = "https://api.bitget.com" + +# === ENDPOINT DE PRUEBA (consulta de balances spot) === +ENDPOINT = "/api/spot/v1/account/assets" + +def get_timestamp(): + return str(int(time.time() * 1000)) + +def sign_request(timestamp, method, endpoint, body=""): + message = f"{timestamp}{method}{endpoint}{body}" + signature = hmac.new( + API_SECRET.encode(), message.encode(), hashlib.sha256 + ).digest() + return base64.b64encode(signature).decode() + +def get_auth_headers(method, endpoint, body=""): + timestamp = get_timestamp() + signature = sign_request(timestamp, method, endpoint, body) + return { + "ACCESS-KEY": API_KEY, + "ACCESS-SIGN": signature, + "ACCESS-TIMESTAMP": timestamp, + "ACCESS-PASSPHRASE": PASSPHRASE, + "Content-Type": "application/json", + "locale": "en-US" + } + +def probar_conexion_api(): + url = f"{BASE_URL}{ENDPOINT}" + headers = get_auth_headers("GET", ENDPOINT) + + print("🔐 Probando conexión con el endpoint de balances spot...") + try: + response = requests.get(url, headers=headers, timeout=10) + print(f"🧾 Status code: {response.status_code}") + if response.status_code == 200: + data = response.json() + print("✅ Conexión exitosa. Respuesta:") + print(json.dumps(data, indent=2)) + else: + print("⚠️ Algo salió mal. Respuesta:") + print(response.text) + except Exception as e: + print(f"❌ Error al conectar: {e}") + +if __name__ == "__main__": + probar_conexion_api()