Skip to main content
Glama
arbitrage-anyprice
by pjrpjr
README.md
# Arbitrage-AnyPrice

**Cross-Market Real-Time Pricing Inefficiency, GPU-vs-LLM Token Compute Arbitrage & Prediction-Market Resolution-Rule Firewall Terminal.**

[![CI](https://github.com/pjrpjr/arbitrage-anyprice/actions/workflows/ci.yml/badge.svg)](https://github.com/pjrpjr/arbitrage-anyprice/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)

> **Strictly Zero-Custody & Read-Only Posture (MM-04)**: Pure read-only quantitative market-data analytics, resolution-rule equivalence auditing, and signed JSON/MCP/x402 feeds. `$0` client capital custodied, zero automated trading on restricted venues, and zero individualized investment advice.

---

## Why Arbitrage-AnyPrice Exists

Retail arbitrage scanners fail in production because they compare top-of-book midpoints across Polymarket and Kalshi without auditing settlement clauses, ignore Kalshi quadratic fees and FRED risk-free capital lockup carry, or claim "90% GPU compute savings" using VRAM-OOM or 100%-utilization fantasies.

**Arbitrage-AnyPrice** unifies three live public pricing arenas inside one deterministic, cryptographically hash-chained SQLite WAL terminal:

1. **Prediction & Event Markets (`>= 2,300` live contracts)** — Polymarket Gamma + sorted CLOB L2 books (`feesEnabled` modeled), Kalshi Trade API v2 non-MVE series & `orderbook_fp` L2 books, plus Manifold (`MANA_PLAY`) and Metaculus (`POINTS_PLAY`) strictly quarantined as non-cash calibration feeds.
2. **AI Compute & Token Markets (`468` OpenRouter LLMs + `500+` live GPU offers)** — Vast.ai spot GPU slices, stock-verified RunPod GraphQL, and Azure Retail Prices On-Demand baselines compared against open-weight OpenRouter per-1M-token pricing under hard VRAM physics (`weights + 25% KV cache + >=2.5 GB/GPU CUDA/NCCL`), `<= 70%` realistic utilization ceiling, `3:1` input:output token mix, `1 / reliability` preemption haircut, and sublinear PCIe vs NVLink tensor-parallel scaling.
3. **FX, Macro Carry & Digital-Asset Valuation** — Frankfurter ECB FX rates, live FRED DFF / NY Fed EFFR risk-free carry (`3.89%`), CoinGecko/Kraken/Coinbase executable bid/ask spot quotes, and ICANN RDAP domain expiry metadata.

---

## Core Anti-Phantom Architecture

- **Fail-Closed Resolution-Rule Equivalence Firewall**: Blocks divergent oracles (e.g., Binance BTC/USDT vs CF Benchmarks BRTI), asymmetric macro definitions (e.g., BEA-only vs BEA-or-NBER recession), UTC cutoff/timezone gaps (`> 15 min`), boundary mismatches (`>` vs `>=`, intraday touch vs close), one-sided 50-50 void clauses, subjective UMA vs statutory agency rules, inverted polarity/negation traps, play-money conflation, and non-exhaustive Dutch-books.
- **Depth-Weighted Marginal Book Walk & FRED Carry Gate**: Walks sorted opposing orderbooks level-by-level, stops strictly before negative-EV marginal L2 depth, caps executable size at `min(depth_A, depth_B)`, deducts exact Kalshi quadratic `ceil_cents(0.07 * N * p * (1 - p))` + Polymarket active taker fees + compound FRED DFF / EFFR lockup carry (`days_to_expiry + 2d settlement lag`), and rejects `NaN`/`inf` inputs fail-closed.
- **Deep Row-Level SHA-256 SQLite WAL Ledger**: Every polling cycle chains `prev_sha256 -> snapshot_sha256` across all persisted tables; `verify_hash_chain()` recomputes every run's canonical content digest directly from stored SQLite rows to detect silent row tampering.

---

## Quickstart

```bash
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python -e ".[dev]"

# 1. Run full test suite (64+ deterministic core + hostile red-team tests, 0 warnings)
.venv/bin/pytest -v -W error

# 2. Run a live multi-venue ingestion cycle into data/ledger.sqlite3
.venv/bin/python scripts/run_collector.py --once

# 3. Launch the read-only FastAPI terminal + MCP HTTP + x402 API
.venv/bin/python scripts/run_server.py --host 127.0.0.1 --port 8787
```

---

## Independent Verification (Zero Dependencies)

Any independent quant or AI-infrastructure engineer can audit the exported report, SHA-256 manifest checksums, deep SQLite hash chain, and zero-phantom invariants using Python stdlib only:

```bash
python3 scripts/verify_report.py
# Or verify published report checksums without the local SQLite database:
python3 scripts/verify_report.py --manifest-only
```

---

## MCP Server (Stdio & HTTP JSON-RPC 2.0)

Expose 6 strictly read-only quantitative tools to Claude Desktop, Cursor, or autonomous compute routers:

- `get_verified_spreads`
- `get_quarantined_traps`
- `get_backtest_summary`
- `audit_resolution_equivalence`
- `calculate_gpu_vs_api_arbitrage`
- `verify_ledger_integrity`

**Stdio MCP client config**:
```json
{
  "mcpServers": {
    "arbitrage-anyprice": {
      "command": "arbitrage-anyprice-mcp",
      "args": ["--db", "data/ledger.sqlite3"]
    }
  }
}
```

**HTTP MCP endpoint**: `POST /mcp` (JSON-RPC 2.0 `initialize`, `tools/list`, `tools/call`).

---

## x402 Base Mainnet USDC & Creem Subscription API

- **x402 Pay-Per-Query (`$0.01 USDC` on Base)**: `GET /api/v1/x402/spreads` and `GET /api/v1/x402/backtest` return an `x402Version: 1` `HTTP 402` manifest when unauthenticated, and verify real Base mainnet `eth_getTransactionReceipt` USDC `Transfer` logs (`0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`, `status=0x1`, exact `X402_PAY_TO_ADDRESS`, `>= 10000` units) with atomic SQLite replay protection.
- **Subscription Plans (`GET /api/v1/billing/plans`)** (strictly zero-custody read-only analytics via Creem):
  - **Starter / Independent (`$99/mo`)**: [Subscribe via Creem](https://www.creem.io/product/prod_2rs2vCr87QzBlqLDrj5X8h)
  - **Pro Quant API & Backtester (`$299/mo`)**: [Subscribe via Creem](https://www.creem.io/product/prod_DmVW8EKqZT8trRCv1HgjX)
  - **Institutional Terminal Seat (`$995/mo`)**: [Subscribe via Creem](https://www.creem.io/product/prod_3V9iUDaHoxTndKf6gEDICg)
  - Automated fulfillment webhook (`POST /api/v1/billing/creem/webhook`) enforces constant-time HMAC-SHA256 verification and fails closed (`HTTP 503`) when `CREEM_API_KEY` / `CREEM_WEBHOOK_SECRET` are unset.

---

## License

MIT License — see [LICENSE](LICENSE).

TDQS

B3.2/5.0

Scored across 6 tools

Disambiguation4/5

The three listing tools (verified spreads, quarantined traps, backtest summary) target clearly different datasets, and the two computational tools (resolution equivalence audit vs GPU/API arbitrage math) are distinct in purpose. The only mild overlap is between get_backtest_summary and verify_ledger_integrity, both of which mention SHA-256 chain verification, which could cause some selection hesitation.

Naming Consistency5/5

All six names follow a consistent snake_case verb_noun pattern (get_*, audit_*, calculate_*, verify_*), and each verb matches the operation type. No mixed conventions or vague standalone verbs.

Tool Count5/5

Six tools is well within the ideal 3-15 range and each one maps to a distinct facet of the arbitrage workflow: reading results, reading exclusions, historical context, rule auditing, arbitrage math, and integrity verification. No tool appears redundant.

Completeness3/5

The surface is entirely read/compute-oriented: there is no way to trigger a new poll or ingest fresh market data, adjust slippage/VRAM thresholds, or add a contract for ongoing monitoring. Agents can analyze existing ledger state and audit user-supplied specs, but the lifecycle has notable dead ends for data refresh and configuration.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues