npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

prediction-market-context

v2.0.0

Published

Real-time prediction market context for AI agents and LLMs. World state, uncertainty index, edges, and market data from 30,000+ markets.

Readme

prediction-market-context

Real-time prediction market context for AI agents and LLMs. One function call gives your agent calibrated world awareness from 30,000+ prediction markets.

npm License: MIT

import { world } from 'prediction-market-context'

const state = await world()
console.log(state.index.uncertainty)  // 35 (0-100, how much markets disagree)
console.log(state.regimeSummary)      // "Risk-off: geo elevated, momentum negative"
console.log(state.actionableEdges)    // Markets where model price != market price
console.log(state.movers)             // What moved in the last 24h

Why

LLMs don't know what's happening today. Web search returns narratives and opinions. Prediction markets return calibrated probabilities backed by real money.

This package gives any AI agent instant world awareness:

  • Uncertainty Index — four numbers summarizing global market sentiment
  • Actionable Edges — markets where thesis-implied price diverges from market price
  • Market Movers — what changed in the last 24h across all tracked markets
  • Contagion Signals — when one market should move because another did
  • Regime Summary — one-line qualitative read on the current environment

All data sourced from Kalshi and Polymarket via SimpleFunctions.

Install

npm install prediction-market-context

Quick Start

Zero-config functions

import { world, index, edges, delta, market } from 'prediction-market-context'

// Full world state (~800 tokens, refreshes every 15 min)
const state = await world()

// Just the uncertainty index (4 numbers)
const { uncertainty, geopolitical, momentum, activity } = await index()

// Actionable edges (thesis price != market price)
const { edges: list } = await edges()

// What changed in the last hour (~30-50 tokens)
const changes = await delta('1h')

// Specific market detail with orderbook
const m = await market('KXFEDDECISION', { depth: true })

Client class (for custom config)

import { PredictionMarketClient } from 'prediction-market-context'

const client = new PredictionMarketClient({
  apiKey: process.env.SF_API_KEY,  // optional, enables portfolio overlay
  timeout: 10_000,                  // default 15s
})

const state = await client.world()
const idx = await client.index({ history: true })

Markdown output (for LLM system prompts)

const markdown = await world({ format: 'markdown' })
// Returns ~800 tokens of structured markdown, ready to inject into a system prompt

CLI

# World state
npx prediction-market-context world
npx prediction-market-context world --json

# What changed
npx prediction-market-context delta 1h

# Uncertainty index
npx prediction-market-context index
npx prediction-market-context index --history

# Edges
npx prediction-market-context edges

# Specific market
npx prediction-market-context market KXFEDDECISION

# Search
npx prediction-market-context search "oil prices"

Use with AI Frameworks

OpenAI

import OpenAI from 'openai'
import { world } from 'prediction-market-context'

const state = await world({ format: 'markdown' })

const response = await new OpenAI().chat.completions.create({
  model: 'gpt-4o',
  messages: [
    { role: 'system', content: `You are a market analyst.\n\n${state}` },
    { role: 'user', content: 'What are the key risks right now?' },
  ],
})

Anthropic (Claude)

import Anthropic from '@anthropic-ai/sdk'
import { world } from 'prediction-market-context'

const state = await world({ format: 'markdown' })

const response = await new Anthropic().messages.create({
  model: 'claude-sonnet-4-20250514',
  max_tokens: 1024,
  system: `You are a geopolitical analyst.\n\n${state}`,
  messages: [{ role: 'user', content: 'Summarize the current risk environment.' }],
})

LangChain

import { tool } from '@langchain/core/tools'
import { world, index } from 'prediction-market-context'

const worldTool = tool(async () => {
  return JSON.stringify(await world())
}, {
  name: 'get_world_state',
  description: 'Get real-time prediction market world state with uncertainty index, edges, and movers',
})

const indexTool = tool(async () => {
  return JSON.stringify(await index())
}, {
  name: 'get_uncertainty_index',
  description: 'Get the prediction market uncertainty index (0-100) with geopolitical risk and momentum',
})

As an MCP Tool

For full MCP server integration, use the SimpleFunctions MCP Server:

npx @spfunctions/cli --mcp

API Reference

| Function | Returns | Description | |----------|---------|-------------| | world(options?) | WorldState \| string | Full world state. { format: 'markdown' } for LLM injection. | | index(options?) | UncertaintyIndex | Four-signal uncertainty index. { history: true } for 24h data. | | edges() | EdgesResponse | Actionable edges with reasoning, causal path, absorption. | | delta(since?) | WorldDelta | Incremental changes. "1h", "6h", "24h", or ISO timestamp. | | market(ticker, options?) | MarketDetail | Single market detail. { depth: true } for orderbook. | | markets(tickers, options?) | MarketDetail[] | Batch query up to 20 markets. | | search(query) | SearchResult | Search markets by topic. |

Data

  • 30,000+ prediction markets tracked across Kalshi and Polymarket
  • 548 tickers with live orderbook snapshots
  • 10,000+ market changes detected daily
  • Refreshes every 15 minutes
  • Data available since 2026-03-19

Related

License

MIT — SimpleFunctions