Reorganización en carpeta Bitget
This commit is contained in:
58
Bitget/conexion.py
Normal file
58
Bitget/conexion.py
Normal file
@ -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()
|
||||
Reference in New Issue
Block a user