api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(resp *http.Response) error

CheckResponse checks the API response for errors. If the response status code indicates an error (>= 400), it parses the error body and returns an APIError. Otherwise, returns nil.

func DecodeJSON

func DecodeJSON(resp *http.Response, target interface{}) error

DecodeJSON decodes a JSON response body into the given target.

func GetAuthToken

func GetAuthToken(store keyring.Store, baseURL string, forceRefresh bool) (string, error)

GetAuthToken retrieves a valid auth token using the keyring store. It handles secret retrieval, token exchange, and caching. If forceRefresh is true, it ignores any cached token.

Types

type APIError

type APIError struct {
	StatusCode int
	Code       string
	Message    string
}

APIError represents an error response from the Public.com API.

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) IsForbidden

func (e *APIError) IsForbidden() bool

IsForbidden returns true if the error is a 403 Forbidden.

func (*APIError) IsNotFound

func (e *APIError) IsNotFound() bool

IsNotFound returns true if the error is a 404 Not Found.

func (*APIError) IsUnauthorized

func (e *APIError) IsUnauthorized() bool

IsUnauthorized returns true if the error is a 401 Unauthorized.

type Account

type Account = publicapi.Account

type AccountsResponse

type AccountsResponse = publicapi.AccountsResponse

type BuyingPower

type BuyingPower = publicapi.BuyingPower

type Client

type Client struct {
	BaseURL        string
	AuthToken      string
	HTTPClient     *http.Client
	TokenRefresher TokenRefresher // Optional: called on 401 to get fresh token
}

Client handles HTTP requests to the Public.com API.

func NewClient

func NewClient(baseURL, authToken string) *Client

NewClient creates a new API client with the given base URL and auth token.

func NewClientWithAuth

func NewClientWithAuth(store keyring.Store, baseURL string) (*Client, error)

NewClientWithAuth creates a new API client with automatic token retrieval. It fetches the auth token using the provided keyring store and base URL.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) (*http.Response, error)

Delete performs a DELETE request to the specified path.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)

Get performs a GET request to the specified path.

func (*Client) GetInstrument

func (c *Client) GetInstrument(ctx context.Context, symbol, instType string) (*InstrumentResponse, error)

GetInstrument retrieves trading details for a single instrument.

func (*Client) GetOptionChain

func (c *Client) GetOptionChain(ctx context.Context, accountID, symbol, expiration string) (*OptionChainResponse, error)

GetOptionChain retrieves the option chain for a symbol and expiration date.

func (*Client) GetOptionExpirations

func (c *Client) GetOptionExpirations(ctx context.Context, accountID, symbol string) (*OptionExpirationsResponse, error)

GetOptionExpirations retrieves available option expiration dates for a symbol.

func (*Client) GetOptionGreeks

func (c *Client) GetOptionGreeks(ctx context.Context, accountID string, osiSymbols []string) (*GreeksResponse, error)

GetOptionGreeks retrieves greeks for the given OSI option symbols.

func (*Client) GetPortfolio

func (c *Client) GetPortfolio(ctx context.Context, accountID string) (*Portfolio, error)

GetPortfolio retrieves the portfolio for the given account ID.

func (*Client) GetQuotes

func (c *Client) GetQuotes(ctx context.Context, accountID string, instruments []QuoteInstrument) ([]Quote, error)

GetQuotes retrieves quotes for the given instruments.

func (*Client) GetWithParams

func (c *Client) GetWithParams(ctx context.Context, path string, params map[string]string) (*http.Response, error)

GetWithParams performs a GET request to the specified path with query parameters.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body io.Reader) (*http.Response, error)

Post performs a POST request to the specified path with the given body.

func (*Client) WithTokenRefresher

func (c *Client) WithTokenRefresher(refresher TokenRefresher) *Client

WithTokenRefresher sets a token refresher function that will be called on 401.

type CostBasis

type CostBasis = publicapi.CostBasis

type Equity

type Equity = publicapi.Equity

type Gain

type Gain = publicapi.Gain

type GreeksData

type GreeksData = publicapi.GreeksData

type GreeksResponse

type GreeksResponse = publicapi.GreeksResponse

type HistoryResponse

type HistoryResponse = publicapi.HistoryResponse

