Spaces:
Sleeping
Sleeping
File size: 967 Bytes
d96a847 | 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 | # file: agent_system/test_auth_v2.py
import ccxt
import os
from dotenv import load_dotenv
load_dotenv()
def test():
api_key = os.getenv("ALPACA_API_KEY", "").strip()
secret = os.getenv("ALPACA_SECRET", "").strip()
print(f"Key: {api_key}")
print(f"Secret: {secret[:5]}...")
exchange = ccxt.alpaca({
'apiKey': api_key,
'secret': secret,
'options': {'defaultType': 'spot'}
})
if api_key.startswith("PK"):
exchange.set_sandbox_mode(True)
# Force paper URL
exchange.urls['api']['rest'] = 'https://paper-api.alpaca.markets/v2'
print(f">>> Testing Paper Endpoint @ {exchange.urls['api']['rest']}")
try:
print("Fetching balance...")
bal = exchange.fetch_balance()
print(f"✅ Success! USD balance: {bal.get('USD', {}).get('total', 'N/A')}")
except Exception as e:
print(f"❌ Failed: {e}")
if __name__ == "__main__":
test()
|