Skip to main content

KalshiHttpClient

Struct KalshiHttpClient 

Source
pub struct KalshiHttpClient { /* private fields */ }
Expand description

REST transport for public discovery, account reports, and V2 order requests.

Public construction does not resolve credentials. Authenticated construction validates them before traffic. Safe reads retry transient failures twice at the adapter, acquiring quota before each fresh timestamp and signature. Redirects are never followed. Typed mutations use one adapter-owned attempt. Lower-level transport retries can replay the original signed request without entering adapter quota or signing. Callers reconcile uncertain or mismatched acknowledgements.

Implementations§

Source§

impl KalshiHttpClient

Source

pub fn new(config: &KalshiDataClientConfig) -> Result<Self>

Validates the data-client settings and creates the public transport.

Explicit proxies override direct routing. Ambient proxy variables are ignored.

§Errors

Returns an error if config validation or transport construction fails.

Source

pub fn new_authenticated(config: &KalshiDataClientConfig) -> Result<Self>

Creates an authenticated transport from explicit or selected-environment credentials.

§Errors

Returns an error if config, credentials, key encoding, or transport construction is invalid.

Source

pub fn new_authenticated_with_quota( config: &KalshiDataClientConfig, quota: Arc<KalshiQuota>, ) -> Result<Self>

Creates an authenticated transport using the supplied account quota owner.

Share one owner across data and execution clients, including distinct keys for the same account. A key already bound to another owner is rejected before traffic.

§Errors

Returns an error if settings or credentials are invalid, or quota ownership conflicts.

Source

pub fn new_with_quota( config: &KalshiDataClientConfig, quota: Arc<KalshiQuota>, ) -> Result<Self>

Creates a public data transport sharing an authenticated account’s quota.

§Errors

Returns an error if settings or transport construction is invalid.

Source

pub async fn refresh_quota(&self) -> Result<(), KalshiHttpError>

Refreshes authenticated limits and endpoint costs for the shared account owner.

Transports with credentials refresh lazily before ordinary traffic, including public reads. Fresh discovery or an active five-second fallback window returns without traffic. Failed discovery uses Basic read limits, one balance read per second, and a conservative 50-token read cost during the fallback window. Expiry uses those read budgets until refresh; writes wait for discovery and remain disabled if it fails. A subaccount-restricted key uses conservative Basic limits when the limits endpoint denies its scope; endpoint cost discovery remains required.

§Errors

Returns an error if endpoint costs are unavailable or invalid, or limit discovery fails without a recognized subaccount-restriction denial.

Source

pub async fn get_exchange_status(&self) -> Result<HttpResponse, HttpClientError>

Fetches the public exchange status without authentication.

Non-success HTTP statuses remain responses for the caller to inspect.

§Errors

Returns an error if the request fails or exceeds the configured timeout.

Source

pub async fn get_balance( &self, exchange_index: u32, ) -> Result<HttpResponse, KalshiHttpError>

Fetches the authenticated balance on an explicit exchange shard.

§Errors

Returns an error if authentication, quota admission, retries, or transport fails.

Source

pub fn cancel(&self)

Cancels typed REST requests on this client and its clones.

Cancellation after dispatch does not establish whether a mutation reached the venue.

Source

pub async fn get_status(&self) -> Result<ExchangeStatus, KalshiHttpError>

Fetches typed public exchange availability.

Documented maintenance responses (HTTP 500, 503, and 504) return their typed status body. Use Self::get_exchange_status when the HTTP status and response headers are required.

§Errors

Returns an error if transport, cancellation, status, or response decoding fails.

Source

pub async fn get_markets( &self, query: &MarketsQuery, ) -> Result<MarketsResponse, KalshiHttpError>

Fetches one live market discovery page.

§Errors

Returns an error if encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_market( &self, ticker: &str, ) -> Result<MarketResponse, KalshiHttpError>

Fetches one market by ticker.

§Errors

Returns an error if the ticker, transport, status, cancellation, or decoding is invalid.

Source

pub async fn get_historical_markets( &self, query: &HistoricalMarketsQuery, ) -> Result<MarketsResponse, KalshiHttpError>

Fetches one archived market discovery page.

§Errors

Returns an error if encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_historical_market( &self, ticker: &str, ) -> Result<MarketResponse, KalshiHttpError>

Fetches one archived market by ticker.

§Errors

Returns an error if the ticker, transport, status, cancellation, or decoding is invalid.

Source

pub async fn get_events( &self, query: &EventsQuery, ) -> Result<EventsResponse, KalshiHttpError>

Fetches one event discovery page.

§Errors

Returns an error if encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_event( &self, ticker: &str, query: &EventQuery, ) -> Result<EventResponse, KalshiHttpError>

Fetches one event and its markets.

