-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_connection.py
More file actions
81 lines (67 loc) · 2.27 KB
/
test_connection.py
File metadata and controls
81 lines (67 loc) · 2.27 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
"""
Test script to verify Polymarket client connection and authentication.
Run this to ensure API keys are configured correctly.
"""
import asyncio
import structlog
from config.settings import get_settings
from src.core.client import PolymarketClient
# Configure structured logging
structlog.configure(
processors=[
structlog.processors.add_log_level,
structlog.processors.TimeStamper(fmt="iso"),
structlog.dev.ConsoleRenderer()
]
)
logger = structlog.get_logger(__name__)
async def test_connection():
"""Test Polymarket client connection and basic operations."""
try:
# Load settings from .env
logger.info("loading_configuration")
settings = get_settings()
# Initialize client
logger.info("initializing_polymarket_client")
client = PolymarketClient(settings.polymarket)
# Connect to API
logger.info("connecting_to_polymarket_api")
await client.connect()
# Test: Fetch markets
logger.info("testing_market_fetch")
markets = await client.get_markets()
logger.info(
"markets_fetched_successfully",
market_count=len(markets.get("data", []))
)
# Display first 3 markets as example
if markets.get("data"):
logger.info("sample_markets")
for market in markets["data"][:3]:
logger.info(
"market",
question=market.get("question"),
condition_id=market.get("condition_id")
)
# Disconnect
client.disconnect()
logger.info("test_completed_successfully")
except ValueError:
logger.exception(
"configuration_error",
hint="Make sure POLYMARKET_PRIVATE_KEY is set in .env file"
)
return False
except Exception:
logger.exception(
"test_failed",
)
return False
return True
if __name__ == "__main__":
logger.info("starting_connection_test")
success = asyncio.run(test_connection())
if success:
logger.info("All tests passed! Configuration is correct.")
else:
logger.error("Tests failed. Check configuration and API keys.")