# Pattern Machine

> Time series pattern matching and regime detection for financial markets.
> Pay-per-call via x402 on Base mainnet (eip155:8453). No API keys required.

## Description

Find historical price analogs using Dynamic Time Warping (DTW). Given any asset and date window,
returns the k most similar historical price patterns with forward return statistics and regime analysis.

## Endpoints

All endpoints: `POST https://market2000.xyz/<endpoint>` with URL query string parameters.
Authentication: x402 micropayment (USDC on Base mainnet) — no API key needed.

| Endpoint | Description | Price |
|---|---|---|
| `/regime_detection` | What historical era does now most resemble? Top-3 analogs + forward returns | $0.05 |
| `/forward_distribution` | P10→P90 return distribution across all historical analogs | $0.05 |
| `/macro_analog` | Match current VIX/yields/SPY/GLD to historical macro periods | $0.05 |
| `/get_patterns` | Find top-k historical price analogs via DTW, with forward return stats | $0.05 |
| `/get_patterns_ohlc` | Same as get_patterns + full OHLC candlestick data per match | $0.05 |
| `/get_patterns_raw` | DTW pattern search — raw matched windows only, no forward stats | $0.05 |
| `/screen` | Rank up to 50 tickers by pattern similarity in one call | $0.05 |
| `/playbook` | When ticker showed this pattern, what did peers do? Cross-asset signal propagation | $0.10 |
| `/pattern_backtest` | Every time ticker did X% in N days, what happened next? | $0.10 |
| `/position_size` | Kelly criterion position sizing from a pattern's historical forward distribution | $0.05 |
| `/pattern_alert` | Webhook fires when current price action matches a historical template | $0.05 |

## Quick Start

```bash
# Get current regime analog for SPY
curl -X POST "https://market2000.xyz/regime_detection?ticker=SPY&lookback_days=60&k=3" \
  -H "X-PAYMENT: <x402-payment-header>"

# Find historical analogs for AAPL Q1 2024
curl -X POST "https://market2000.xyz/get_patterns?ticker=AAPL&start_date=2024-01-01&end_date=2024-03-01&k=5" \
  -H "X-PAYMENT: <x402-payment-header>"
```

## Payment

- Protocol: [x402](https://x402.org) — HTTP-native pay-per-call micropayments
- Network: Base mainnet (eip155:8453)
- Asset: USDC (`0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`)
- Discovery: `/.well-known/x402`
- Docs: `https://market2000.xyz/docs`
