@cryptyx/x402-client
v0.1.0
Published
Typed x402 client for CRYPTYX — the conviction engine for autonomous crypto trading agents. 60 pay-per-call endpoints spanning signals, factor scores, regime detection, backtests, walk-forward validation, and institutional-grade trigger evidence. Wraps @x
Maintainers
Readme
@cryptyx/x402-client
Typed x402 client for CRYPTYX — institutional crypto intelligence for autonomous trading agents. 60 pay-per-call endpoints. USDC on Base. No API keys, no accounts, no rate cards.
npm install @cryptyx/x402-client viemimport { Cryptyx } from '@cryptyx/x402-client';
const cx = new Cryptyx({
wallet: process.env.WALLET_PRIVATE_KEY!, // any viem WalletClient or 0x private key
network: 'base',
maxSpend: 5.00, // USDC hard ceiling
onPay: (r) => console.log(`$${r.priceUsd} → ${r.route} (${r.txHash})`),
});
// Institutional trigger evaluation — one call, full evidence packet
const trigger = await cx.api.triggers.preset({
preset_id: 'treasury_manager_classic',
asset: 'BTC',
});
if (
trigger.trigger.fires_now &&
(trigger.backtest_evidence.sharpe_ratio ?? 0) > 0.3 &&
(trigger.backtest_evidence.profit_factor ?? 0) > 1.5
) {
// Execute on your chosen venue: OKX, Coinbase, Kraken, Hyperliquid, Binance
}What it does
Wraps the entire CRYPTYX x402 API surface — 60 endpoints across:
- Institutional triggers — z-score / z-differential / composite / custom predicates with 5-year backtest evidence (Sortino, MDD, profit factor, walk-forward IS/OOS, regime-conditional performance)
- Signals — 143 atomic + 9 composite, health-graded, walk-forward validated
- Assets — Claude-narrated thesis, cross-class positioning, top setups, top predictors, peer clusters
- Market pulse — factor breadth, conviction leaderboard, factor cross-section, divergences
- Raw data — OHLCV, funding rates, taker flow, IV surface, order-book depth
- AI grounding — natural-language query, trade-idea starter packs, one-shot context bundles
Every response follows the same envelope: { ok, ..., _next?, _cache? }. The _next.hints block on every response guides agents to the natural follow-up endpoint — no external documentation needed.
Why this exists
Building an autonomous agent that trades crypto? You need three things:
- Execution rails — an exchange or DEX (OKX, Coinbase, Kraken, Hyperliquid, Binance, dYdX)
- A wallet — Coinbase AgentKit, Fireblocks, MPC, or plain private key
- Conviction — this SDK
CRYPTYX is the intelligence layer. Ask "should I trade BTC right now?" and get a walk-forward-validated evidence packet with hit rate, Sortino, max drawdown, and regime context — not a chatbot's opinion. Pay-per-call in USDC on Base. Framework-agnostic (works with any wallet, any exchange).
Quickstart
With a raw private key
import { Cryptyx } from '@cryptyx/x402-client';
const cx = new Cryptyx({
wallet: '0x...',
network: 'base',
});
const brief = await cx.api.ai.marketBrief();
console.log(brief.brief); // LLM-ready market summaryWith Coinbase AgentKit
import { CdpWalletProvider } from '@coinbase/agentkit';
import { Cryptyx } from '@cryptyx/x402-client';
const walletProvider = await CdpWalletProvider.configureWithWallet({ ... });
const cx = new Cryptyx({
wallet: walletProvider.getViemWalletClient(),
network: 'base',
});With viem directly
import { createWalletClient, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { base } from 'viem/chains';
import { Cryptyx } from '@cryptyx/x402-client';
const account = privateKeyToAccount('0x...');
const wallet = createWalletClient({ account, chain: base, transport: http() });
const cx = new Cryptyx({ wallet, network: 'base' });The endpoint graph
Every CRYPTYX response includes a _next.hints block pointing at natural follow-ups. Chain them programmatically:
const catalog = await cx.api.signals.catalog();
const chain = cx.chain(catalog, '/api/signals/catalog');
await chain.follow('/api/signals/top');
await chain.follow('/api/signals/backtest', undefined, {
signal_id: 'TR_MOMO_CONT_14D',
from: '2026-01-01',
to: '2026-07-01',
dryrun: true,
});
const all = chain.collect(); // { path → response } for every stepInstitutional trigger evaluation
Four trigger endpoint families:
// Curated preset (5-year backtest cache, fastest)
await cx.api.triggers.preset({ preset_id: 'treasury_manager_classic', asset: 'BTC' });
// Single-metric z-score threshold — pass any metric_id
await cx.api.triggers.zScore({
asset: 'BTC',
metric_id: 'TR_ROC_7D',
operator: 'abs_gt',
threshold: 1.5,
});
// Cross-window differential — the generalised crossover primitive
await cx.api.triggers.zDifferential({
asset: 'BTC',
metric_a_id: 'VOL_RV_7D',
metric_b_id: 'VOL_RV_30D',
operator: 'abs_gt',
threshold: 1.0,
});
// Arbitrary predicate — anything expressible in Metric Slicer
await cx.api.triggers.custom({
asset: 'BTC',
horizon: '14d',
definition: {
type: 'composite',
logic: 'AND',
conditions: [
{ metric_id: 'TR_ROC_7D', operator: 'abs_gt', threshold: 1.5 },
{ metric_id: 'VOL_RV_7D', operator: 'lt', threshold: 1.0 },
],
},
});Every response returns the same institutional evidence envelope:
{
trigger: { asset, horizon, asof_day, fires_now, confidence, expression },
backtest_evidence: {
sample_size, date_start, date_end,
hit_rate, mean_return,
sharpe_ratio, sortino_ratio,
max_drawdown, profit_factor,
},
regime_context: { current_regime, regime_streak_days, conditional_hit_rate },
recent_performance: { last_10_triggers, rolling_30d_hit_rate, rolling_90d_hit_rate },
}Budget safety
Set a hard USDC ceiling; any call that would exceed it throws before the payment is signed:
const cx = new Cryptyx({ wallet, maxSpend: 1.00 });
// ... spends $0.99 across several calls ...
await cx.api.intelligence.query('...'); // $0.25 — throws, current $0.99 + $0.25 > $1.00Reset the counter when you want to continue:
cx.resetSpend();
console.log(cx.spent); // 0
console.log(cx.remaining); // maxSpend
console.log(cx.history); // full receipt listEndpoint reference
All 60 endpoints are grouped on cx.api.*:
cx.api.signals— catalog, top, active, recent, leaderboard, explain, backtest, simulate, fork, eval, composite (attribution / backtest / breadth / heatmap / momentum / custom)cx.api.asset— thesis, thesisJournal, activeSignals, signalEvents, topSetups, topPredictors, asymmetry, peerCluster, regimeContext, regime, metricHealthcx.api.marketPulse— snapshot, regime, divergences, heroTimeline, compositeBreakdown, conviction, factorCrossSection, temporalLayers, regimeCellContext, regimeDivergencecx.api.metrics— slicer, slicerComposite, slicerScan, previewcx.api.triggers— preset, zScore, zDifferential, customcx.api.ai— context, marketBrief, tradeIdeas, signals, metricscx.api.data— assets, marketHistory, assetRegimes, assetFactors, assetLiquidity, fundingRate, takerFlow, ivSurfacecx.intelligenceQuery(...)— natural-language entry pointcx.health()— service probe
Full endpoint documentation: https://cryptyx.ai/docs/x402
Requirements
- Node.js ≥ 18
- A funded EVM wallet on Base with USDC
- ~$1 USDC covers ~100 Standard-tier calls or the full 5-step agent workflow ~5 times
License
MIT. Ship anything you want on top.
Support
- Docs: https://cryptyx.ai/docs/x402
- Issues: https://github.com/cryptyx-ai/cryptyx/issues
- Discord: x402 CDP server
