Skip to main content

Overview

The SDK provides high-level methods for trading on Kalshi markets:
  • executeBuyFlow / executeSellFlow - Place buy/sell orders with automatic signature generation
  • executeCancelOrderFlow - Cancel existing orders
  • executeMintFlow / executeBurnFlow - Create/destroy position tokens
  • getUserOrders / getUserPositions - Query user’s orders and positions
To avoid ambiguity, we denote the smallest possible multiple of USDC (0.000001 USDC) as one uusdc, which stands for µUSDC (micro-USDC), and denote the smallest possible multiple of a contract (0.01 contract) as one ccontract (centicontract).User-facing USDC balances are specified as fixed-point strings (e.g. "1.2625" for USDC). Contract quantities in the API and SDK are specified as integer ccontracts strings (e.g. "1050" for 10.50 contracts at precision 2).

Developer Accounts

If you have a developer account, you can set it at the client level to automatically apply it to all orders:
You can also override the dev account for specific orders when using the lower-level placeOrder method:
See the Developer Accounts guide for more information on how to get a dev account and earn from trading fees.

Placing Orders

Place limit orders on Kalshi markets. The SDK handles EIP-712 signature generation automatically.

executeBuyFlow

Parameters

WalletClient
required
Viem wallet client for signing messages
PublicClient
required
Viem public client for reading contract state
string
required
User’s Ethereum address
string
required
Chain identifier ("base" or "bsc"). Vault address is automatically resolved from the /info endpoint.
string
required
Kalshi market ticker (e.g., "KXFEDDECISION-26JAN-T425")
string
required
Position side: "yes" or "no"
string
required
Number of ccontracts as an integer string (e.g., "1050" for 10.50 contracts at precision 2)
Tip: use contractsToCcontracts("10.50", 2).toString() from the SDK to convert a fixed-point contracts string.
string
required
Limit price in µUSDC as an integer string
function
Optional callback for order events (placed, filled, etc.)
function
Optional callback for WebSocket errors

Returns

Object containing:
  • disconnect - Function to stop listening for events
  • txHash - Transaction hash (currently always null for off-chain orders)

Example

executeSellFlow

Works identically to executeBuyFlow but places a sell order.

Example

Cancelling Orders

Cancel an existing open order.

executeCancelOrderFlow

Parameters

WalletClient
required
Viem wallet client for signing messages
string
required
User’s Ethereum address
string
required
Chain identifier ("base" or "bsc"). Vault address is automatically resolved from the /info endpoint.
string
required
ID of the order to cancel (from order event or getUserOrders)

Example

Querying Orders & Positions

getUserOrders

Get orders for a user with optional filtering and pagination.

Parameters

string
required
User’s Ethereum address
object
Optional filtering and pagination parameters

Response

The response includes an orders array and a pagination object:

Examples

Get all pending orders:
Get order history with pagination:
Filter by market:
Filter by date range:

getUserPositions

Get all positions for a user.

Example

Position Token Utilities

Get token addresses and balances for position tokens.

getPositionTokenAddress

Returns the ERC20 token address for a position, or null if not yet created. The vault address is automatically resolved from the /info endpoint.

getTokenBalance

Returns the token balance for a user.

addTokenToWallet

Prompts the user to add a position token to their wallet (MetaMask, etc.).

Example

Error Handling

Important Notes

  • All order prices are in µUSDC (1 USD = 1,000,000 µUSDC, so $0.65 = 650000 µUSDC)
  • Order signatures expire after 10 minutes
  • Minting withdraws positions from the exchange to your wallet as ERC-20 tokens
  • Burning deposits ERC-20 tokens from your wallet back to the exchange as tradeable positions
  • The SDK automatically handles EIP-712 signature generation
  • WebSocket connection is automatically established for buy/sell flows
  • Always call disconnect() to clean up WebSocket connections
  • Developer account IDs set at the client level are automatically applied to all orders