-
Notifications
You must be signed in to change notification settings - Fork 15
feat(examples): add slug-to-chart for Polymarket price visualization #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add a script that fetches historical prices from the Polymarket API for a given event slug and generates a professional chart as an image. Features: - Fetches price history for all outcomes in an event - Supports configurable intervals (1m, 1h, 6h, 1d, 1w, max) - --top option to show only top N outcomes by current price - Clean Bloomberg-style chart output with source attribution Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
- Move slug_to_chart.py from scripts/ to examples/ - Add token ID fetching when not present in market metadata - Add example output chart (fed_jan_chart.png) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
- Redesign chart layout to match Bloomberg financial charts - Add diagonal line markers in legend (Bloomberg style) - Add "dr-manhattan" watermark in bottom right - Improve label extraction from market questions - Better font styling and spacing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
Split into focused modules: - labels.py: Label extraction from market questions - fetcher.py: Polymarket API data fetching - chart.py: Bloomberg-style chart generation - __main__.py: CLI entry point Fixes: - Only show "Yes" outcomes for binary markets (correct data) - Default interval changed to 1d with 90 points (~3 months) - Better label extraction for Fed rate decisions Usage: uv run python -m examples.slug_to_chart <slug> [options] Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace Dem 2028 chart with Fed Chair nomination chart showing Kevin Warsh vs Kevin Hassett price movements. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
- Change default interval to 'max' and fidelity to 300 for better historical data - Add smart x-axis date formatting based on data range: - >365 days: "Jan '24" with 2-month intervals - >90 days: "Jan" with monthly ticks - >30 days: "Jan 01" with weekly ticks - <=30 days: "Jan 01" with daily ticks Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
- Add --min-price/-m option (default: 0.001 = 0.1%) - Shows all outcomes above the price threshold instead of arbitrary top N - Fed Chair chart now shows 9 candidates instead of 3 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
- Add --exchange/-e option to select exchange - Support Polymarket (default), Limitless, and Opinion - Auto-normalize intervals for exchange compatibility - Handle exchange-specific API differences - Update README with exchange comparison Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
PR Review: Slug to Chart FeatureSummaryThis PR adds a well-structured module for generating Bloomberg-style price charts from prediction market data. The code is clean and supports multiple exchanges (Polymarket, Limitless, Opinion). Code Quality & Best PracticesStrengths
Issues & Suggestions1. Hardcoded "Polymarket" in chart footer (chart.py:123)The footer always says "Source: Polymarket" even when using Limitless or Opinion exchanges. Fix: Pass exchange name to 2. Bare exception catches (fetcher.py:53, 121, 159)Using bare Recommendation: Catch specific exceptions or at least log the error 3. Magic numbers in chart.py (lines 50, 60-71, 104)Hard-coded values like Recommendation: Extract as named constants 4. Missing validation in main.pyNo validation for negative or zero Potential Bugs1. Duplicate label collision (fetcher.py:156-157)The duplicate handling appends outcome name, but this could still collide if multiple markets have the same question and outcome. 2. Empty price_data edge case (chart.py:57)If 3. Binary market assumption (fetcher.py:128)Assumes binary markets are always Performance Considerations1. Sequential API calls (fetcher.py:149-160)Price history is fetched sequentially for each outcome. For events with many outcomes, this could be slow. Optimization: Use 2. Memory usage with large fidelitySetting fidelity to very high values could consume significant memory. Add max limit validation. Security Concerns1. Path traversal risk (main.py:78) - CRITICALUser-controlled slug is used in filename without proper sanitization. An attacker could potentially use special characters to write to unexpected locations. Fix: Sanitize more thoroughly with regex to allow only safe characters 2. No authentication handlingREADME mentions "Opinion requires authentication" but code doesn't show how to configure credentials. Recommendation: Document how to set up authentication per CLAUDE.md guideline #4. Test Coverage - CRITICALNo tests found for this feature. Per CLAUDE.md guideline #5 ("Run and Debug yourself PROACTIVELY"), this module should include:
Recommendation: Add Adherence to CLAUDE.md
Additional Recommendations
ConclusionThis is a solid feature implementation with clean architecture and good multi-exchange support. The main concerns are:
Recommendation: Request changes to add tests and fix security issue before merging. |
Summary
examples/slug_to_chart/module that generates Bloomberg-style price charts from prediction market dataSupported Exchanges
Usage
Example Output
Test plan
--topparameter for filtering outcomes🤖 Generated with Claude Code