File size: 873 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
# file: agent_system/test_auth.py
import ccxt
import os
from dotenv import load_dotenv

load_dotenv()

def test_alpaca_auth():
    api_key = os.getenv("ALPACA_API_KEY")
    secret = os.getenv("ALPACA_SECRET")
    
    print(f"Key: {api_key[:5]}...")
    
    exchange = ccxt.alpaca({
        'apiKey': api_key,
        'secret': secret,
    })
    
    # Alpaca CCXT specific: setting sandbox mode changes the base URL
    if api_key.startswith("PK"):
        exchange.set_sandbox_mode(True)
        print(">>> Sandbox Mode Active (Paper Trading)")
    
    print(f"URLs: {exchange.urls['api']}")
    
    try:
        balance = exchange.fetch_balance()
        print("✅ Auth Successful!")
        print(f"Total Cash: ${balance['total'].get('USD', 0)}")
    except Exception as e:
        print(f"❌ Auth Failed: {e}")

if __name__ == "__main__":
    test_alpaca_auth()