type Instrument

type Instrument = publicapi.Instrument

type InstrumentIdentifier

type InstrumentIdentifier = publicapi.InstrumentIdentifier

type InstrumentResponse

type InstrumentResponse = publicapi.InstrumentResponse

type InstrumentsResponse added in v0.5.0

type InstrumentsResponse = publicapi.InstrumentsResponse

type MultilegExpiration added in v0.5.0

type MultilegExpiration = publicapi.MultilegExpiration

type MultilegInstrument added in v0.5.0

type MultilegInstrument = publicapi.MultilegInstrument

type MultilegLeg added in v0.5.0

type MultilegLeg = publicapi.MultilegLeg

type MultilegOrderRequest added in v0.5.0

type MultilegOrderRequest = publicapi.MultilegOrderRequest

type MultilegOrderResponse added in v0.5.0

type MultilegOrderResponse = publicapi.MultilegOrderResponse

type MultilegPreflightLeg added in v0.5.0

type MultilegPreflightLeg = publicapi.MultilegPreflightLeg

type MultilegPreflightRequest added in v0.5.0

type MultilegPreflightRequest = publicapi.MultilegPreflightRequest

type MultilegPreflightResponse added in v0.5.0

type MultilegPreflightResponse = publicapi.MultilegPreflightResponse

type MultilegPriceIncrement added in v0.5.0

type MultilegPriceIncrement = publicapi.MultilegPriceIncrement

type MultilegRegulatoryFees added in v0.5.0

type MultilegRegulatoryFees = publicapi.MultilegRegulatoryFees

type OptionChainRequest

type OptionChainRequest = publicapi.OptionChainRequest

type OptionChainResponse

type OptionChainResponse = publicapi.OptionChainResponse

type OptionExpirationsRequest

type OptionExpirationsRequest = publicapi.OptionExpirationsRequest

type OptionExpirationsResponse

type OptionExpirationsResponse = publicapi.OptionExpirationsResponse

type OptionGreeks

type OptionGreeks = publicapi.OptionGreeks

type OptionInstrument

type OptionInstrument = publicapi.OptionInstrument

type OptionQuote

type OptionQuote = publicapi.OptionQuote

type OptionsOrderRequest added in v0.4.0

type OptionsOrderRequest = publicapi.OptionsOrderRequest

type OptionsPreflightRequest added in v0.4.0

type OptionsPreflightRequest = publicapi.OptionsPreflightRequest

type OptionsPreflightResponse added in v0.4.0

type OptionsPreflightResponse = publicapi.OptionsPreflightResponse

type OptionsRegulatoryFees added in v0.4.0

type OptionsRegulatoryFees = publicapi.OptionsRegulatoryFees

type Order

type Order = publicapi.Order

type OrderExpiration

type OrderExpiration = publicapi.OrderExpiration

type OrderInstrument

type OrderInstrument = publicapi.OrderInstrument

type OrderListResponse

type OrderListResponse = publicapi.OrderListResponse

type OrderRequest

type OrderRequest = publicapi.OrderRequest

type OrderResponse

type OrderResponse = publicapi.OrderResponse

type OrderStatusResponse

type OrderStatusResponse = publicapi.OrderStatusResponse

type OrdersResponse

type OrdersResponse = publicapi.OrdersResponse

type Portfolio

type Portfolio = publicapi.Portfolio

type Position

type Position = publicapi.Position

type PreflightRequest

type PreflightRequest = publicapi.PreflightRequest

type PreflightResponse

type PreflightResponse = publicapi.PreflightResponse

type Price

type Price = publicapi.Price

type Quote

type Quote = publicapi.Quote

type QuoteInstrument

type QuoteInstrument = publicapi.QuoteInstrument

type QuoteRequest

type QuoteRequest = publicapi.QuoteRequest

type QuotesResponse

type QuotesResponse = publicapi.QuotesResponse

type RegulatoryFees

type RegulatoryFees = publicapi.RegulatoryFees

type TokenRefresher

type TokenRefresher func() (string, error)

TokenRefresher is a function that returns a fresh auth token. It's called when the API returns 401 Unauthorized.

type Transaction

type Transaction = publicapi.Transaction

Jump to

Keyboard shortcuts

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