feat(polymarket): prediction-market section — venue, AI analysis, suggestions & trading#161
Merged
Merged
Conversation
Re-adds Polymarket as a venue (prediction markets, CLOB API) following the re-adding checklist in docs/venues/abstraction.md, and makes venue routing per-strategy so Binance and Polymarket strategies run side by side: - Restore engine/venues/polymarket.py + tests from the pre-reduction tree, and add PolymarketOrderClient — a py-clob-client wrapper that signs and submits live CLOB market orders (shares are converted to a USDC amount for market BUYs; responses normalised for the venue). - Register the venue (no sandbox; credential fields private_key, api_key, api_secret, passphrase, wallet_address) and wire build_venue: public market data with no creds, signing client with the full set. - BaseStrategy/StrategyInstance/AISignal gain a `venue`; VenueRouter and ExecutorRouter accept an explicit venue override; the engine resolves market data and executors per strategy venue. Testnet mode falls back to Sim for venues without a sandbox. - Widen symbol columns to 80 chars (Polymarket token ids are ~77 digits) — migration 0022. - tests/__init__.py: py-clob-client deps ship a stray top-level `tests` package; mark our tests directory a regular package so imports resolve. https://claude.ai/code/session_01RGKRo1Xjvhv9UMsQMpNvNj
Adds the engine/polymarket module — the prediction-market side of the
platform, deliberately slow-cadence (markets move on events and news, not
ticks):
- Discovery: refresh_markets pulls the top-volume active markets from the
public Gamma API into a local prediction_market catalogue (upsert by
condition id); list/search/watch APIs under /api/polymarket power the
market browser. Migration 0023.
- AI bet analysis: analyze_market packs a market's question, prices, time
to resolution and news headlines matched to the question's keywords
(new news.service.search), asks the configured writer LLM for a strict
-JSON probability estimate, and stores the edge (estimate minus market
price) as a market_analysis row. Usage recorded as purpose=polymarket
under the daily AI spend cap.
- Screening: run_screening_cycle analyses the watchlist plus the top-N
markets every N hours; an analysis clearing the operator's edge and
confidence bars becomes a pending AISignal (Telegram + dashboard) that
executes through the existing risk-gated confirmation path.
- Resolution sync: watched/held markets are re-checked hourly; on
resolution the position settles at 1/0 USDC directly into the
sub-ledger (redemption, not an order) and the operator is alerted.
- Settings: polymarket_{refresh,research}_hours, edge threshold, min
confidence, screen top-N and stake — readable/updatable via
/api/settings (PUT /api/settings/polymarket).
https://claude.ai/code/session_01RGKRo1Xjvhv9UMsQMpNvNj
Adds PredictionAIStrategy — automated trading on AI-found edge. It subclasses AIStrategy so the engine's existing AI machinery (per-strategy provider/model resolution, daily spend cap, usage recording and the notify/auto action mode) applies unchanged: - Each tick it reads the latest stored bet analysis for its token's market, re-running the AI at a configurable cadence when stale; enters when the token's edge clears edge_threshold with min_confidence, exits when the edge is gone. NO tokens mirror the stored YES edge. - Closed/resolved markets are never traded — the resolution sync settles held tokens at 1/0. - Registered as a pickable type; StrategyType gains a `venue` pin (prediction_ai → polymarket) enforced by build_strategy and surfaced via /api/strategies/types, and kind=="AI" checks become isinstance(AIStrategy) so the subclass inherits model config, seeding and the read model. https://claude.ai/code/session_01RGKRo1Xjvhv9UMsQMpNvNj
…yses - New Polymarket page (route + sidebar entry): browse the discovered markets most-traded first with search and an All/Watchlist scope, pin markets to the AI's watchlist, and open a detail panel showing the latest AI bet analysis — estimated probability vs market price, edge, confidence and reasoning, with the recent-analysis trail. Admins can refresh the catalogue and run a one-off "Analyze now". - Strategies page: venue selector on the create form (locked when a type is pinned, e.g. Prediction AI → Polymarket); Polymarket token-id symbols stay case-sensitive and render truncated with a venue badge. - Settings page: Polymarket card for the discovery/screening cadence, edge threshold, min confidence, screen top-N and suggested stake. The Polymarket credential form comes from the generic per-venue renderer. - lib/api/polymarket.ts client; OpenAPI schema + generated types regenerated. https://claude.ai/code/session_01RGKRo1Xjvhv9UMsQMpNvNj
- polymarket-setup.md: drop the "not yet selectable" warning; document the section's features (discovery, AI bet analysis, suggestions, Prediction AI, resolution settlement), the five stored credential fields and the Sim-fallback behaviour in Testnet mode. - abstraction.md: document per-strategy venue routing. - README / docs index / api-features / research status: Binance-only framing becomes Binance + Polymarket; roadmap Phase 8 marked in progress. - CHANGELOG: Unreleased "Added" entry for the whole section. https://claude.ai/code/session_01RGKRo1Xjvhv9UMsQMpNvNj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Polymarket prediction-market section to the platform, mirroring the Binance side with venue access, automated trading, trade suggestions and alerts — but tuned for prediction markets (AI bet/news analysis instead of high-frequency trading).
PolymarketVenuewith per-strategy venue routing60 files changed, +4965 / −75.
🤖 Generated with Claude Code