@gaberoo/kalshitools
v1.1.1
Published
CLI for interacting with Kalshi prediction markets API
Maintainers
Readme
kalshitools
A powerful CLI tool for interacting with the Kalshi prediction markets API. Built for traders, automated systems, and AI agents.
Features
- 🔐 Secure Authentication: RSA-PSS based authentication with secure credential storage
- 📊 Market Data: Browse markets, view order books, filter by event/series, batch queries
- 💼 Portfolio Management: View balances, positions with P&L, settlement status filtering
- 📈 Trading: Place and manage orders with safety features, dry-run mode
- 🤖 AI-Friendly: Structured JSON output for automated systems (OpenClaw integration ready)
- 🛡️ Safety First: Demo environment default, confirmations, and order limits
- 📈 Order Book Analysis: Real-time order depth and liquidity assessment
- 🔍 Market Discovery: Event/series filtering, nested markets, multi-ticker batch queries
- 📊 Portfolio Analytics: Comprehensive performance metrics, win rate, P&L analysis, fee tracking
- ⚠️ Risk Management: Real-time risk assessment, concentration analysis, correlation detection
- 📈 Historical Analysis: Time-series performance data, maker/taker statistics, trend analysis
- 🔎 Market Scanner: Automated opportunity discovery based on liquidity, spreads, and volume
Quick Start
1. Install
npm install -g @gaberoo/kalshitools2. Get Demo API Credentials
Visit the Kalshi Demo Portal to generate API credentials:
- API Key ID: Your registered email address
- Private Key: Download the
.pemfile
3. Configure Credentials
Option A: Interactive Setup (Recommended)
# Run the configuration wizard
kalshitools config init
# Follow the prompts:
# - Environment: demo (default)
# - API Key ID: [email protected]
# - Private Key Path: ~/.kalshitools/demo-private-key.pem (default)
# Place your private key file
mkdir -p ~/.kalshitools
cp ~/Downloads/private-key.pem ~/.kalshitools/demo-private-key.pem
chmod 600 ~/.kalshitools/demo-private-key.pem # Secure permissionsOption B: Environment Variables (Quick Testing)
# Copy the example file
cp .env.example .env
# Edit .env with your credentials
nano .env
# Source the environment
source .env4. Verify Setup
# Check configuration
kalshitools config show
# Test API connection
kalshitools portfolio balance
# List active markets
kalshitools markets list --status active --limit 55. Start Trading
# View available markets
kalshitools markets list --status active
# Get market details
kalshitools markets show TICKER-SYMBOL
# View order book for liquidity analysis
kalshitools markets orderbook TICKER-SYMBOL --depth 5
# Discover markets within an event
kalshitools markets list --event-ticker EVENT-ID
# Batch query multiple tickers
kalshitools markets list --tickers "TICKER1,TICKER2,TICKER3"
# View your portfolio
kalshitools portfolio balance
kalshitools portfolio positions
# Filter positions by settlement status
kalshitools portfolio positions --settlement-status open
# Place an order (with confirmation)
kalshitools orders create \
--ticker MARKET-TICKER \
--action buy \
--side yes \
--quantity 10 \
--type market
# Use --dry-run to simulate without placing order
kalshitools orders create \
--ticker MARKET-TICKER \
--action buy \
--side yes \
--quantity 10 \
--type market \
--dry-run
# View order history
kalshitools orders list
# Analyze portfolio performance
kalshitools portfolio analytics --period 30 --json
# Check portfolio risk
kalshitools portfolio risk --threshold 20
# View historical performance
kalshitools portfolio history --group-by week
# Scan markets for opportunities
kalshitools markets scan --min-liquidity 200 --min-spread 0.05Advanced Features for AI Trading Agents
kalshitools provides powerful analytics and scanning capabilities designed for automated trading systems:
Portfolio Analytics
Get comprehensive performance metrics for strategy evaluation:
# Full analytics for last 30 days
kalshitools portfolio analytics --period 30 --json
# Custom date range
kalshitools portfolio analytics \
--min-ts 2026-01-01T00:00:00Z \
--max-ts 2026-02-01T00:00:00Z \
--json
# Returns: win rate, avg P&L, total return, exposure ratio, concentration, feesRisk Management
Real-time risk assessment to prevent over-concentration:
# Check portfolio risk with 20% position limit
kalshitools portfolio risk --threshold 20 --json
# Analyze concentration by event
kalshitools portfolio risk --group-by event --json
# Returns: risk score, concentrations, correlations, alerts, recommendationsHistorical Performance
Deep dive into trading history with time-series analytics:
# Daily performance breakdown
kalshitools portfolio history --group-by day --json
# Filter by specific market
kalshitools portfolio history --ticker MARKET-A --json
# Returns: time-series data, maker/taker stats, performance by tickerMarket Opportunity Scanner
Discover high-quality trading opportunities:
# Scan for markets with good liquidity and spreads
kalshitools markets scan \
--min-liquidity 200 \
--min-spread 0.05 \
--max-spread 0.20 \
--min-volume 1000 \
--json
# Filter to specific event
kalshitools markets scan --event-ticker EVENT-2024 --json
# Returns: scored opportunities with liquidity, spread, and volume dataConfiguration
Configuration is stored at ~/.config/kalshitools/config.json and can be overridden with environment variables:
export KALSHI_ENV=demo
export [email protected]
export KALSHI_PRIVATE_KEY_PATH=~/.kalshitools/demo-private-key.pem
export LOG_LEVEL=infoSecurity Notes
- Private keys are never committed to the repository
- All
.pem,.key, and.envfiles are in.gitignore - Demo environment is the default (safe for testing)
- Always use
--dry-runfirst to verify order parameters - Store private keys with restricted permissions:
chmod 600
Configuration Precedence
- Environment variables (highest priority)
~/.config/kalshitools/config.json- Default values (demo environment)
- kalshitools
- Run the configuration wizard
- Follow the prompts:
- - Environment: demo (default)
- - API Key ID: [email protected]
- - Private Key Path: ~/.kalshitools/demo-private-key.pem (default)
- Place your private key file
- Copy the example file
- Edit .env with your credentials
- Source the environment
- Check configuration
- Test API connection
- List active markets
- View available markets
- Get market details
- View order book for liquidity analysis
- Discover markets within an event
- Batch query multiple tickers
- View your portfolio
- Filter positions by settlement status
- Place an order (with confirmation)
- Use --dry-run to simulate without placing order
- View order history
- Analyze portfolio performance
- Check portfolio risk
- View historical performance
- Scan markets for opportunities
- Full analytics for last 30 days
- Custom date range
- Returns: win rate, avg P&L, total return, exposure ratio, concentration, fees
- Check portfolio risk with 20% position limit
- Analyze concentration by event
- Returns: risk score, concentrations, correlations, alerts, recommendations
- Daily performance breakdown
- Filter by specific market
- Returns: time-series data, maker/taker stats, performance by ticker
- Scan for markets with good liquidity and spreads
- Filter to specific event
- Returns: scored opportunities with liquidity, spread, and volume data
- Usage
- Commands
Usage
$ npm install -g @gaberoo/kalshitools
$ kalshitools COMMAND
running command...
$ kalshitools (--version)
@gaberoo/kalshitools/1.1.1 darwin-arm64 node-v22.20.0
$ kalshitools --help [COMMAND]
USAGE
$ kalshitools COMMAND
...Commands
kalshitools config initkalshitools config showkalshitools help [COMMAND]kalshitools markets listkalshitools markets orderbook TICKERkalshitools markets scankalshitools markets show TICKERkalshitools orders cancel ORDERIDkalshitools orders createkalshitools orders listkalshitools pluginskalshitools plugins add PLUGINkalshitools plugins:inspect PLUGIN...kalshitools plugins install PLUGINkalshitools plugins link PATHkalshitools plugins remove [PLUGIN]kalshitools plugins resetkalshitools plugins uninstall [PLUGIN]kalshitools plugins unlink [PLUGIN]kalshitools plugins updatekalshitools portfolio analyticskalshitools portfolio balancekalshitools portfolio fillskalshitools portfolio historykalshitools portfolio positionskalshitools portfolio risk
kalshitools config init
Initialize kalshitools configuration interactively
USAGE
$ kalshitools config init [--json] [--env demo|production] [--keyId <value>] [--privateKeyPath <value>]
FLAGS
--env=<option> [default: demo] Environment to configure (demo or production)
<options: demo|production>
--json Output in JSON format
--keyId=<value> API key ID (email)
--privateKeyPath=<value> Path to private key file
DESCRIPTION
Initialize kalshitools configuration interactively
EXAMPLES
$ kalshitools config init
$ kalshitools config init --env productionSee code: src/commands/config/init.ts
kalshitools config show
Show current configuration (credentials redacted)
USAGE
$ kalshitools config show [--json]
FLAGS
--json Output in JSON format
DESCRIPTION
Show current configuration (credentials redacted)
EXAMPLES
$ kalshitools config show
$ kalshitools config show --jsonSee code: src/commands/config/show.ts
kalshitools help [COMMAND]
Display help for kalshitools.
USAGE
$ kalshitools help [COMMAND...] [-n]
ARGUMENTS
[COMMAND...] Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
Display help for kalshitools.See code: @oclif/plugin-help
kalshitools markets list
List prediction markets
USAGE
$ kalshitools markets list [--json] [--event-ticker <value>] [--limit <value>] [--series-ticker <value>]
[--status active|closed|settled|finalized] [--tickers <value>] [--with-nested]
FLAGS
--event-ticker=<value> Filter by event ticker
--json Output in JSON format
--limit=<value> [default: 20] Maximum number of markets to return
--series-ticker=<value> Filter by series ticker
--status=<option> Filter by market status
<options: active|closed|settled|finalized>
--tickers=<value> Comma-separated list of tickers to fetch
--with-nested Include nested markets
DESCRIPTION
List prediction markets
EXAMPLES
$ kalshitools markets list
$ kalshitools markets list --status active --limit 10
$ kalshitools markets list --event-ticker ELECTION-2024
$ kalshitools markets list --tickers "TICKER1,TICKER2,TICKER3"
$ kalshitools markets list --with-nested
$ kalshitools markets list --jsonSee code: src/commands/markets/list.ts
kalshitools markets orderbook TICKER
Show order book for a market
USAGE
$ kalshitools markets orderbook TICKER [--json] [--depth <value>]
ARGUMENTS
TICKER Market ticker symbol
FLAGS
--depth=<value> [default: 10] Number of price levels to show
--json Output in JSON format
DESCRIPTION
Show order book for a market
EXAMPLES
$ kalshitools markets orderbook TICKER
$ kalshitools markets orderbook TICKER --depth 5
$ kalshitools markets orderbook TICKER --jsonSee code: src/commands/markets/orderbook.ts
kalshitools markets scan
Scan markets for trading opportunities based on liquidity and spreads
USAGE
$ kalshitools markets scan [--json] [--depth <value>] [--event-ticker <value>] [--limit <value>] [--max-spread
<value>] [--min-liquidity <value>] [--min-spread <value>] [--min-volume <value>] [--series-ticker <value>]
[--sort-by liquidity|score|spread|volume]
FLAGS
--depth=<value> [default: 5] Orderbook depth to fetch for analysis
--event-ticker=<value> Filter to specific event
--json Output in JSON format
--limit=<value> [default: 50] Maximum markets to scan
--max-spread=<value> [default: 0.30] Maximum spread in cents (e.g., 0.30 = 30 cents)
--min-liquidity=<value> [default: 100] Minimum orderbook depth in dollars
--min-spread=<value> [default: 0.03] Minimum spread in cents (e.g., 0.03 = 3 cents)
--min-volume=<value> [default: 500] Minimum 24h volume in dollars
--series-ticker=<value> Filter to specific series
--sort-by=<option> [default: score] Ranking criteria
<options: liquidity|score|spread|volume>
DESCRIPTION
Scan markets for trading opportunities based on liquidity and spreads
EXAMPLES
$ kalshitools markets scan
$ kalshitools markets scan --min-liquidity 200 --min-spread 0.05
$ kalshitools markets scan --event-ticker EVENT-2024
$ kalshitools markets scan --sort-by liquidity --limit 20
$ kalshitools markets scan --jsonSee code: src/commands/markets/scan.ts
kalshitools markets show TICKER
Show market details
USAGE
$ kalshitools markets show TICKER [--json]
ARGUMENTS
TICKER Market ticker symbol
FLAGS
--json Output in JSON format
DESCRIPTION
Show market details
EXAMPLES
$ kalshitools markets show TICKER
$ kalshitools markets show TICKER --jsonSee code: src/commands/markets/show.ts
kalshitools orders cancel ORDERID
Cancel an order
USAGE
$ kalshitools orders cancel ORDERID [--json] [-y]
ARGUMENTS
ORDERID Order ID to cancel
FLAGS
-y, --yes Skip confirmation prompt
--json Output in JSON format
DESCRIPTION
Cancel an order
EXAMPLES
$ kalshitools orders cancel ORDER_ID
$ kalshitools orders cancel ORDER_ID --yes
$ kalshitools orders cancel ORDER_ID --jsonSee code: src/commands/orders/cancel.ts
kalshitools orders create
Create a new order (buy or sell contracts)
USAGE
$ kalshitools orders create -a buy|sell -q <value> -s yes|no -t <value> [--json] [--dry-run] [-p <value>] [--type
market|limit] [-y]
FLAGS
-a, --action=<option> (required) Order action (buy or sell)
<options: buy|sell>
-p, --price=<value> Limit price (required for limit orders, 0.01-0.99)
-q, --quantity=<value> (required) Number of contracts
-s, --side=<option> (required) Contract side (yes or no)
<options: yes|no>
-t, --ticker=<value> (required) Market ticker symbol
-y, --yes Skip confirmation prompt
--dry-run Simulate the order without actually placing it
--json Output in JSON format
--type=<option> [default: market] Order type (market or limit)
<options: market|limit>
DESCRIPTION
Create a new order (buy or sell contracts)
EXAMPLES
$ kalshitools orders create --ticker TICKER --action buy --side yes --quantity 10 --type market
$ kalshitools orders create --ticker TICKER --action buy --side yes --quantity 10 --type limit --price 0.65
$ kalshitools orders create --ticker TICKER --action sell --side no --quantity 5 --type market --yes
$ kalshitools orders create --ticker TICKER --action buy --side yes --quantity 100 --dry-runSee code: src/commands/orders/create.ts
kalshitools orders list
List orders
USAGE
$ kalshitools orders list [--json] [--limit <value>] [--status pending|resting|canceled|executed|expired]
[--ticker <value>]
FLAGS
--json Output in JSON format
--limit=<value> [default: 50] Maximum number of orders to return
--status=<option> Filter by order status
<options: pending|resting|canceled|executed|expired>
--ticker=<value> Filter by ticker
DESCRIPTION
List orders
EXAMPLES
$ kalshitools orders list
$ kalshitools orders list --status resting
$ kalshitools orders list --ticker TICKER
$ kalshitools orders list --jsonSee code: src/commands/orders/list.ts
kalshitools plugins
List installed plugins.
USAGE
$ kalshitools plugins [--json] [--core]
FLAGS
--core Show core plugins.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
List installed plugins.
EXAMPLES
$ kalshitools pluginsSee code: @oclif/plugin-plugins
kalshitools plugins add PLUGIN
Installs a plugin into kalshitools.
USAGE
$ kalshitools plugins add PLUGIN... [--json] [-f] [-h] [-s | -v]
ARGUMENTS
PLUGIN... Plugin to install.
FLAGS
-f, --force Force npm to fetch remote resources even if a local copy exists on disk.
-h, --help Show CLI help.
-s, --silent Silences npm output.
-v, --verbose Show verbose npm output.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Installs a plugin into kalshitools.
Uses npm to install plugins.
Installation of a user-installed plugin will override a core plugin.
Use the KALSHITOOLS_NPM_LOG_LEVEL environment variable to set the npm loglevel.
Use the KALSHITOOLS_NPM_REGISTRY environment variable to set the npm registry.
ALIASES
$ kalshitools plugins add
EXAMPLES
Install a plugin from npm registry.
$ kalshitools plugins add myplugin
Install a plugin from a github url.
$ kalshitools plugins add https://github.com/someuser/someplugin
Install a plugin from a github slug.
$ kalshitools plugins add someuser/somepluginkalshitools plugins:inspect PLUGIN...
Displays installation properties of a plugin.
USAGE
$ kalshitools plugins inspect PLUGIN...
ARGUMENTS
PLUGIN... [default: .] Plugin to inspect.
FLAGS
-h, --help Show CLI help.
-v, --verbose
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Displays installation properties of a plugin.
EXAMPLES
$ kalshitools plugins inspect mypluginSee code: @oclif/plugin-plugins
kalshitools plugins install PLUGIN
Installs a plugin into kalshitools.
USAGE
$ kalshitools plugins install PLUGIN... [--json] [-f] [-h] [-s | -v]
ARGUMENTS
PLUGIN... Plugin to install.
FLAGS
-f, --force Force npm to fetch remote resources even if a local copy exists on disk.
-h, --help Show CLI help.
-s, --silent Silences npm output.
-v, --verbose Show verbose npm output.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Installs a plugin into kalshitools.
Uses npm to install plugins.
Installation of a user-installed plugin will override a core plugin.
Use the KALSHITOOLS_NPM_LOG_LEVEL environment variable to set the npm loglevel.
Use the KALSHITOOLS_NPM_REGISTRY environment variable to set the npm registry.
ALIASES
$ kalshitools plugins add
EXAMPLES
Install a plugin from npm registry.
$ kalshitools plugins install myplugin
Install a plugin from a github url.
$ kalshitools plugins install https://github.com/someuser/someplugin
Install a plugin from a github slug.
$ kalshitools plugins install someuser/somepluginSee code: @oclif/plugin-plugins
kalshitools plugins link PATH
Links a plugin into the CLI for development.
USAGE
$ kalshitools plugins link PATH [-h] [--install] [-v]
ARGUMENTS
PATH [default: .] path to plugin
FLAGS
-h, --help Show CLI help.
-v, --verbose
--[no-]install Install dependencies after linking the plugin.
DESCRIPTION
Links a plugin into the CLI for development.
Installation of a linked plugin will override a user-installed or core plugin.
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
command will override the user-installed or core plugin implementation. This is useful for development work.
EXAMPLES
$ kalshitools plugins link mypluginSee code: @oclif/plugin-plugins
kalshitools plugins remove [PLUGIN]
Removes a plugin from the CLI.
USAGE
$ kalshitools plugins remove [PLUGIN...] [-h] [-v]
ARGUMENTS
[PLUGIN...] plugin to uninstall
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Removes a plugin from the CLI.
ALIASES
$ kalshitools plugins unlink
$ kalshitools plugins remove
EXAMPLES
$ kalshitools plugins remove mypluginkalshitools plugins reset
Remove all user-installed and linked plugins.
USAGE
$ kalshitools plugins reset [--hard] [--reinstall]
FLAGS
--hard Delete node_modules and package manager related files in addition to uninstalling plugins.
--reinstall Reinstall all plugins after uninstalling.See code: @oclif/plugin-plugins
kalshitools plugins uninstall [PLUGIN]
Removes a plugin from the CLI.
USAGE
$ kalshitools plugins uninstall [PLUGIN...] [-h] [-v]
ARGUMENTS
[PLUGIN...] plugin to uninstall
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Removes a plugin from the CLI.
ALIASES
$ kalshitools plugins unlink
$ kalshitools plugins remove
EXAMPLES
$ kalshitools plugins uninstall mypluginSee code: @oclif/plugin-plugins
kalshitools plugins unlink [PLUGIN]
Removes a plugin from the CLI.
USAGE
$ kalshitools plugins unlink [PLUGIN...] [-h] [-v]
ARGUMENTS
[PLUGIN...] plugin to uninstall
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Removes a plugin from the CLI.
ALIASES
$ kalshitools plugins unlink
$ kalshitools plugins remove
EXAMPLES
$ kalshitools plugins unlink mypluginkalshitools plugins update
Update installed plugins.
USAGE
$ kalshitools plugins update [-h] [-v]
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Update installed plugins.See code: @oclif/plugin-plugins
kalshitools portfolio analytics
Comprehensive portfolio performance analytics
USAGE
$ kalshitools portfolio analytics [--json] [--max-ts <value>] [--min-ts <value>] [--period <value>]
FLAGS
--json Output in JSON format
--max-ts=<value> End date for analysis (ISO-8601 format)
--min-ts=<value> Start date for analysis (ISO-8601 format)
--period=<value> Analysis period in days (overridden by min-ts/max-ts)
DESCRIPTION
Comprehensive portfolio performance analytics
EXAMPLES
$ kalshitools portfolio analytics
$ kalshitools portfolio analytics --period 7
$ kalshitools portfolio analytics --min-ts 2026-01-01T00:00:00Z
$ kalshitools portfolio analytics --jsonSee code: src/commands/portfolio/analytics.ts
kalshitools portfolio balance
View account balance
USAGE
$ kalshitools portfolio balance [--json]
FLAGS
--json Output in JSON format
DESCRIPTION
View account balance
EXAMPLES
$ kalshitools portfolio balance
$ kalshitools portfolio balance --jsonSee code: src/commands/portfolio/balance.ts
kalshitools portfolio fills
View trade history (fills)
USAGE
$ kalshitools portfolio fills [--json] [--limit <value>] [--ticker <value>]
FLAGS
--json Output in JSON format
--limit=<value> [default: 50] Maximum number of fills to return
--ticker=<value> Filter by ticker
DESCRIPTION
View trade history (fills)
EXAMPLES
$ kalshitools portfolio fills
$ kalshitools portfolio fills --ticker TICKER
$ kalshitools portfolio fills --limit 20
$ kalshitools portfolio fills --jsonSee code: src/commands/portfolio/fills.ts
kalshitools portfolio history
Historical performance analysis with time-series data
USAGE
$ kalshitools portfolio history [--json] [--group-by day|week|month] [--limit <value>] [--max-ts <value>] [--min-ts
<value>] [--ticker <value>]
FLAGS
--group-by=<option> [default: day] Time aggregation level
<options: day|week|month>
--json Output in JSON format
--limit=<value> [default: 500] Maximum fills to fetch (handles pagination)
--max-ts=<value> End date (ISO-8601 format)
--min-ts=<value> Start date (ISO-8601 format)
--ticker=<value> Filter by specific market ticker
DESCRIPTION
Historical performance analysis with time-series data
EXAMPLES
$ kalshitools portfolio history
$ kalshitools portfolio history --ticker MARKET-A
$ kalshitools portfolio history --group-by week
$ kalshitools portfolio history --min-ts 2026-01-01T00:00:00Z --max-ts 2026-02-01T00:00:00Z
$ kalshitools portfolio history --jsonSee code: src/commands/portfolio/history.ts
kalshitools portfolio positions
View current positions with P&L
USAGE
$ kalshitools portfolio positions [--json] [--settlement-status open|pending|settled]
FLAGS
--json Output in JSON format
--settlement-status=<option> Filter by settlement status
<options: open|pending|settled>
DESCRIPTION
View current positions with P&L
EXAMPLES
$ kalshitools portfolio positions
$ kalshitools portfolio positions --settlement-status open
$ kalshitools portfolio positions --settlement-status settled
$ kalshitools portfolio positions --jsonSee code: src/commands/portfolio/positions.ts
kalshitools portfolio risk
Real-time portfolio risk analysis and warnings
USAGE
$ kalshitools portfolio risk [--json] [--group-by event|series|ticker] [--threshold <value>]
FLAGS
--group-by=<option> [default: ticker] Grouping for concentration analysis
<options: event|series|ticker>
--json Output in JSON format
--threshold=<value> [default: 20] Alert threshold for position concentration (%)
DESCRIPTION
Real-time portfolio risk analysis and warnings
EXAMPLES
$ kalshitools portfolio risk
$ kalshitools portfolio risk --threshold 15
$ kalshitools portfolio risk --group-by event
$ kalshitools portfolio risk --jsonSee code: src/commands/portfolio/risk.ts
