api

package
v4.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BasicAuth = iota
	HeaderAuth
)
View Source
const (
	EnvApiKeyID     = "APCA_API_KEY_ID"
	EnvApiSecretKey = "APCA_API_SECRET_KEY"
	EnvAuthMethod   = "APCA_API_AUTH_METHOD"
	EnvApiOAuth     = "APCA_API_OAUTH"
	EnvPolygonKeyID = "POLY_API_KEY_ID"
)

Variables

View Source
var (
	// DefaultClient is the default Alpaca client using the
	// environment variable set credentials.
	DefaultClient = NewClient(Credentials())
)

Functions

func SetBaseUrl

func SetBaseUrl(baseUrl string)

Types

type APIError

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

APIError wraps the detailed code and message supplied by Alpaca's API for debugging purposes.

func (*APIError) Error

func (e *APIError) Error() string

type APIKey

type APIKey struct {
	ID           string
	Secret       string
	OAuth        string
	PolygonKeyID string
	AuthMethod   AuthMethod
}

func Credentials

func Credentials() *APIKey

Credentials returns the user's Alpaca API key ID and secret for use through the SDK.

type Adjustment added in v4.1.16

type Adjustment string

Adjustment specifies the corporate action adjustment(s) for the bars

const (
	Raw      Adjustment = "raw"
	Split    Adjustment = "split"
	Dividend Adjustment = "dividend"
	All      Adjustment = "all"
)

List of adjustments

type AuthMethod added in v4.1.21

type AuthMethod int

func AuthMethodFromString added in v4.1.21

func AuthMethodFromString(s string) AuthMethod

type Bar

type Bar struct {
	Timestamp  time.Time `json:"t"`
	Open       float64   `json:"o"`
	High       float64   `json:"h"`
	Low        float64   `json:"l"`
	Close      float64   `json:"c"`
	Volume     uint64    `json:"v"`
	TradeCount uint64    `json:"n"`
	VWAP       float64   `json:"vw"`
}

Bar is an aggregate of trades

type Client

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

Client is an Alpaca REST API client.

func NewClient

func NewClient(credentials *APIKey) *Client

NewClient creates a new Alpaca client with specified credentials.

func (*Client) GetMultiBars added in v4.1.16

func (c *Client) GetMultiBars(
	symbols []string, params GetBarsParams,
) (map[string][]Bar, error)

GetMultiBars returns bars for the given symbols.

func (*Client) GetMultiBarsAsync added in v4.1.16

func (c *Client) GetMultiBarsAsync(symbols []string, params GetBarsParams) <-chan MultiBarItem

GetMultiBarsAsync returns a channel that will be populated with the bars for the requested symbols.

func (*Client) GetSnapshots

func (c *Client) GetSnapshots(symbols []string) (map[string]*Snapshot, error)

GetSnapshots returns the snapshots for multiple symbol.

func (*Client) ListAssets

func (c *Client) ListAssets(status *string) ([]v1.Asset, error)

ListAssets returns the list of assets, filtered by the input parameters.

type GetBarsParams added in v4.1.16

type GetBarsParams struct {
	// TimeFrame is the aggregation size of the bars
	TimeFrame TimeFrame
	// Adjustment tells if the bars should be adjusted for corporate actions
	Adjustment Adjustment
	// Start is the inclusive beginning of the interval
	Start time.Time
	// End is the inclusive end of the interval
	End time.Time
	// TotalLimit is the limit of the total number of the returned bars.
	// If missing, all bars between start end end will be returned.
	TotalLimit int
	// PageLimit is the pagination size. If empty, the default page size will be used.
	PageLimit int
	// Feed is the source of the data: sip or iex.
	// If provided, it overrides the client's Feed option.
	Feed string
}

GetBarsParams contains optional parameters for getting bars

type MultiBarItem added in v4.1.16

type MultiBarItem struct {
	Symbol string
	Bar    Bar
	Error  error
}

MultiBarItem contains a single bar for a symbol or an error

type Quote

type Quote struct {
	BidExchange string    `json:"bx"`
	BidPrice    float64   `json:"bp"`
	BidSize     uint32    `json:"bs"`
	AskExchange string    `json:"ax"`
	AskPrice    float64   `json:"ap"`
	AskSize     uint32    `json:"as"`
	Timestamp   time.Time `json:"t"`
	Conditions  []string  `json:"c"`
	Tape        string    `json:"z"`
}

Quote is a stock quote from the market.

type Snapshot

type Snapshot struct {
	LatestTrade  *Trade `json:"latestTrade"`
	LatestQuote  *Quote `json:"latestQuote"`
	MinuteBar    *Bar   `json:"minuteBar"`
	DailyBar     *Bar   `json:"dailyBar"`
	PrevDailyBar *Bar   `json:"prevDailyBar"`
}

Snapshot is a snapshot of a symbol.

type TimeFrame added in v4.1.16

type TimeFrame struct {
	N    int
	Unit TimeFrameUnit
}

TimeFrame is the resolution of the bars

var (
	OneMin  TimeFrame = NewTimeFrame(1, Min)
	OneHour TimeFrame = NewTimeFrame(1, Hour)
	OneDay  TimeFrame = NewTimeFrame(1, Day)
)

func NewTimeFrame added in v4.1.16

func NewTimeFrame(n int, unit TimeFrameUnit) TimeFrame

func (TimeFrame) String added in v4.1.16

func (tf TimeFrame) String() string

type TimeFrameUnit added in v4.1.16

type TimeFrameUnit string

TimeFrameUnite is the base unit of the timeframe.

const (
	Min  TimeFrameUnit = "Min"
	Hour TimeFrameUnit = "Hour"
	Day  TimeFrameUnit = "Day"
)

List of timeframe units

type Trade

type Trade struct {
	ID         int64     `json:"i"`
	Exchange   string    `json:"x"`
	Price      float64   `json:"p"`
	Size       uint32    `json:"s"`
	Timestamp  time.Time `json:"t"`
	Conditions []string  `json:"c"`
	Tape       string    `json:"z"`
}

Trade is a stock trade that happened on the market.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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