-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdebug_api.py
More file actions
98 lines (82 loc) · 2.33 KB
/
debug_api.py
File metadata and controls
98 lines (82 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
"""
Debug Gemini API authentication
"""
import json
import base64
import hmac
import hashlib
import time
import requests
from pathlib import Path
# Load secrets
secrets_path = Path("data/secrets.json")
with open(secrets_path) as f:
secrets = json.load(f)
api_key = secrets["api_key"]
api_secret = secrets["api_secret"]
print("=" * 60)
print("Gemini API Debug")
print("=" * 60)
print(f"\nAPI Key: {api_key}")
print(f"API Secret length: {len(api_secret)} characters")
print(f"API Secret (first 10 chars): {api_secret[:10]}...")
print()
# Test authentication
url = "https://api.gemini.com/v1/balances"
nonce = int(time.time() * 1000)
payload = {
"request": "/v1/balances",
"nonce": nonce
}
print("Payload:")
print(json.dumps(payload, indent=2))
print()
# Encode payload
payload_json = json.dumps(payload)
payload_b64 = base64.b64encode(payload_json.encode()).decode()
print(f"Base64 Payload: {payload_b64[:50]}...")
print()
# Generate signature
signature = hmac.new(
api_secret.encode(),
payload_b64.encode(),
hashlib.sha384
).hexdigest()
print(f"Signature: {signature[:50]}...")
print()
# Make request
headers = {
"Content-Type": "text/plain",
"X-GEMINI-APIKEY": api_key,
"X-GEMINI-PAYLOAD": payload_b64,
"X-GEMINI-SIGNATURE": signature,
}
print("Request Headers:")
for key, value in headers.items():
if key == "X-GEMINI-SIGNATURE":
print(f" {key}: {value[:50]}...")
else:
print(f" {key}: {value}")
print()
print("Making request...")
response = requests.post(url, headers=headers)
print(f"Response Status: {response.status_code}")
print(f"Response Headers: {dict(response.headers)}")
print(f"Response Body: {response.text}")
print()
if response.status_code == 200:
print("✅ SUCCESS!")
print("API authentication working correctly.")
else:
print("❌ FAILED")
print("\nPossible issues:")
print("1. API key not activated yet (wait 5-10 minutes)")
print("2. Wrong API environment (sandbox vs production)")
print("3. Permissions not set correctly")
print("4. API secret copied incorrectly")
print("\nPlease check:")
print("- Go to https://exchange.gemini.com/settings/api")
print("- Verify the API key is 'Active'")
print("- Verify 'Trader' or 'Trading' permission is enabled")
print("- Try regenerating the API key if problem persists")