MarketHeist Backtest API API
Fetch historical OHLCV price data and run quantitative backtests on 20+ built-in technical indicators. All data is sourced from Yahoo Finance. Backtests run server-side on Cloudflare Workers.
Fetch historical OHLCV price data and run quantitative backtests on 20+ built-in technical indicators. All data is sourced from Yahoo Finance. Backtests run server-side on Cloudflare Workers.
Every API here is available over the APIs.io API and to AI agents over MCP.
One button, every client — Claude, Cursor, VS Code and the rest.
https://apis.io/mcp
find_apisBrowse and filter every API in the catalog.get_api_artifactsOne API's artifacts, grouped by type.get_openapiThe primary OpenAPI for this API.find_similar_apisAPIs that look like this one.apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.resolveTurn a domain, URL or GitHub org into the provider it belongs to.find_cohortsEvery scored population of providers in the catalog.curl "https://apis.io/api/v1/apis/marketheist-io:marketheist-backtest-api-api"
curl "https://apis.io/api/v1/apis?limit=25"
Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.
Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.
A second provider on the same verified email joins the account you already have.
{"openapi":"3.1.0","info":{"title":"MarketHeist Backtest API","version":"1.0.0","description":"Fetch historical OHLCV price data and run quantitative backtests on 20+ built-in technical indicators. All data is sourced from Yahoo Finance. Backtests run server-side on Cloudflare Workers.","contact":{"url":"https://marketheist.io/docs/"}},"servers":[{"url":"https://api.marketheist.io"}],"security":[],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"Session token obtained by completing the magic-link login flow at marketheist.io/backtest/. Pass the token value from localStorage key `bth.session.v1` as a Bearer token."}},"schemas":{"Frequency":{"type":"string","enum":["1d","1wk","1mo"],"description":"Data bar frequency. 1d = daily, 1wk = weekly, 1mo = monthly."},"OhlcvRow":{"type":"object","required":["t","o","h","l","c","v"],"properties":{"t":{"type":"number","description":"Bar open timestamp (Unix milliseconds)."},"o":{"type":"number","description":"Open price."},"h":{"type":"number","description":"High price."},"l":{"type":"number","description":"Low price."},"c":{"type":"number","description":"Adjusted close price."},"v":{"type":"number","description":"Volume."}}},"OhlcvResponse":{"type":"object","required":["ticker","frequency","rows"],"properties":{"ticker":{"type":"string","description":"Yahoo Finance ticker symbol."},"frequency":{"$ref":"#/components/schemas/Frequency"},"rows":{"type":"array","items":{"$ref":"#/components/schemas/OhlcvRow"},"description":"Chronologically ordered OHLCV bars. Holiday/null bars are omitted."}}},"PositionRule":{"oneOf":[{"type":"object","title":"Threshold","description":"Long when the indicator value is above (or below) a fixed threshold.","required":["type","threshold","direction"],"properties":{"type":{"type":"string","enum":["threshold"]},"threshold":{"type":"number","description":"Crossover level (e.g. 50 for RSI)."},"direction":{"type":"string","enum":["above","below"],"description":"Long when indicator is above or below the threshold."}}},{"type":"object","title":"Crossover","description":"Long when the indicator value is above its own moving average.","required":["type","ma_window","direction"],"properties":{"type":{"type":"string","enum":["crossover"]},"ma_window":{"type":"integer","minimum":2,"description":"MA window in bars."},"direction":{"type":"string","enum":["above","below"]}}},{"type":"object","title":"Percentile","description":"Long when the indicator is above its rolling percentile rank.","required":["type","lookback","percentile","direction"],"properties":{"type":{"type":"string","enum":["percentile"]},"lookback":{"type":"integer","minimum":10,"description":"Rolling window in bars."},"percentile":{"type":"number","minimum":0,"maximum":100},"direction":{"type":"string","enum":["above","below"]}}}]},"LeverageConfig":{"oneOf":[{"type":"object","title":"None","description":"No leverage applied (1×). Default.","required":["mode"],"properties":{"mode":{"type":"string","enum":["none"]}}},{"type":"object","title":"Fixed","description":"Fixed leverage multiplier (e.g. 2.0 = 2×).","required":["mode","value"],"properties":{"mode":{"type":"string","enum":["fixed"]},"value":{"type":"number","minimum":0.1,"maximum":10}}},{"type":"object","title":"Target volatility","description":"Scale leverage so annualized strategy vol matches target_vol (e.g. 0.15 = 15% target annualized volatility).","required":["mode","target_vol"],"properties":{"mode":{"type":"string","enum":["target_vol"]},"target_vol":{"type":"number","minimum":0.01,"maximum":2}}},{"type":"object","title":"Target drawdown","description":"Scale leverage so max drawdown matches target_dd (e.g. -0.40 = target -40% max drawdown).","required":["mode","target_dd"],"properties":{"mode":{"type":"string","enum":["target_dd"]},"target_dd":{"type":"number","minimum":-1,"maximum":-0.01}}}]},"RegimeFilter":{"oneOf":[{"type":"object","title":"Trend","description":"Only hold long positions when close > SMA(close, sma_window). The classic 200-period trend filter.","required":["type","sma_window"],"properties":{"type":{"type":"string","enum":["trend"]},"sma_window":{"type":"integer","minimum":2,"default":200}}},{"type":"object","title":"Volatility","description":"Only hold positions when ATR%(period) < max_atr_pct. Avoids entering during high-volatility / crisis regimes.","required":["type","atr_period","max_atr_pct"],"properties":{"type":{"type":"string","enum":["volatility"]},"atr_period":{"type":"integer","minimum":2},"max_atr_pct":{"type":"number","minimum":0}}}]},"BacktestConfig":{"type":"object","required":["indicator_id","indicator_params","position_rule","execution_delay","leverage"],"properties":{"indicator_id":{"type":"string","description":"Built-in indicator identifier. Supported values: rsi, bollinger, ma_crossover, ema_crossover, adx, atr, cci, obv, stochastic, vwap_dev, curvature, vol_ratio."},"indicator_params":{"type":"object","additionalProperties":{"oneOf":[{"type":"number"},{"type":"boolean"},{"type":"string"}]},"description":"Indicator parameter values keyed by param name. Use the indicator's default values if unsure (e.g. RSI: { period: 14 })."},"position_rule":{"$ref":"#/components/schemas/PositionRule"},"execution_delay":{"type":"integer","minimum":0,"maximum":5,"description":"Bars of lag between signal and execution (0 = the signal bar's own return, which looks ahead; 1 = position is held from the following bar, i.e. filled at the signal bar's close). Use 1 to avoid lookahead bias.","default":1},"transaction_costs_bps":{"type":"number","minimum":0,"description":"One-way transaction cost in basis points (1 bps = 0.01%). Default 0.","default":0},"leverage":{"$ref":"#/components/schemas/LeverageConfig"},"regime_filter":{"$ref":"#/components/schemas/RegimeFilter","description":"Optional secondary filter. Zeroes out positions outside the regime."}}},"MetricsBlock":{"type":"object","description":"Performance metrics for one strategy (strategy or buy-and-hold).","properties":{"sharpe":{"type":"number","description":"Annualized Sharpe ratio."},"sortino":{"type":"number","description":"Annualized Sortino ratio."},"cagr":{"type":"number","description":"Compound annual growth rate (decimal, e.g. 0.12 = 12%)."},"max_dd":{"type":"number","description":"Maximum drawdown (decimal, e.g. -0.35 = -35%)."},"calmar":{"type":"number","description":"CAGR / |max_dd|."},"omega":{"type":"number","description":"Omega ratio (threshold = 0)."},"profit_factor":{"type":"number","description":"Gross profit / gross loss."},"recovery_factor":{"type":"number","description":"Total return / |max_dd|."},"pct_invested":{"type":"number","description":"Fraction of bars holding a long position (0–1)."}}},"Validity":{"type":"object","description":"Trust layer: where the numbers came from, their known failure modes, and how to reproduce them. Present on every backtest result — reproducible about the past, traceable to its inputs, flagged for known failure modes.","required":["provenance","caveats","reproduce"],"properties":{"provenance":{"type":"object","required":["engine_version","data_source","ticker","frequency","price_basis","bar_count","warmup_bars","sample_start","sample_end","n_years"],"properties":{"engine_version":{"type":"string","description":"Pinned engine version."},"data_source":{"type":"string","description":"Market-data source id, e.g. \"yahoo\"."},"ticker":{"type":"string"},"frequency":{"$ref":"#/components/schemas/Frequency"},"price_basis":{"type":"string","enum":["total-return-adjusted"],"description":"Close is total-return adjusted (dividends reinvested, splits applied)."},"bar_count":{"type":"integer","description":"Bars the metrics were computed on (after warm-up)."},"warmup_bars":{"type":"integer","description":"Bars dropped to warm up indicators / align buy-and-hold."},"sample_start":{"type":"string","format":"date","description":"First bar of the measured window (UTC)."},"sample_end":{"type":"string","format":"date","description":"Last bar of the measured window (UTC)."},"n_years":{"type":"number","description":"Length of the measured window in years."}}},"caveats":{"type":"array","description":"Known limitations of this run. severity=warn materially affects interpretation.","items":{"type":"object","required":["code","severity","message"],"properties":{"code":{"type":"string","enum":["single-run-no-walkforward","no-transaction-costs","short-sample","few-trades","leverage-frictionless","sharpe-not-significant","parameter-overfit"]},"severity":{"type":"string","enum":["info","warn"]},"message":{"type":"string"}}}},"reproduce":{"type":"object","required":["config_hash","recipe"],"properties":{"config_hash":{"type":"string","description":"Deterministic fingerprint of the run inputs (config + measured window + engine version). Same inputs → same hash; a citation key, not a cryptographic commitment."},"recipe":{"type":"string","description":"One-line recipe for reproducing the run."}}}}},"BacktestResponse":{"type":"object","required":["ticker","frequency","indicator_id","metrics","equity_curve","drawdown_curve","bar_count","validity"],"properties":{"ticker":{"type":"string"},"frequency":{"$ref":"#/components/schemas/Frequency"},"indicator_id":{"type":"string"},"metrics":{"type":"object","properties":{"strategy":{"$ref":"#/components/schemas/MetricsBlock"},"buyhold":{"$ref":"#/components/schemas/MetricsBlock"},"applied_leverage":{"type":"number","description":"Actual leverage multiplier used (1.0 when mode=none)."},"leverage_mode":{"type":"string","description":"Echo of the leverage mode used."},"n_years":{"type":"number","description":"Number of years of data used."}}},"equity_curve":{"type":"array","items":{"type":"array","prefixItems":[{"type":"number"},{"type":"number"}],"minItems":2,"maxItems":2},"description":"Strategy equity curve as [unixMs, value] pairs. Starts at 1.0."},"drawdown_curve":{"type":"array","items":{"type":"array","prefixItems":[{"type":"number"},{"type":"number"}],"minItems":2,"maxItems":2},"description":"Strategy drawdown series as [unixMs, value] pairs. Values ≤ 0."},"bar_count":{"type":"integer","description":"Number of data bars used after warm-up alignment."},"validity":{"$ref":"#/components/schemas/Validity"}}},"ErrorResponse":{"type":"object","required":["error"],"properties":{"error":{"type":"string","description":"Human-readable error message."},"code":{"type":"string","description":"Machine-readable reason, where the endpoint provides one (e.g. `not_found`, `upstream_unavailable`)."},"retryable":{"type":"boolean","description":"Whether the same request may succeed later."},"detail":{"type":"string","description":"Raw upstream reason, for debugging."}}}}},"paths":{"/api/ohlcv":{"get":{"operationId":"getOhlcv","summary":"Fetch historical OHLCV data","description":"Returns the full historical OHLCV price series for a Yahoo Finance ticker. Data is cached server-side for up to 1 hour. No authentication required.","parameters":[{"name":"ticker","in":"query","required":true,"schema":{"type":"string"},"description":"Yahoo Finance ticker symbol. Examples: AAPL, MSFT, ^NDX, BTC-USD, GC=F. Use URL encoding for special characters (e.g. ^NDX → %5ENDX)."},{"name":"frequency","in":"query","required":false,"schema":{"$ref":"#/components/schemas/Frequency"},"description":"Bar frequency. Defaults to 1wk."}],"responses":{"200":{"description":"OHLCV data returned successfully.","headers":{"x-cache":{"schema":{"type":"string","enum":["HIT","MISS","STALE"]},"description":"HIT = fresh cache, MISS = fetched now, STALE = provider unavailable, last good copy served."},"x-data-stale":{"schema":{"type":"string","enum":["true"]},"description":"Present when the data provider was unavailable and the last good cached copy was served."},"x-data-age":{"schema":{"type":"integer"},"description":"Seconds since the data was fetched from the provider, when known."}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OhlcvResponse"},"example":{"ticker":"^NDX","frequency":"1wk","rows":[{"t":1704067200000,"o":16825.93,"h":16932.17,"l":16548.28,"c":16832.92,"v":0},{"t":1704672000000,"o":16832.92,"h":17314.01,"l":16739.11,"c":17314.01,"v":0}]}}}},"400":{"description":"Missing or invalid query parameters.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"No data for this symbol (code `not_found`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"502":{"description":"The data provider returned unusable data (code `upstream_error`).","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"The data provider is rate-limiting or not responding (code `upstream_unavailable`, `retryable: true`). Retry after the `Retry-After` header. When a recent cached copy exists it is served instead, with status 200 and `x-data-stale: true`.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}},"/api/backtest":{"post":{"operationId":"runBacktest","summary":"Run a single-strategy backtest","description":"Fetches OHLCV data (from cache or Yahoo Finance), runs the specified built-in indicator and position rule through the backtest engine, and returns performance metrics plus equity and drawdown curves. No authentication required.","security":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["ticker","frequency","config"],"properties":{"ticker":{"type":"string","description":"Yahoo Finance ticker symbol.","example":"^NDX"},"frequency":{"$ref":"#/components/schemas/Frequency"},"config":{"$ref":"#/components/schemas/BacktestConfig"}}},"example":{"ticker":"^NDX","frequency":"1wk","config":{"indicator_id":"rsi","indicator_params":{"period":14},"position_rule":{"type":"threshold","threshold":50,"direction":"above"},"execution_delay":1,"leverage":{"mode":"none"}}}}}},"responses":{"200":{"description":"Backtest completed successfully.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BacktestResponse"}}}},"400":{"description":"Invalid request body or unknown indicator_id.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"No data for this ticker.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"422":{"description":"Insufficient data or backtest engine error.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"502":{"description":"The data provider returned unusable data.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"503":{"description":"The data provider is temporarily unavailable; retry in a minute.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}