-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_connection.py
More file actions
61 lines (53 loc) · 1.79 KB
/
Copy pathtest_connection.py
File metadata and controls
61 lines (53 loc) · 1.79 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
from connection import AlpacaConnection
import logging
from config import LOG_LEVEL, LOG_FILE
# Configure logging
logging.basicConfig(
level=getattr(logging, LOG_LEVEL),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(LOG_FILE),
logging.StreamHandler()
]
)
logger = logging.getLogger(__name__)
def test_alpaca_connection():
"""Test Alpaca connection and basic API functionality"""
alpaca = AlpacaConnection()
# Test connection
logger.info("Testing Alpaca connection...")
if not alpaca.connect():
logger.error("Failed to connect to Alpaca")
return False
# Test account info
logger.info("Testing account information retrieval...")
account_info = alpaca.get_account_info()
if account_info:
logger.info("Account Information:")
for key, value in account_info.items():
logger.info(f"{key}: {value}")
else:
logger.error("Failed to get account information")
return False
# Test market status
logger.info("Testing market status retrieval...")
market_status = alpaca.get_market_status()
if market_status:
logger.info("Market Status:")
for key, value in market_status.items():
logger.info(f"{key}: {value}")
else:
logger.error("Failed to get market status")
return False
# Test positions
logger.info("Testing positions retrieval...")
positions = alpaca.get_positions()
if positions is not None:
logger.info(f"Current positions: {positions}")
else:
logger.error("Failed to get positions")
return False
logger.info("All tests completed successfully!")
return True
if __name__ == "__main__":
test_alpaca_connection()