Perp Risk Engine
Calculates the probability of liquidation for a leveraged cryptocurrency futures position using Monte Carlo simulation over historical price data. Given a token, entry price, leverage, direction, and risk horizon, the endpoint automatically picks an appropriate historical lookback window and simulates thousands of price paths to estimate liquidation risk and the price level at which liquidation would occur.
Parameters
Responses
Examples
1. Long Position Risk Assessment
Calculates the liquidation risk for a 10x leveraged long position opened at $2,800 on a Solana token, over a 1-day risk horizon.
Response:
2 {
3 "riskProbability": 1,
4 "liquidationPrice": 2519.8038627038927,
5 "entryPrice": 2800,
6 "volatility": 0.022190955844549592,
7 "drift": -0.03405525985897041,
8 "priceChangeNeeded": 0,
9 "sigmasAway": 0,
10 "simulationDetails": {
11 "totalSimulations": 10000,
12 "liquidatedPaths": 10000,
13 "dataPointsUsed": 672,
14 "dataInterval": "variable",
15 "riskHorizon": "1d"
16 },
17 "visualizationData": {
18 "histogram": {
19 "bins": [
20 0.9961838126182556,
21 0.9963539242744446,
22 0.9965240955352783,
23 0.9966942071914673,
24 0.996864378452301,
25 0.99703449010849,
26 0.9972046613693237,
27 0.9973747730255127,
28 0.9975449442863464,
29 0.9977150559425354
30 ],
31 "counts": [
32 4,
33 4,
34 5,
35 6,
36 13,
37 21,
38 34,
39 37,
40 64,
41 92
42 ],
43 "finalPrices": [
44 0.9994016289710999,
45 0.999608039855957,
46 1.0007919073104858,
47 1.00118088722229,
48 1.0003645420074463,
49 1.0016578435897827,
50 0.9973054528236389,
51 0.9984804391860962,
52 0.9994128942489624,
53 0.9994698166847229
54 ]
55 },
56 "liquidationThreshold": 2519.8038627038927
57 }
58 }
59]
x402 Payment Option
This endpoint supports pay-per-use access via the x402 payment protocol (v2): pay $0.05 USDC per request using blockchain micropayments. No API key required.
Quickstart (Typescript)
2import { ExactEvmScheme } from "@x402/evm/exact/client";
3import { wrapFetchWithPayment } from "@x402/fetch";
4import { privateKeyToAccount } from "viem/accounts";
5const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
6const client = new x402Client();
7client.register("eip155:*", new ExactEvmScheme(signer));
8const fetchWithPayment = wrapFetchWithPayment(fetch, client);
9const response = await fetchWithPayment(
10 "https://x402.cambrian.org/api/v1/perp-risk-engine"
11);
12const data = await response.json();
Quickstart (Python)
2from eth_account import Account
3from x402 import x402Client
4from x402.http.clients import x402HttpxClient
5from x402.mechanisms.evm import EthAccountSigner
6from x402.mechanisms.evm.exact.register import register_exact_evm_client
7async def main():
8 client = x402Client()
9 account = Account.from_key(os.getenv("EVM_PRIVATE_KEY"))
10 register_exact_evm_client(client, EthAccountSigner(account))
11 async with x402HttpxClient(client) as http:
12 response = await http.get("https://x402.cambrian.org/api/v1/perp-risk-engine")
13 print(response.json())
14asyncio.run(main())
Payment Flow
- Send a normal request to the endpoint (no API key needed)
- Server returns 402 Payment Required with payment details
- The x402 SDK automatically signs a payment authorization with your wallet
- The SDK resubmits the request with the signed payment
- Server verifies payment and returns the API response
The x402 SDK handles steps 2 through 5 automatically.
Network: Base (chain ID 8453) | Currency: USDC | Price: $0.05 per request