Expand description
Kalshi Trading API Client for Rust.
This crate provides an async client for the Kalshi trading API, including both REST endpoints and WebSocket streaming.
§Quick Start
ⓘ
use kalshi_trade_rs::{cents_to_dollars, KalshiClient, KalshiConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration from environment variables
let config = KalshiConfig::from_env()?;
// Create the client
let client = KalshiClient::new(config)?;
// Get account balance
let balance = client.get_balance().await?;
println!("Balance: ${:.2}", cents_to_dollars(balance.balance));
// Get positions
let positions = client.get_positions().await?;
for pos in positions.market_positions {
println!("{}: {} contracts", pos.ticker, pos.position);
}
Ok(())
}§Environment Variables
The following environment variables are used for configuration:
KALSHI_ENV: Either “demo” or “prod” (default: “demo”)KALSHI_API_KEY_ID: Your API key IDKALSHI_PRIVATE_KEY_PATH: Path to your RSA private key PEM file
Re-exports§
pub use auth::KalshiConfig;pub use client::Environment;pub use client::HttpClient;pub use client::KalshiClient;pub use error::DisconnectReason;pub use error::Error;pub use error::MAX_BATCH_SIZE;pub use error::Result;pub use models::AcceptQuoteRequest;pub use models::Action;pub use models::AmendOrderRequest;pub use models::AmendOrderResponse;pub use models::Announcement;pub use models::AnnouncementStatus;pub use models::AnnouncementType;pub use models::ApiKey;pub use models::ApiKeysResponse;pub use models::BalanceResponse;pub use models::BatchCancelOrderResult;pub use models::BatchCancelOrdersRequest;pub use models::BatchCancelOrdersResponse;pub use models::BatchCandlesticksResponse;pub use models::BatchCreateOrdersRequest;pub use models::BatchCreateOrdersResponse;pub use models::BatchLiveDataResponse;pub use models::BatchOrderError;pub use models::BatchOrderResult;pub use models::CancelOrderResponse;pub use models::Candlestick;pub use models::CandlestickPeriod;pub use models::CandlesticksResponse;pub use models::CommunicationsIdResponse;pub use models::CompetitionFilter;pub use models::CreateApiKeyRequest;pub use models::CreateApiKeyResponse;pub use models::CreateOrderGroupRequest;pub use models::CreateOrderGroupResponse;pub use models::CreateOrderRequest;pub use models::CreateQuoteRequest;pub use models::CreateRfqRequest;pub use models::DecreaseOrderRequest;pub use models::DeleteApiKeyResponse;pub use models::Event;pub use models::EventPosition;pub use models::EventResponse;pub use models::EventStatus;pub use models::EventsResponse;pub use models::ExchangeAnnouncementsResponse;pub use models::ExchangeSchedule;pub use models::ExchangeScheduleResponse;pub use models::ExchangeStatusResponse;pub use models::FeeChangesResponse;pub use models::FeeType;pub use models::Fill;pub use models::FillsResponse;pub use models::FiltersBySportResponse;pub use models::GenerateApiKeyRequest;pub use models::GenerateApiKeyResponse;pub use models::GetBatchCandlesticksParams;pub use models::GetBatchLiveDataParams;pub use models::GetCandlesticksParams;pub use models::GetEventParams;pub use models::GetEventsParams;pub use models::GetFcmOrdersParams;pub use models::GetFcmPositionsParams;pub use models::GetFeeChangesParams;pub use models::GetFillsParams;pub use models::GetIncentiveProgramsParams;pub use models::GetMarketsParams;pub use models::GetMilestonesParams;pub use models::GetOrderGroupResponse;pub use models::GetOrderGroupsParams;pub use models::GetOrderbookParams;pub use models::GetOrdersParams;pub use models::GetPositionsParams;pub use models::GetQueuePositionsParams;pub use models::GetQuoteResponse;pub use models::GetRfqResponse;pub use models::GetSeriesParams;pub use models::GetSettlementsParams;pub use models::GetStructuredTargetsParams;pub use models::GetTradesParams;pub use models::IncentiveProgram;pub use models::IncentiveProgramsResponse;pub use models::ListQuotesParams;pub use models::ListQuotesResponse;pub use models::ListRfqsParams;pub use models::ListRfqsResponse;pub use models::LiveData;pub use models::LiveDataResponse;pub use models::MaintenanceWindow;pub use models::Market;pub use models::MarketCandlesticks;pub use models::MarketFilterStatus;pub use models::MarketPosition;pub use models::MarketResponse;pub use models::MarketResult;pub use models::MarketStatus;pub use models::MarketType;pub use models::MarketsResponse;pub use models::Milestone;pub use models::MilestoneInfo;pub use models::MilestoneResponse;pub use models::MilestonesResponse;pub use models::MveFilter;pub use models::OhlcData;pub use models::Order;pub use models::OrderGroupSummary;pub use models::OrderGroupsResponse;pub use models::OrderQueuePositionResponse;pub use models::OrderResponse;pub use models::OrderStatus;pub use models::OrderType;pub use models::Orderbook;pub use models::OrderbookResponse;pub use models::OrdersResponse;pub use models::PositionsResponse;pub use models::PriceLevelDollars;pub use models::PriceOhlcData;pub use models::PriceRange;pub use models::QueuePosition;pub use models::QueuePositionsResponse;pub use models::Quote;pub use models::QuoteResponse;pub use models::Rfq;pub use models::RfqResponse;pub use models::SelfTradePreventionType;pub use models::Series;pub use models::SeriesFeeChange;pub use models::SeriesListResponse;pub use models::SeriesResponse;pub use models::Settlement;pub use models::SettlementStatus;pub use models::SettlementsResponse;pub use models::Side;pub use models::SportFilter;pub use models::StandardHoursPeriod;pub use models::StrikeType;pub use models::StructuredTarget;pub use models::StructuredTargetResponse;pub use models::StructuredTargetsResponse;pub use models::TagsByCategoriesResponse;pub use models::TakerSide;pub use models::TimeInForce;pub use models::Trade;pub use models::TradesResponse;pub use models::TradingSession;pub use models::UserDataTimestampResponse;pub use models::cents_to_dollars;pub use ws::Channel;pub use ws::ConnectStrategy;pub use ws::KalshiStreamClient;pub use ws::KalshiStreamHandle;pub use ws::StreamMessage;pub use ws::StreamUpdate;pub use ws::SubscribeResult;pub use batch::AggregatedCancelResponse;pub use batch::AggregatedCreateResponse;pub use batch::BatchManager;pub use batch::BatchManagerBuilder;pub use batch::BatchOperationResult;pub use batch::RateLimitTier;pub use batch::RetryConfig;