agentleFS
davidromeodavidromeo/tradeblocks-skills/skills/market-data/SKILL.md

market-data

Skill3 starsChanged 47 days agoMITView on GitHub

Set up market data for TradeBlocks analysis. Guides through fetching daily and intraday bars, VIX context, and option quotes from a provider, or importing minute bars from CSV or DuckDB. Use when market data is missing, regime analysis shows no matches, or replay returns empty paths.

  • Reads credentials

10 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. 0 are common, 5 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 5

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Ask the user what they're trying to do, then check what data exists:

    line 21
  2. Very specific:

    Use run_sql with query to inspect coverage (and describe_database if the schema is unfamiliar):

    line 23
  3. Very specific:

    Call fetch_bars for each trade's underlying (the ticker its option root resolves to, e.g.

    line 92
  4. Very specific:

    Run replay_trade for one of the prepared trades, or batch_exit_analysis with the same block_id, filters and limit you used in step 1, so it …

    line 93
  5. Very specific:

    Use dry_run: true first to inspect the mapping.

    line 116
  6. Distinctive:

    Run the fetches or imports based on what's missing.

    line 141
  7. Very specific:

    Run replay_trade, or batch_exit_analysis with those same filters and limit, against the cached quotes and bars

    line 156
  8. Very specific:

    After fetching or importing, verify the data is available using run_sql:

    line 160
  9. Very specific:

    If Term_Structure_State is all NULL, check coverage for VIX, VIX9D, and VIX3M, fetch any missing bars, then call compute_vix_context for …

    line 183
  10. Very specific:

    Don't assume a single VIX import computes complete context — ingest all three VIX-family tickers before compute_vix_context

    line 203
  11. Distinctive:

    Don't assume all date ranges have data — Massive index bars start 2023-02-14

    line 204
  12. Distinctive:

    Don't skip per-ticker enrichment — without it RSI and other per-ticker fields won't be populated, and context computation needs enriched …

    line 205
  13. Distinctive:

    Don't fetch the same data twice without checking — repeated calls waste provider usage

    line 206

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Market Data Setup

Guide the user through importing market data so other skills (DC analysis, health checks, replay) have the data they need.

When This Skill Triggers

  • enrich_trades returns warnings about missing market data
  • analyze_regime_performance returns "No trades matched to market data"
  • replay_trade returns 0 minute bars / $0 P&L
  • batch_exit_analysis returns mostly noTrigger with $0 P&L
  • User says "import market data", "set up market data", "I need VIX data", etc.

Step 1: Diagnose What's Missing

Ask the user what they're trying to do, then check what data exists:

Use run_sql with query to inspect coverage (and describe_database if the schema is unfamiliar):

-- Daily bars derived from spot data
SELECT ticker, COUNT(*) AS days, MIN(date) AS earliest, MAX(date) AS latest
FROM market.spot_daily GROUP BY ticker ORDER BY ticker
-- Underlying intraday bars
SELECT ticker, COUNT(*) AS bars, MIN(date) AS earliest, MAX(date) AS latest
FROM market.spot GROUP BY ticker ORDER BY ticker
-- Minute option quotes used by replay
SELECT underlying, COUNT(DISTINCT ticker) AS contracts,
  MIN(date) AS earliest, MAX(date) AS latest
FROM market.option_quote_minutes GROUP BY underlying
-- Cross-ticker regime and term structure
SELECT COUNT(*) AS days, MIN(date) AS earliest, MAX(date) AS latest
FROM market.enriched_context

Present what's available and what's missing for their goal.

Step 2: Determine the Right Data Source

For Regime Analysis (VIX regimes, term structure, enriched trades)

Minimum needed: Daily bars for the underlying and for VIX, VIX9D, VIX3M. Fetch all three VIX tickers before computing cross-ticker context.

What to fetchToolExample arguments
Underlying daily (SPX or QQQ)fetch_barstickers: ["SPX"], from: "2023-02-14", to: "2024-12-31", timespan: "1d"
VIX-family daily barsfetch_barstickers: ["VIX", "VIX9D", "VIX3M"], from: "2023-02-14", to: "2024-12-31", timespan: "1d"
Cross-ticker contextcompute_vix_contextfrom: "2023-02-14", to: "2024-12-31"

Order matters: fetch_bars writes spot bars and auto-enriches each ticker. Once all three VIX-family tickers are ingested and enriched, call compute_vix_context for the same date range. Never compute context on a partially loaded VIX family.

Useful flags on fetch_bars:

  • dry_run: true — preview without writing
  • skip_enrichment: true — defer per-ticker enrichment; if used, call enrich_market_data for each ticker before compute_vix_context

Provider coverage: Massive index bars start 2023-02-14; choose dates the active provider actually covers. to takes a YYYY-MM-DD date, not "today".

Date range: Match the trade data range. Check with:

SELECT MIN(date_opened) as earliest, MAX(date_opened) as latest
FROM trades.trade_data WHERE block_id = '<block>'

For Trade Replay (minute-level P&L paths, greeks, exit trigger simulation)

Needed: Minute option quotes for each OCC leg and minute underlying spot bars for the same trade dates. replay_trade reads the local cache only; it does not auto-fetch missing data.

  1. Decide which trades you will analyze. batch_exit_analysis takes the newest limit trades (default 50, max 200) after its optional strategy, date_range, min_pl and max_pl filters, so read the legs and dates of exactly that set with run_sql, using the same filters and limit:
SELECT legs, date_opened, date_closed FROM trades.trade_data
WHERE block_id = '<block>'
  -- AND strategy ILIKE '%<strategy>%'  AND date_opened >= '<from>'  AND date_opened <= '<to>'
  -- AND pl >= <min_pl>  AND pl <= <max_pl>
