-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_monitor.py
More file actions
95 lines (77 loc) · 2.72 KB
/
test_monitor.py
File metadata and controls
95 lines (77 loc) · 2.72 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
"""
Test script for market monitoring system.
Monitors a few markets and logs price updates.
"""
import asyncio
import structlog
from config.settings import get_settings
from src.core.client import PolymarketClient
from src.core.market_selector import MarketSelector, SelectionStrategy
from src.core.market_monitor import MarketMonitor, PriceUpdate
# Configure logging
structlog.configure(
processors=[
structlog.processors.add_log_level,
structlog.processors.TimeStamper(fmt="iso"),
structlog.dev.ConsoleRenderer()
]
)
logger = structlog.get_logger(__name__)
def on_price_update(update: PriceUpdate) -> None:
"""Handle price update events."""
if update.price_change_pct is not None:
change_pct = update.price_change_pct * 100
logger.info(
"price_update",
token_id=update.token_id[:16] + "...",
price=f"{update.price:.4f}",
change_pct=f"{change_pct:+.2f}%"
)
async def main():
"""Run market monitoring test."""
try:
# Load settings
logger.info("loading_configuration")
settings = get_settings()
# Initialize client
logger.info("initializing_client")
client = PolymarketClient(settings.polymarket)
await client.connect()
# Create market selector (start with random for testing)
logger.info("creating_market_selector", strategy="random", max_markets=5)
selector = MarketSelector(
strategy=SelectionStrategy.RANDOM,
max_markets=5 # Start with just 5 for testing
)
# Create monitor
logger.info("creating_market_monitor")
monitor = MarketMonitor(
client=client,
selector=selector,
poll_interval=settings.trading.poll_interval,
price_history_window=60
)
# Register price update callback
monitor.on_price_update(on_price_update)
# Start monitoring
logger.info("starting_monitor", duration_seconds=30)
logger.info("press_ctrl_c_to_stop")
# Run for 30 seconds
monitor_task = asyncio.create_task(monitor.start())
try:
await asyncio.wait_for(monitor_task, timeout=30.0)
except asyncio.TimeoutError:
logger.info("test_duration_complete")
await monitor.stop()
logger.info("test_completed")
except KeyboardInterrupt:
logger.info("interrupted_by_user")
except Exception as e:
logger.error(
"test_failed",
error=str(e),
error_type=type(e).__name__
)
raise
if __name__ == "__main__":
asyncio.run(main())