Overview
Generate interactive Plotly price charts with multiple time-window views. Thechart.py script creates a self-contained HTML file with 8 time ranges (1H, 6H, 1D, 1W, 1M, 3M, 6M, All) and opens it in your browser.
Prerequisites
- Python 3.9+
polymarketCLI installed and on PATH- A web browser available locally
Workflow
Get the condition ID
Start with the market’s Each market in the
condition_id from event or market data:markets array contains a conditionId field.Resolve decimal token ID
The CLOB API requires decimal token IDs (not hex). Convert the condition ID:This returns a Pick the
tokens array:token_id for the YES or NO outcome you want to chart.Generate the chart
Run the chart script with the decimal token ID:Example:The script will:
- Fetch high-resolution recent price data
- Fetch full historical data with
--fidelity 5000 - Merge the two datasets (recent high-res + historical low-res)
- Generate a dark-themed HTML file
- Open it in your default browser
Interact with the chart
The chart opens with a 1-week (1W) view by default. Click any tab to change the time window:
- 1H: Last hour
- 6H: Last 6 hours
- 1D: Last 24 hours
- 1W: Last week (default)
- 1M: Last 30 days
- 3M: Last 90 days
- 6M: Last 180 days
- All: Full history
How the Script Works
Two-Stage Fetch Strategy
The script fetches price history twice to optimize data resolution:- High-resolution recent data:
polymarket clob price-history --interval max <TOKEN_ID>(scripts/chart.py:250) - Full history with reduced fidelity: Same command with
--fidelity 5000flag (scripts/chart.py:254)
- Dense data points for recent price action
- Sparse but complete historical backdrop
Merge Logic
Themerge_histories() function (scripts/chart.py:58-95):
- Finds the earliest timestamp in the high-res dataset
- Takes all full-history points before that cutoff
- Appends all high-res points
- Sorts by timestamp
Chart Rendering
Thegenerate_html() function (scripts/chart.py:98-230) creates a self-contained HTML page using:
- Plotly.js 2.32.0 from CDN
- Dark theme: GitHub-style
#0d1117background - Area fill: Blue gradient under the price line
- Y-axis: Fixed 0-1.0 range formatted as percentages (e.g., 26.4%)
- Interactive tabs: JavaScript-driven time-window filtering
Output File
The chart is saved to a temporary file:Tips
Troubleshooting
| Issue | Solution |
|---|---|
polymarket: command not found | Install the CLI: brew install polymarket (macOS/Linux) |
Error: No price history returned | Verify the token ID is decimal and valid. Re-run clob market to confirm. |
| Browser doesn’t open | Open the printed file path manually in any browser |
| Empty chart or “No data” | The token ID may be invalid or have no trading history |
| Chart shows only a few points | The market may be newly created. Use “All” time window. |