ORDER BY date_opened DESC LIMIT 50
  1. Obtain the OCC tickers from every returned trade's legs, then call fetch_quotes for them from each trade's date_opened through its date_closed (a trade held overnight needs every session it was open), e.g. tickers: ["SPXW260320P06410000"], from: "2026-03-20", to: "2026-03-20". Use the actual trade dates and provider coverage; for supported ThetaData bulk fetching, underlyings: ["SPX"] can replace tickers.
  2. Call fetch_bars for each trade's underlying (the ticker its option root resolves to, e.g. SPX for SPXW legs or QQQ for QQQ legs; resolve_root explains a root you are unsure of) with the same open-through-close from and to, and timespan: "1m" for underlying spot bars.
  3. Run replay_trade for one of the prepared trades, or batch_exit_analysis with the same block_id, filters and limit you used in step 1, so it replays only trades whose data is cached. Trades it reports as skipped are missing cached data.

Note: Provider option coverage varies. Missing quotes or underlying bars can yield degenerate replay; inspect coverage before trusting a $0 result.

For TradingView CSV Import

import_market_csv imports minute bars into spot; daily bars and indicators are derived from the intraday data. For a TradingView minute-bar CSV whose time column is a Unix timestamp, map that column to date: the parser extracts the time automatically. Do not present a daily-only CSV as minute bars.

{
  "file_path": "~/Downloads/SPX_1m.csv",
  "ticker": "SPX",
  "column_mapping": {
    "time": "date",
    "open": "open",
    "high": "high",
    "low": "low",
    "close": "close"
  },
  "dry_run": true
}

Use dry_run: true first to inspect the mapping; then repeat without it to write. VIX-family CSV imports also update cross-ticker context, but import all three before verifying derived context.

For External DuckDB Import

import_from_database imports minute bars from a read-only attached DuckDB file, with ext_import_source as the table alias. Map query columns to spot bar fields:

{
  "db_path": "~/data/market.duckdb",
  "query": "SELECT date, time, open, high, low, close FROM ext_import_source.spx_minutes",
  "ticker": "SPX",
  "column_mapping": {
    "date": "date",
    "time": "time",
    "open": "open",
    "high": "high",
    "low": "low",
    "close": "close"
  },
  "dry_run": true
}

Step 3: Fetch or Import

Run the fetches or imports based on what's missing. Common recipes:

Recipe: Full SPX Setup (regime + enrichment)

  1. fetch_bars: tickers: ["SPX"], from: "2023-02-14", to: "2024-12-31", timespan: "1d"
  2. fetch_bars: tickers: ["VIX", "VIX9D", "VIX3M"], same dates and timespan: "1d"
  3. Once all three VIX tickers are enriched, compute_vix_context: same from and to

Recipe: Full QQQ Setup

  1. fetch_bars: tickers: ["QQQ"], the chosen from and to, timespan: "1d"
  2. Fetch the VIX family and compute context as above (shared across underlyings)

Recipe: Replay Data for a Block

  1. Select the trades to analyze with the same filters and limit that batch_exit_analysis will use (see For Trade Replay, step 1)
  2. fetch_quotes for every selected trade's OCC tickers from date_opened through date_closed
  3. fetch_bars for the underlying with timespan: "1m" over the same open-through-close dates
  4. Run replay_trade, or batch_exit_analysis with those same filters and limit, against the cached quotes and bars

Step 4: Verify

After fetching or importing, verify the data is available using run_sql:

-- Check daily coverage
SELECT ticker, COUNT(*) AS days, MIN(date) AS earliest, MAX(date) AS latest
FROM market.spot_daily GROUP BY ticker ORDER BY ticker
-- Check regime data populated
SELECT Vol_Regime, COUNT(*) AS days
FROM market.enriched_context
GROUP BY Vol_Regime ORDER BY Vol_Regime
-- Check term structure populated
SELECT Term_Structure_State, COUNT(*) AS days
FROM market.enriched_context
WHERE Term_Structure_State IS NOT NULL
GROUP BY Term_Structure_State

If Term_Structure_State is all NULL, check coverage for VIX, VIX9D, and VIX3M, fetch any missing bars, then call compute_vix_context for the complete range.

Common Issues

SymptomCauseFix
enrich_trades shows null VIX3M fieldsVIX3M spot bars missingfetch_bars for VIX3M, then compute_vix_context after all three VIX tickers are enriched
Term_Structure_State all NULLVIX-family bars or context missingFetch all three VIX tickers, then compute_vix_context
analyze_regime_performance returns 0 matchedNo underlying daily barsfetch_bars for the underlying with timespan: "1d"
replay_trade returns 0 barsCached option quotes or underlying minute bars missingfetch_quotes for OCC tickers and fetch_bars for the underlying with timespan: "1m"
Enrichment fields missing (RSI, ATR)Per-ticker enrichment skippedRun enrich_market_data with ticker for each affected ticker
Provider fetch returns 0 rowsDate range outside provider coverageCheck the provider's available date range
CSV import fails on column mappingWrong column namesUse dry_run: true first to preview

Cleanup

purge_market_table accepts only table: "daily" | "date_context" | "intraday"; it deletes all rows in that table and its sync metadata, not one ticker or date range. Inspect coverage and confirm the scope with the user before using it to repair corrupted data.

What NOT to Do

  • Don't assume a single VIX import computes complete context — ingest all three VIX-family tickers before compute_vix_context
  • Don't assume all date ranges have data — Massive index bars start 2023-02-14
  • Don't skip per-ticker enrichment — without it RSI and other per-ticker fields won't be populated, and context computation needs enriched VIX data
  • Don't fetch the same data twice without checking — repeated calls waste provider usage

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.