MCP Kalshi
An MCP server for interacting with Kalshi prediction markets
- Package:
@iqai/mcp-kalshi - Purpose: Interacting with Kalshi prediction markets for trading and market analysis.
Usage with ADK TypeScript
import {McpKalshi} from "@iqai/adk";
const toolset = McpKalshi({
env: {
KALSHI_API_KEY: process.env.KALSHI_API_KEY,
KALSHI_PRIVATE_KEY_PATH: process.env.KALSHI_PRIVATE_KEY_PATH,
},
})
const tools = await toolset.getTools()import {McpToolset} from "@iqai/adk";
const toolset = new McpToolset({
name: "Kalshi MCP Client",
description: "Client for Kalshi prediction markets",
transport: {
mode: "stdio",
command: "pnpm",
args: ["dlx", "@iqai/mcp-kalshi"],
env: {
KALSHI_API_KEY: process.env.KALSHI_API_KEY,
KALSHI_PRIVATE_KEY_PATH: process.env.KALSHI_PRIVATE_KEY_PATH,
PATH: process.env.PATH || "",
},
},
})
const tools = await toolset.getTools(){
"mcpServers": {
"kalshi-mcp-server": {
"command": "pnpm",
"args": ["dlx", "@iqai/mcp-kalshi"],
"env": {
"KALSHI_API_KEY": "your_kalshi_api_key",
"KALSHI_PRIVATE_KEY_PATH": "/path/to/your/private_key.pem"
}
}
}
}Available Tools
GET_MARKETSlimit:numbercursor:stringeventTicker:stringseriesTicker:stringstatus:stringtickers:string
GET_MARKETSDescription
List and discover prediction markets on Kalshi. Markets represent binary outcomes users can trade on. Returns paginated results with market details including ticker, title, prices, and volume.
GET_MARKETticker:string
GET_MARKETDescription
Get detailed information about a specific prediction market by its ticker, including current prices, volume, open interest, and settlement rules.
GET_MARKET_ORDERBOOKticker:stringdepth:number
GET_MARKET_ORDERBOOKDescription
Get the current orderbook for a market showing bid prices and quantities for both Yes and No sides.
GET_TRADESticker:stringlimit:numbercursor:stringminTs:numbermaxTs:number
GET_TRADESDescription
Get recent public trades across all markets or for a specific market. Each trade shows price, quantity, and timestamp.
GET_SERIESseriesTicker:string
GET_SERIESDescription
Get information about a series, which is a template for recurring events (e.g., monthly jobs reports, daily weather).
GET_BALANCENo parameters
GET_BALANCENo parameters
Description
Get the current account balance and portfolio value. Values are returned in dollars.
GET_POSITIONSticker:stringeventTicker:stringlimit:numbercursor:stringcountFilter:string
GET_POSITIONSDescription
Get your current portfolio positions showing market exposure, cost basis, and P&L for each position.
GET_FILLSticker:stringorderId:stringlimit:numbercursor:stringminTs:numbermaxTs:number
GET_FILLSDescription
Get your trade fill history. A fill occurs when your order is matched with another trader.
GET_SETTLEMENTSticker:stringeventTicker:stringlimit:numbercursor:stringminTs:numbermaxTs:number
GET_SETTLEMENTSDescription
Get your settlement history showing resolved markets and their payouts.
GET_ORDERSticker:stringeventTicker:stringstatus:stringlimit:numbercursor:string
GET_ORDERSDescription
Get your orders with optional filtering by market, status, or time range.
GET_ORDERorderId:string
GET_ORDERDescription
Get detailed information about a specific order by its ID.
CREATE_ORDERticker:stringside:stringaction:stringcount:numbertype:stringyesPrice:numbernoPrice:numbertimeInForce:stringpostOnly:booleanreduceOnly:boolean
CREATE_ORDERDescription
Create a new order to buy or sell contracts in a prediction market. Use limit orders with a price, or market orders for immediate execution.
CANCEL_ORDERorderId:string
CANCEL_ORDERDescription
Cancel an existing open order by its ID.
BATCH_CANCEL_ORDERSids:array
BATCH_CANCEL_ORDERSDescription
Cancel multiple orders at once (up to 20 orders per batch).
DECREASE_ORDERorderId:stringreduceBy:number
DECREASE_ORDERDescription
Decrease the quantity of an existing order. This is the only way to reduce order size without fully canceling.
Environment Variables
Security
Private keys are used for trading operations. Handle with care and never commit them to version control.
KALSHI_API_KEY: Required. Your Kalshi API key ID.KALSHI_PRIVATE_KEY_PATH: Path to your RSA private key PEM file.KALSHI_PRIVATE_KEY_PEM: RSA private key as PEM string (alternative to path).
Authentication
Provide either KALSHI_PRIVATE_KEY_PATH or KALSHI_PRIVATE_KEY_PEM, not both.
Usage Examples
Here's a complete example of using MCP Kalshi with an ADK agent:
import { McpKalshi, AgentBuilder } from "@iqai/adk";
import dotenv from "dotenv";
dotenv.config();
async function main() {
// Initialize Kalshi MCP toolset
const toolset = McpKalshi({
env: {
KALSHI_API_KEY: process.env.KALSHI_API_KEY,
KALSHI_PRIVATE_KEY_PATH: process.env.KALSHI_PRIVATE_KEY_PATH,
},
debug: false,
retryOptions: {
maxRetries: 3,
initialDelay: 500,
},
});
// Get available tools
const kalshiTools = await toolset.getTools();
// Create agent with Kalshi tools
const { runner } = await AgentBuilder.create("kalshi_agent")
.withModel("gemini-2.5-flash")
.withDescription("An agent that interacts with Kalshi prediction markets")
.withTools(...kalshiTools)
.build();
try {
// Example queries
const response = await runner.ask("Show me available markets on Kalshi");
console.log(response);
} finally {
// Clean up resources
await toolset.close();
}
}
main().catch(console.error);Getting Your Credentials
API Key
- Sign up at Kalshi
- Navigate to your account settings
- Generate an API key
Private Key
Generate an RSA private key for API authentication. You can provide it either as a file path (KALSHI_PRIVATE_KEY_PATH) or as a PEM string (KALSHI_PRIVATE_KEY_PEM).
Important
Never share your private key or commit it to version control. Always use environment variables or secure secret management systems.
Best Practices
- Security: Store API keys and private keys in environment variables, never hardcode them
- Resource Cleanup: Always call
await toolset.close()when done to properly close connections - Error Handling: Implement proper error handling for trading operations
- Rate Limits: Be aware of Kalshi API rate limits and implement appropriate retry logic
Error Handling
Error Scenarios
The server handles various error scenarios gracefully.
šØ Missing credentials: Ensure KALSHI_API_KEY and a private key are set
šø Insufficient balance: Ensure your account has sufficient funds for trading
š Invalid market identifiers: Verify market IDs are correct
š Network issues: Check your internet connection and Kalshi API status
Resources
- Kalshi - Kalshi prediction market platform
- Model Context Protocol - MCP specification and standards