marketdata

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package marketdata provides a read-only HTTP adapter for Kalshi public market-data endpoints. It is transport-only: no credentials are used or stored, all prices and quantities remain fixed-point strings, and every failure is surfaced as a typed error for the caller to decide on retries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Code

func Code(err error) string

Types

type CandleOptions

type CandleOptions struct {
	StartTS                  int64
	EndTS                    int64
	PeriodIntervalMinutes    int
	IncludeLatestBeforeStart bool
}

CandleOptions carries required candlestick window parameters.

type CandlesPage

type CandlesPage struct {
	Ticker        string        `json:"ticker"`
	PeriodMinutes int           `json:"period_interval_minutes"`
	Candlesticks  []Candlestick `json:"candlesticks"`
}

CandlesPage is the candlestick response with echo metadata.

type Candlestick

type Candlestick struct {
	EndPeriodTS int64  `json:"end_period_ts"`
	Price       *OHLC  `json:"price,omitempty"`
	YesBid      *OHLC  `json:"yes_bid,omitempty"`
	YesAsk      *OHLC  `json:"yes_ask,omitempty"`
	VolumeFP    string `json:"volume_fp,omitempty"`
	OpenIntFP   string `json:"open_interest_fp,omitempty"`
}

Candlestick is one OHLC bucket exactly as upstream emits it: prices are fixed-point dollar strings, volume/open interest are fixed-point strings. price may be nil when no trade printed during the period.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client performs unauthenticated GET requests against Kalshi public market-data endpoints.

func NewClient

func NewClient() *Client

NewClient returns a Client bound to the production Kalshi API host.

func NewClientWithBaseURL

func NewClientWithBaseURL(baseURL string, httpClient *http.Client) *Client

NewClientWithBaseURL is used by tests to point the client at a fixture server.

func (*Client) GetEventCandles

func (c *Client) GetEventCandles(ctx context.Context, seriesTicker, ticker string, opt CandleOptions) (*CandlesPage, error)

GetEventCandles fetches candlesticks for an event-contract market. seriesTicker is the market's parent series (upstream path component).

func (*Client) GetEventLastQuote

func (c *Client) GetEventLastQuote(ctx context.Context, ticker string) (*LastQuote, error)

GetEventLastQuote fetches the compact live pricing snapshot for one event-contract market via GET /markets/{ticker}.

func (*Client) GetEventMarket

func (c *Client) GetEventMarket(ctx context.Context, ticker string) (json.RawMessage, error)

GetEventMarket returns authoritative metadata for one event-contract market as raw JSON (schema-faithful; no lossy re-typing).

func (*Client) GetEventOrderbook

func (c *Client) GetEventOrderbook(ctx context.Context, ticker string, depth int) (*Orderbook, error)

GetEventOrderbook fetches the order book for an event-contract market. Depth 0 means upstream default.

func (*Client) GetEventTrades

func (c *Client) GetEventTrades(ctx context.Context, opt TradesOptions) (*TradesPage, error)

GetEventTrades fetches one page of the public event-contract trade tape.

func (*Client) GetMarginCandles

func (c *Client) GetMarginCandles(ctx context.Context, ticker string, opt CandleOptions) (*CandlesPage, error)

GetMarginCandles fetches candlesticks for a perpetuals market.

func (*Client) GetMarginLastQuote

func (c *Client) GetMarginLastQuote(ctx context.Context, ticker string) (*LastQuote, error)

GetMarginLastQuote fetches the compact live pricing snapshot for one perpetuals market via GET /margin/markets.

func (*Client) GetMarginMarket

func (c *Client) GetMarginMarket(ctx context.Context, ticker string) (json.RawMessage, error)

GetMarginMarket returns authoritative metadata for one perpetuals market.

func (*Client) GetMarginOrderbook

func (c *Client) GetMarginOrderbook(ctx context.Context, ticker string, depth int) (*Orderbook, error)

GetMarginOrderbook fetches the order book for a perpetuals market.

func (*Client) GetWeatherIndex

func (c *Client) GetWeatherIndex(ctx context.Context, city string, from, to, lastSec *int64, detailed bool) (*WeatherIndex, error)

GetWeatherIndex fetches the Kalshi-computed city temperature index via GET /live_data/weather/{city}. Exactly one of lastSec or the from/to pair may be supplied; from without to (or vice versa) is invalid.

func (*Client) SearchEventMarkets

func (c *Client) SearchEventMarkets(ctx context.Context, opt SearchOptions) (*MarketsPage, error)

SearchEventMarkets fetches one page of event-contract markets.

func (*Client) SearchMarginMarkets

func (c *Client) SearchMarginMarkets(ctx context.Context, opt SearchOptions) (*MarketsPage, error)

SearchMarginMarkets fetches one page of perpetuals markets.

type LastQuote

