# Quant Preflight Mcp (`quant-preflighter/quant-preflight-mcp`) Actor

- **URL**: https://apify.com/quant-preflighter/quant-preflight-mcp.md
- **Developed by:** [jang mongbin](https://apify.com/quant-preflighter) (community)
- **Features:** Limited permissions, Multi-tenant, Server interface
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $8.00 / 1,000 preflight execution risk checks

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## QuantPreflight & Strategy-Audit MCP (`quant-preflight-mcp`)

🌐 **Language**: English | [한국어 사용자 설명서 (Korean Guide)](./README_KO.md)

> **Stop Letting AI Agents Guess Orderbook Slippage, Overbet Kelly Fractions, and Stack Redundant Indicators.**\
> Real-time L2 VWAP book-walk execution drag, cross-venue perpetual microstructure, Ridge-stabilized VIF + Modified Gram-Schmidt feature orthogonalization, and 5,000-path Monte Carlo ruin audits — delivered via **Stateless MCP** at **$0.008–$0.025 per verified call** instead of **$379/month** institutional data terminals.

***

### Fold 1 — 5-Second Value Proposition & 4 Frozen Tools

Autonomous trading bots and AI coding assistants (Claude, Cursor, ChatGPT) routinely hallucinate execution assumptions: they assume 0 bps market impact on $250,000 orders, apply frictionless textbook Kelly formulas, combine 8 collinear momentum oscillators (`VIF > 25`), and ignore consecutive losing-streak math.

**QuantPreflight MCP** gives any MCP-compatible AI agent deterministic, zero-hallucination quantitative pre-trade and strategy-audit tools backed by live public L2 orderbooks (**Hyperliquid Primary + OKX Swap v5 Automatic Failover**) with **zero API keys**, **zero residential proxy cost**, and **Fail-Closed Billing (`$0.00` charged on any error)**.

| MCP Tool (`verb_noun`) | Primary Use Case | Upstream I/O | PPE Price | Calls in $5 Apify Free Credit |
| :--- | :--- | :--- | :---: | :---: |
| `preflight_execution_risk` | Live L2 VWAP slippage (bps/$), fee + funding drag, 14-period Wilder ATR stops, breakeven win-rate penalty, and Half-Kelly sizing | Live L2 + 1H Candles (`3s`/`30s` cache) | **$0.008** | **625 calls / mo** |
| `scan_venue_microstructure` | Normalized annualized funding APR%, open interest (USD), top spread (bps), and $10k/$100k L2 impact across top perpetual pairs | Live Contexts + L2 Depth (`3s` cache) | **$0.010** | **500 calls / mo** |
| `audit_indicator_collinearity` | Detect indicator overfitting via Ridge VIF, Jacobi SVD Condition Number, Effective Rank, and 2-pass Modified Gram-Schmidt orthogonal weights | Mode A: Live OHLCV · Mode B: Pure CPU | **$0.025** | **200 calls / mo** |
| `simulate_backtest_reality` | Inject realistic or live L2 friction into backtest stats across 5,000 seeded Mulberry32 Monte Carlo paths + exact Markov losing-streak DP | Optional Live L2 or Pure CPU | **$0.025** | **200 calls / mo** |

**Cost Anchor**: Institutional derivatives microstructure dashboards charge **$379/month ($4,548/year)** regardless of usage. With `quant-preflight-mcp`, 100 live pre-trade L2 checks cost **$0.80 total** — covered 100% inside Apify's free monthly starter credit.

***

### Fold 2 — 60-Second Setup for Any AI Client (No Coding Needed)

Works out-of-the-box via **Streamable HTTP (`/mcp`)** with **Cursor (Free & Pro)**, **Claude Desktop**, **Antigravity IDE**, **VS Code (Copilot / Cline / Roo Code)**, and **ChatGPT**—plus one-click batch runs inside the **Apify Console**.

#### Option A: Connect via Apify Server (MCP) URL (Recommended)

Copy your Actor's Server URL from **Apify Console → Actor → `Server` tab** (or **Settings → Server**) and paste this into your AI client's MCP config (`~/.cursor/mcp.json`, `claude_desktop_config.json`, or `~/.gemini/config/mcp_config.json`):

```json
{
  "mcpServers": {
    "quant-preflight": {
      "url": "https://<YOUR_APIFY_USERNAME>--quant-preflight-mcp.apify.actor/mcp",
      "headers": {
        "Authorization": "Bearer <YOUR_APIFY_API_TOKEN>"
      }
    }
  }
}
```

#### Option B: Run Locally or on MCPize (`LOCAL_STANDALONE=true`)

```bash
LOCAL_STANDALONE=true PORT=3000 npm start
## Readiness probe: GET http://localhost:3000/health -> {"status":"ok","mode":"multi-tenant"}
## Stateless MCP endpoint: POST http://localhost:3000/mcp
```

#### Copy-Paste Prompts to Try Immediately

Once connected, ask your AI assistant any of these plain-English prompts:

- **Pre-Trade Slippage & ATR Stop**: *"Use `preflight_execution_risk` to check L2 slippage, round-trip fee drag, and 1h ATR stop distances for a $25,000 BTC market buy."*
- **Cross-Asset / Failover Check**: *"Run `preflight_execution_risk` on `NVDAUSDT` for a $10,000 buy to inspect live spread and 1h ATR volatility."* (Automatically fails over to OKX Swap v5 if unlisted on Hyperliquid.)
- **Market Scanner**: *"Call `scan_venue_microstructure` for the top 10 perpetual pairs sorted by annualized funding APR%."*
- **Indicator Overfitting Audit**: *"Use `audit_indicator_collinearity` on BTC 1h candles with `sma_5`, `sma_20`, `ema_12`, `rsi_14`, `bb_upper`, `atr_14` to check VIF and orthogonal weights."*
- **5,000-Path Reality Check**: *"Run `simulate_backtest_reality` for a 52% win rate, 0.8% avg win, 0.5% avg loss, 1.5% risk/trade over 250 trades with live BTC L2 slippage."*

***

### Fold 3 — LLM Hallucination vs. `quant-preflight-mcp` Verified JSON

| Prompt Asked to AI Agent | Typical Unassisted LLM Hallucination | `quant-preflight-mcp` Deterministic Output |
| :--- | :--- | :--- |
| *"Check execution drag for a $250,000 SOL market order with 52% win rate and 1.6 R:R."* | *"Slippage on SOL is usually ~1–2 bps. Using standard Kelly `p - q/b = 22%`, Half-Kelly is 11%."* *(Dangerous overbet + guessed liquidity)* | Walks live L2 levels: measures exact `vwap_execution_price`, `slippage_vs_mid_bps`, `insufficient_book_depth` flag, 14-period Wilder ATR 1.5x/2.0x/3.0x stops, exact breakeven jump `ΔW`, and friction-adjusted Half-Kelly haircut. |
| *"Are SMA(20), EMA(12), Bollinger Middle, and RSI(14) independent features?"* | *"Yes, mixing trend and momentum gives diverse confirmation!"* *(Ignores exact linear redundancy between SMA(20) and BB Middle)* | Computes exact sample correlation `r = 1.000000`, `condition_number = 1e12` (`CRITICAL`), flags redundant pairs `|r| > 0.85`, and outputs 2-pass Modified Gram-Schmidt `orthogonal_weights` (`max_off_diagonal_dot < 1e-14`). |

#### Example Verified Response (`preflight_execution_risk`)

```json
{
  "meta": {
    "advisory": false,
    "data_type": "derived_quantitative_analytics",
    "disclaimer": "Deterministic mathematical calculation for educational and risk-simulation purposes only. Not financial or investment advice."
  },
  "tool": "preflight_execution_risk",
  "asset_symbol": "BTC",
  "venue_used": "hyperliquid",
  "data_freshness_ms": 0,
  "l2_execution_walk": {
    "book_side_swept": "asks",
    "mid_price": 100000,
    "top_spread_bps": 1,
    "requested_order_usd": 50000,
    "filled_order_usd": 50000,
    "insufficient_book_depth": false,
    "vwap_execution_price": 100005,
    "slippage_vs_mid_bps": 0.5
  },
  "friction_breakdown": {
    "round_trip_taker_fee_bps": 7,
    "round_trip_slippage_bps": 1,
    "estimated_funding_drag_bps": 0.125,
    "total_round_trip_friction_bps": 8.125
  }
}
```

***

### Fold 4 — Transparent Pay-Per-Event Pricing & Fail-Closed `$0` Error Guarantee

| Billing Event ID | Triggered By Tool | Event Price (USD) | Recommended `minimalMaxTotalChargeUsd` |
| :--- | :--- | :---: | :---: |
| `preflight-execution-risk` | `preflight_execution_risk` | `$0.008` | `$0.05` |
| `scan-venue-microstructure` | `scan_venue_microstructure` | `$0.010` | `$0.05` |
| `audit-indicator-collinearity` | `audit_indicator_collinearity` | `$0.025` | `$0.05` |
| `simulate-backtest-reality` | `simulate_backtest_reality` | `$0.025` | `$0.05` |

#### Strict Fail-Closed Billing Guarantee (`$0` on Error)

1. **Validation First**: Malformed parameters, oversized payloads (`>256KB`), unsupported HTTP methods (`405`), or rate-limited bursts (`429`) are rejected at the ingress boundary with **`$0.00` billed**.
2. **Upstream Resilience**: If Primary (`Hyperliquid`) times out (`>2,500ms`) or trips its 3-strike circuit breaker, `VenueRouter` automatically fails over to Secondary (`OKX Swap v5`). If *all* venues are unreachable, the server returns `{ isError: true, code: "UPSTREAM_UNAVAILABLE" }` with **`0` calls to `Actor.charge()`**.
3. **Graceful Spend-Cap Protection**: If your Apify Free tier or `maxTotalChargeUsd` ceiling is reached (`eventChargeLimitReached: true`), the server exits cleanly with a structured JSON notice instead of throwing unhandled runtime exceptions.

***

### Fold 5 — Deterministic Mathematical Specifications & Latency SLAs

1. **L2 Orderbook VWAP Book-Walk**: Sweeps sorted resting levels $(p_i, q_i)$ up to notional $N\_{\text{req}}$, computing $\text{VWAP} = \frac{\sum \Delta u_i}{\sum (\Delta u_i / p_i)}$ and $\text{Slippage}*{\text{bps}} = \frac{|\text{VWAP} - P*{\text{mid}}|}{P\_{\text{mid}}} \times 10^4$.
2. **14-Period Wilder ATR**: $TR_t = \max(H_t - L_t, |H_t - C\_{t-1}|, |L_t - C\_{t-1}|)$ smoothed via $ATR_t = \frac{13 \cdot ATR\_{t-1} + TR_t}{14}$, outputting `1.5x`, `2.0x`, and `3.0x` volatility distances and fee-adjusted `1R` notional limits.
3. **Ridge VIF, Jacobi Eigenvalues & 2-Pass Modified Gram-Schmidt**:
   - Excludes zero-variance constant columns ($\sigma < 10^{-12}$) prior to Z-scoring.
   - Computes $\text{VIF}*j = \[(R + 10^{-10}I)^{-1}]*{jj}$ via Gauss-Jordan partial pivoting and spectral Condition Number $\kappa(R) = \min(10^{12}, \lambda\_{\max} / \lambda\_{\min})$ + Shannon Effective Rank $\exp(-\sum p_i \ln p_i)$.
   - Applies Kahan 2-pass Modified Gram-Schmidt re-orthogonalization guaranteeing `max_off_diagonal_dot < 1e-9` (`~1e-15` typical).
4. **Friction-Adjusted Kelly & 5,000-Path Seeded Monte Carlo**:
   - Solves $f^\* = \max\left(0, \frac{p}{1 + c_R} - \frac{1 - p}{B - c_R}\right)$ where $c_R = \frac{C\_{\text{rt}}}{SL}$, alongside 5,000 seeded 32-bit `Mulberry32` multiplicative equity paths and exact $(k+1)$-state absorbing Markov chain streak probabilities for $k \in {4, 6, 8, 10, 12}$.

| Execution Path | Target SLA | Architecture Enabler |
| :--- | :---: | :--- |
| Pure CPU Analytics (Mode B Collinearity & 5,000-Path MC) | **`< 50 ms`** | Inlined `Mulberry32` integer PRNG + `Float64Array` native sort |
| Warm Cache Microstructure Call (`p95`) | **`< 200 ms`** | Bounded 2-tier `LruTtlCache` (`3,000ms` L2/OI · `30,000ms` OHLCV) |
| Cold Live Upstream L2 Call (`p95`) | **`< 500 ms`** | Direct JSON REST (`0` proxy hops) + `2,500ms` `AbortController` |

***

### Fold 6 — 60-Second Verification Checklist & Non-Advisory Regulatory Firewall

#### Quick Local Smoke Test (60 Seconds)

```bash
npm install
npm run typecheck          # Strict tsc --noEmit (0 errors)
npm test                   # 45+ Vitest boundary, security, SLA & fail-closed billing tests
npm run build              # Compile ESM production bundle into dist/
LOCAL_STANDALONE=true npm start
```

#### Strict Non-Advisory & Zero-PII Compliance Notice

- **Zero PII**: `quant-preflight-mcp` never requests, logs, or stores names, emails, wallet addresses, or exchange API keys. Multi-tenant `X-Apify-User-ID` headers are hashed in volatile memory (`SHA-256` 12-char digest) solely for `60 req/min` sliding-window rate limiting.
- **Non-Advisory Firewall**: Every response enforces `"advisory": false` and strips directional trading recommendations. Outputs are strictly deterministic mathematical and market-microstructure computations for educational, research, and pre-trade risk-simulation use only, and do not constitute financial or investment advice.

# Actor input Schema

## `tool` (type: `string`):

Select which of the 4 frozen quantitative audit tools to run.

## `params` (type: `object`):

JSON arguments matching the selected MCP tool's Zod schema.

## Actor input object example

```json
{
  "tool": "scan_venue_microstructure",
  "params": {
    "limit": 5,
    "sort_by": "open_interest_usd"
  }
}
```

# Actor output Schema

## `results` (type: `string`):

JSON dataset items containing tool name, error flag, non-advisory metadata, and deterministic L2/ATR/collinearity/Monte Carlo outputs.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("quant-preflighter/quant-preflight-mcp").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("quant-preflighter/quant-preflight-mcp").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call quant-preflighter/quant-preflight-mcp --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,quant-preflighter/quant-preflight-mcp"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/XsI9UcijKdX2I3Ern/builds/Ly6IX6jew9zVlKn9b/openapi.json