§Errors

Returns an error if the ticker, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_series_list( &self, query: &SeriesQuery, ) -> Result<SeriesListResponse, KalshiHttpError>

Fetches series definitions.

§Errors

Returns an error if encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_series( &self, ticker: &str, ) -> Result<SeriesResponse, KalshiHttpError>

Fetches one series definition.

§Errors

Returns an error if the ticker, transport, cancellation, status, or decoding is invalid.

Source

pub async fn get_orderbook( &self, ticker: &str, depth: u32, ) -> Result<OrderbookResponse, KalshiHttpError>

Fetches exact YES and NO bid levels; zero depth requests all levels.

§Errors

Returns an error if depth exceeds 100, or transport, cancellation, status, or decoding fails.

Source

pub async fn get_trades( &self, query: &TradesQuery, ) -> Result<TradesResponse, KalshiHttpError>

Fetches one public trade page from the live tier.

§Errors

Returns an error if encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_historical_trades( &self, query: &TradesQuery, ) -> Result<TradesResponse, KalshiHttpError>

Fetches one public trade page from the archive.

§Errors

Returns an error if encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_candlesticks( &self, series: &str, ticker: &str, query: &CandlesticksQuery, ) -> Result<CandlesticksResponse, KalshiHttpError>

Fetches live market candles for a supported interval.

§Errors

Returns an error if the window, interval, transport, status, cancellation, or decoding fails.

Source

pub async fn get_historical_candlesticks( &self, ticker: &str, query: &CandlesticksQuery, ) -> Result<HistoricalCandlesticksResponse, KalshiHttpError>

Fetches archived market candles.

§Errors

Returns an error if the window, interval, transport, status, cancellation, or decoding fails.

Source

pub async fn get_historical_cutoff( &self, ) -> Result<HistoricalCutoff, KalshiHttpError>

Fetches each archive partition’s authoritative cutoff.

§Errors

Returns an error if transport, cancellation, status, or decoding fails.

Source

pub async fn get_account_balance( &self, query: &AccountQuery, ) -> Result<Balance, KalshiHttpError>

Fetches typed collateral for an explicit subaccount and exchange shard.

§Errors

Returns an error if scope, authentication, transport, cancellation, status, or decoding fails.

Source

pub async fn get_positions( &self, query: &PositionsQuery, ) -> Result<PositionsResponse, KalshiHttpError>

Fetches one live market/event position page.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_historical_positions( &self, query: &HistoricalPositionsQuery, ) -> Result<PositionsResponse, KalshiHttpError>

Fetches one archived market/event position page.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_fills( &self, query: &FillsQuery, ) -> Result<FillsResponse, KalshiHttpError>

Fetches one live fills page.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_historical_fills( &self, query: &HistoryQuery, ) -> Result<FillsResponse, KalshiHttpError>

Fetches one archived fills page.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_orders( &self, query: &OrdersQuery, ) -> Result<OrdersResponse, KalshiHttpError>

Fetches one live orders page.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_order( &self, order_id: &str, ) -> Result<OrderResponse, KalshiHttpError>

Fetches one order by its venue identity.

§Errors

Returns an error if identity, authentication, transport, cancellation, status, or decoding fails.

Source

pub async fn get_historical_orders( &self, query: &HistoryQuery, ) -> Result<OrdersResponse, KalshiHttpError>

Fetches one archived orders page.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_settlements( &self, query: &SettlementsQuery, ) -> Result<SettlementsResponse, KalshiHttpError>

Fetches one page of settlements still held in the live tier.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_account_limits(&self) -> Result<AccountLimits, KalshiHttpError>

Fetches token limits and updates the shared account quota owner.

§Errors

Returns an error if authentication, transport, cancellation, status, decoding, or quota validation fails.

Source

pub async fn get_endpoint_costs(&self) -> Result<EndpointCosts, KalshiHttpError>

Fetches endpoint token costs and updates the shared account quota owner.

§Errors

Returns an error if transport, cancellation, status, decoding, or quota validation fails.

Source

pub async fn create_order( &self, request: &CreateOrderRequest, ) -> Result<CreateOrderResponse, KalshiHttpError>

Sends one V2 limit-order request without replay.

§Errors

Returns an error if validation, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn batch_create_orders( &self, request: &BatchCreateRequest, ) -> Result<BatchCreateResponse, KalshiHttpError>

Sends independent V2 order requests once in one batch.

Each child requires a unique, non-empty client order identity. Reply identities must match.

§Errors

Returns an error if validation, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn amend_order( &self, order_id: &str, subaccount: u32, request: &AmendOrderRequest, ) -> Result<AmendOrderResponse, KalshiHttpError>

Sends a V2 amendment once. Expiration remains a raw protocol field.

Callers verify returned order and client identities, then obtain authoritative order reports.

§Errors

Returns an error if scope, values, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn decrease_order( &self, order_id: &str, subaccount: u32, request: &DecreaseOrderRequest, ) -> Result<DecreaseOrderResponse, KalshiHttpError>

Sends a V2 decrease once, using exactly one selector.

Callers verify returned order and client identities, then obtain authoritative order reports.

§Errors

Returns an error if scope, selectors, values, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn cancel_order( &self, order_id: &str, query: &AccountQuery, ) -> Result<CancelOrderResponse, KalshiHttpError>

Cancels one selected V2 order once on an explicit shard.

Callers verify returned order and client identities, then obtain authoritative order reports.

§Errors

Returns an error if scope, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn batch_cancel_orders( &self, request: &BatchCancelRequest, ) -> Result<BatchCancelResponse, KalshiHttpError>

Cancels only the explicitly selected V2 orders, without replay.

Selected order identities must be unique. Reply identities must match the selected set.

§Errors

Returns an error if scope, identities, authentication, encoding, transport, cancellation, status, or decoding fails.

Source

pub async fn get_all_markets( &self, query: MarketsQuery, max_pages: u32, ) -> Result<Pages<Market>, KalshiHttpError>

Collects live market pages with stable-ticker deduplication and a page budget.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_historical_markets( &self, query: HistoricalMarketsQuery, max_pages: u32, ) -> Result<Pages<Market>, KalshiHttpError>

Collects archived market pages with stable-ticker deduplication.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_events( &self, query: EventsQuery, max_pages: u32, ) -> Result<Pages<Event>, KalshiHttpError>

Collects event pages with stable-event-identity deduplication.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_trades( &self, query: TradesQuery, max_pages: u32, ) -> Result<Pages<Trade>, KalshiHttpError>

Collects live trades, deduplicating inclusive boundaries by trade identity.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_historical_trades( &self, query: TradesQuery, max_pages: u32, ) -> Result<Pages<Trade>, KalshiHttpError>

Collects archived trades with stable-trade-identity deduplication.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_fills( &self, query: FillsQuery, max_pages: u32, ) -> Result<Pages<Fill>, KalshiHttpError>

Collects live fills, deduplicating by shard and fill identity.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_historical_fills( &self, query: HistoryQuery, max_pages: u32, ) -> Result<Pages<Fill>, KalshiHttpError>

Collects archived fills, deduplicating by shard and fill identity.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_orders( &self, query: OrdersQuery, max_pages: u32, ) -> Result<Pages<Order>, KalshiHttpError>

Collects live order reports with stable-order-identity deduplication.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_historical_orders( &self, query: HistoryQuery, max_pages: u32, ) -> Result<Pages<Order>, KalshiHttpError>

Collects archived order reports with stable-order-identity deduplication.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_settlements( &self, query: SettlementsQuery, max_pages: u32, ) -> Result<Pages<Settlement>, KalshiHttpError>

Collects live settlement records with shard/ticker deduplication.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_positions( &self, query: PositionsQuery, max_pages: u32, ) -> Result<PositionPages, KalshiHttpError>

Collects live market and event positions without discarding either list.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source

pub async fn get_all_historical_positions( &self, query: HistoricalPositionsQuery, max_pages: u32, ) -> Result<PositionPages, KalshiHttpError>

Collects archived market and event positions; shard identity stays record-level.

§Errors

Returns an error if any source fails, the budget is zero, or pagination makes no progress.

Source§

impl KalshiHttpClient

Source

pub async fn get_trades_range( &self, query: TradesQuery, max_pages: u32, ) -> Result<Vec<Trade>, KalshiHttpError>

Collects a bounded trade window, oldest first with trade ID breaking timestamp ties.

The cutoff is read once. A window reaching it reads live pages before a full-window archive probe to cover a forward handoff between the reads. The venue does not promise an atomic snapshot across pages. limit is a page size, not a result limit.

§Errors

Returns an error if:

  • The query is invalid, unbounded, or resumed.
  • Pagination is incomplete, duplicates conflict, or records do not match.
  • Any source fails.
Source

pub async fn get_candlesticks_range( &self, market: &Market, series: &str, query: &CandlesticksQuery, ) -> Result<Vec<Candlestick>, KalshiHttpError>

Fetches native candles using market settlement time to select the archive partition.

The cutoff is read once. A settled market still in the live tier receives an archive probe after the live read to cover a forward handoff. Endpoint time bounds apply to candle end timestamps.

§Errors

Returns an error if:

  • Bounds or periods are invalid, or a finalized market has no settlement evidence.
  • Market identity does not match, candles conflict, or a source fails.

Trait Implementations§

Source§

impl Clone for KalshiHttpClient

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KalshiHttpClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more