type LastQuote struct {
	Ticker string `json:"ticker"`
	Status string `json:"status,omitempty"`

	// Event-contract fields (empty for perps).
	LastPriceDollars string `json:"last_price_dollars,omitempty"`
	YesBidDollars    string `json:"yes_bid_dollars,omitempty"`
	YesAskDollars    string `json:"yes_ask_dollars,omitempty"`
	YesBidSizeFP     string `json:"yes_bid_size_fp,omitempty"`
	YesAskSizeFP     string `json:"yes_ask_size_fp,omitempty"`
	NoBidDollars     string `json:"no_bid_dollars,omitempty"`
	NoAskDollars     string `json:"no_ask_dollars,omitempty"`

	// Perpetuals fields (empty for event contracts).
	MarkPriceDollars       string `json:"mark_price_dollars,omitempty"`
	BidDollars             string `json:"bid_dollars,omitempty"`
	AskDollars             string `json:"ask_dollars,omitempty"`
	SettlementMarkDollars  string `json:"settlement_mark_price_dollars,omitempty"`
	LiquidationMarkDollars string `json:"liquidation_mark_price_dollars,omitempty"`

	Volume24hFP string `json:"volume_24h_fp,omitempty"`
}

LastQuote is a compact live pricing snapshot for one market. Every price/size field is the fixed-point string exactly as upstream emits it.

type MarketSummary

type MarketSummary struct {
	Ticker         string `json:"ticker"`
	EventTicker    string `json:"event_ticker,omitempty"`
	SeriesTicker   string `json:"series_ticker,omitempty"`
	Title          string `json:"title,omitempty"`
	YesSubTitle    string `json:"yes_sub_title,omitempty"`
	Status         string `json:"status,omitempty"`
	YesBidDollars  string `json:"yes_bid_dollars,omitempty"`
	YesAskDollars  string `json:"yes_ask_dollars,omitempty"`
	VolumeFP       string `json:"volume_fp,omitempty"`
	OpenInterestFP string `json:"open_interest_fp,omitempty"`
	CloseTime      string `json:"close_time,omitempty"`
}

MarketSummary is a compact projection of an event-contract market, sized for agent context budgets. Prices and sizes stay fixed-point strings exactly as upstream emits them.

type MarketsPage

type MarketsPage struct {
	Markets []MarketSummary `json:"markets"`
	Cursor  string          `json:"cursor,omitempty"`
}

MarketsPage is one page of search results with the passthrough cursor.

type OHLC

type OHLC struct {
	OpenDollars  *string `json:"open_dollars,omitempty"`
	HighDollars  *string `json:"high_dollars,omitempty"`
	LowDollars   *string `json:"low_dollars,omitempty"`
	CloseDollars *string `json:"close_dollars,omitempty"`
}

OHLC is an open/high/low/close distribution of fixed-point dollar strings. Traded-price distributions may be null when no trade occurred in the bucket; quote (bid/ask) distributions are required by upstream.

type Orderbook

type Orderbook struct {
	Yes []PriceLevel `json:"yes_dollars"`
	No  []PriceLevel `json:"no_dollars"`
}

Orderbook keeps both sides exactly as upstream emits them: yes bids and no bids only (a yes ask is a bid on the no side).

type PriceLevel

type PriceLevel []string

PriceLevel is [dollars_string, fp_count] verbatim from upstream.

type SearchOptions

type SearchOptions struct {
	Tickers      []string
	EventTicker  string
	SeriesTicker string
	Status       string
	Limit        int
	Cursor       string
}

SearchOptions maps curated search_markets filters onto upstream query parameters. Tickers joins into the upstream comma-separated form.

type Trade

type Trade struct {
	Ticker       string `json:"ticker"`
	PriceDollars string `json:"yes_price_dollars,omitempty"`
	CountFP      string `json:"count_fp,omitempty"`
	TradedAt     string `json:"created_time,omitempty"`
	IsBlockTrade *bool  `json:"is_block_trade,omitempty"`
	TradeID      string `json:"trade_id,omitempty"`
}

Trade is one public print on the tape, verbatim fixed-point strings.

type TradesOptions

type TradesOptions struct {
	Ticker       string
	MinTS        int64
	MaxTS        int64
	Limit        int
	Cursor       string
	IsBlockTrade *bool
}

TradesOptions maps curated get_trades filters onto upstream parameters.

type TradesPage

type TradesPage struct {
	Trades []Trade `json:"trades"`
	Cursor string  `json:"cursor,omitempty"`
}

TradesPage is one page of the trade tape with passthrough cursor.

type WeatherIndex

type WeatherIndex struct {
	City          string              `json:"city"`
	ConfigVersion string              `json:"config_version,omitempty"`
	Units         string              `json:"units"`
	Timeseries    []WeatherIndexPoint `json:"timeseries"`
}

WeatherIndex is the Kalshi-computed city temperature index response.

type WeatherIndexPoint

type WeatherIndexPoint struct {
	T            int64                        `json:"t"`
	V            *fixedPoint                  `json:"v,omitempty"`
	Status       string                       `json:"status"`
	Contributors *int                         `json:"contributors,omitempty"`
	Stations     []WeatherIndexStationReading `json:"stations,omitempty"`
}

WeatherIndexPoint is one minute of the city temperature index. v and contributors are nil on `incomplete` points, which have no canonical value and no contributor count — they are returned as points but never zero-filled. Minutes where quorum failed carry no point at all.

type WeatherIndexStationReading

type WeatherIndexStationReading struct {
	StationID string      `json:"station_id"`
	Code      string      `json:"code"`
	Source    *string     `json:"source,omitempty"`
	TempF     *fixedPoint `json:"temp_f,omitempty"`
}

WeatherIndexStationReading is one member station's reported reading and QC disposition, exactly as upstream emits it (only with detailed=true). temp_f/source are nil: absent members carry no reading.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL