alpaca

package
v3.7.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = NewClient(ClientOpts{})

DefaultClient uses options from environment variables, or the defaults.

View Source
var ErrSymbolMissing = errors.New("symbol missing from request")

Functions

func APIErrorFromResponse

func APIErrorFromResponse(resp *http.Response) error

func CancelAllOrders

func CancelAllOrders() error

CancelAllOrders submits a request to cancel all orders.

func CancelOrder

func CancelOrder(orderID string) error

CancelOrder submits a request to cancel an open order.

func DeleteWatchlist

func DeleteWatchlist(watchlistID string) error

DeleteWatchlist deletes a watchlist by getting the watchlist id with the default Alpaca client.

func RemoveSymbolFromWatchlist

func RemoveSymbolFromWatchlist(watchlistID string, req RemoveSymbolFromWatchlistRequest) error

RemoveSymbolFromWatchlist removes an asset from a watchlist by getting the watchlist id with the default Alpaca client.

func RoundLimitPrice

func RoundLimitPrice(price decimal.Decimal, side Side) *decimal.Decimal

RoundLimitPrice calculates the limit price that respects the minimum price variance rule.

Orders received in excess of the minimum price variance will be rejected.

Limit price >= $1.00: Max Decimals = 2
Limit price <  $1.00: Max Decimals = 4

https://docs.alpaca.markets/docs/orders-at-alpaca#sub-penny-increments-for-limit-orders

func StreamTradeUpdates

func StreamTradeUpdates(ctx context.Context, handler func(TradeUpdate), req StreamTradeUpdatesRequest) error

StreamTradeUpdates streams the trade updates of the account. It blocks and keeps calling the handler function for each trade update until the context is cancelled.

func StreamTradeUpdatesInBackground

func StreamTradeUpdatesInBackground(ctx context.Context, handler func(TradeUpdate))

StreamTradeUpdatesInBackground streams the trade updates of the account. It runs in the background and keeps calling the handler function for each trade update until the context is cancelled. If an error happens it logs it and retries immediately.

func Version

func Version() string

Version returns a string contains alpaca-trade-api-go dep version and go runtime version

Types

type APIError

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

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

func (*APIError) Error

func (e *APIError) Error() string

func (APIError) MarshalEasyJSON

func (v APIError) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (APIError) MarshalJSON

func (v APIError) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*APIError) UnmarshalEasyJSON

func (v *APIError) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*APIError) UnmarshalJSON

func (v *APIError) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Account

type Account struct {
	ID                    string          `json:"id"`
	AccountNumber         string          `json:"account_number"`
	Status                string          `json:"status"`
	CryptoStatus          string          `json:"crypto_status"`
	Currency              string          `json:"currency"`
	BuyingPower           decimal.Decimal `json:"buying_power"`
	RegTBuyingPower       decimal.Decimal `json:"regt_buying_power"`
	DaytradingBuyingPower decimal.Decimal `json:"daytrading_buying_power"`
	EffectiveBuyingPower  decimal.Decimal `json:"effective_buying_power"`
	NonMarginBuyingPower  decimal.Decimal `json:"non_marginable_buying_power"`
	BodDtbp               decimal.Decimal `json:"bod_dtbp"`
	Cash                  decimal.Decimal `json:"cash"`
	AccruedFees           decimal.Decimal `json:"accrued_fees"`
	PortfolioValue        decimal.Decimal `json:"portfolio_value"`
	PatternDayTrader      bool            `json:"pattern_day_trader"`
	TradingBlocked        bool            `json:"trading_blocked"`
	TransfersBlocked      bool            `json:"transfers_blocked"`
	AccountBlocked        bool            `json:"account_blocked"`
	ShortingEnabled       bool            `json:"shorting_enabled"`
	TradeSuspendedByUser  bool            `json:"trade_suspended_by_user"`
	CreatedAt             time.Time       `json:"created_at"`
	Multiplier            decimal.Decimal `json:"multiplier"`
	Equity                decimal.Decimal `json:"equity"`
	LastEquity            decimal.Decimal `json:"last_equity"`
	LongMarketValue       decimal.Decimal `json:"long_market_value"`
	ShortMarketValue      decimal.Decimal `json:"short_market_value"`
	PositionMarketValue   decimal.Decimal `json:"position_market_value"`
	InitialMargin         decimal.Decimal `json:"initial_margin"`
	MaintenanceMargin     decimal.Decimal `json:"maintenance_margin"`
	LastMaintenanceMargin decimal.Decimal `json:"last_maintenance_margin"`
	SMA                   decimal.Decimal `json:"sma"`
	DaytradeCount         int64           `json:"daytrade_count"`
	CryptoTier            int             `json:"crypto_tier"`
}

func GetAccount

func GetAccount() (*Account, error)

GetAccount returns the user's account information using the default Alpaca client.

func (Account) MarshalEasyJSON

func (v Account) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Account) MarshalJSON

func (v Account) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Account) UnmarshalEasyJSON

func (v *Account) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Account) UnmarshalJSON

func (v *Account) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type AccountActivity

type AccountActivity struct {
	ID              string          `json:"id"`
	ActivityType    string          `json:"activity_type"`
	TransactionTime time.Time       `json:"transaction_time"`
	Type            string          `json:"type"`
	Price           decimal.Decimal `json:"price"`
	Qty             decimal.Decimal `json:"qty"`
	Side            string          `json:"side"`
	Symbol          string          `json:"symbol"`
	LeavesQty       decimal.Decimal `json:"leaves_qty"`
	CumQty          decimal.Decimal `json:"cum_qty"`
	Date            civil.Date      `json:"date"`
	NetAmount       decimal.Decimal `json:"net_amount"`
	Description     string          `json:"description"`
	PerShareAmount  decimal.Decimal `json:"per_share_amount"`
	OrderID         string          `json:"order_id"`
	OrderStatus     string          `json:"order_status"`
	Status          string          `json:"status"`
}

func GetAccountActivities

func GetAccountActivities(req GetAccountActivitiesRequest) ([]AccountActivity, error)

GetAccountActivities returns the account activities.

func (AccountActivity) MarshalEasyJSON

func (v AccountActivity) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (AccountActivity) MarshalJSON

func (v AccountActivity) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*AccountActivity) UnmarshalEasyJSON

func (v *AccountActivity) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*AccountActivity) UnmarshalJSON

func (v *AccountActivity) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type AccountConfigurations

type AccountConfigurations struct {
	DTBPCheck            DTBPCheck         `json:"dtbp_check"`
	NoShorting           bool              `json:"no_shorting"`
	TradeConfirmEmail    TradeConfirmEmail `json:"trade_confirm_email"`
	TradeSuspendedByUser bool              `json:"trade_suspended_by_user"`
}

func GetAccountConfigurations

func GetAccountConfigurations() (*AccountConfigurations, error)

GetAccountConfigurations returns the current account configurations

func UpdateAccountConfigurations

func UpdateAccountConfigurations(req UpdateAccountConfigurationsRequest) (*AccountConfigurations, error)

UpdateAccountConfigurations updates the account configs.

func (AccountConfigurations) MarshalEasyJSON

func (v AccountConfigurations) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (AccountConfigurations) MarshalJSON

func (v AccountConfigurations) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*AccountConfigurations) UnmarshalEasyJSON

func (v *AccountConfigurations) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*AccountConfigurations) UnmarshalJSON

func (v *AccountConfigurations) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type AddSymbolToWatchlistRequest

type AddSymbolToWatchlistRequest struct {
	Symbol string `json:"symbol"`
}

func (AddSymbolToWatchlistRequest) MarshalEasyJSON

func (v AddSymbolToWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (AddSymbolToWatchlistRequest) MarshalJSON

func (v AddSymbolToWatchlistRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*AddSymbolToWatchlistRequest) UnmarshalEasyJSON

func (v *AddSymbolToWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*AddSymbolToWatchlistRequest) UnmarshalJSON

func (v *AddSymbolToWatchlistRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Announcement

type Announcement struct {
	ID                      string `json:"id"`
	CorporateActionsID      string `json:"corporate_actions_id"`
	CAType                  string `json:"ca_type"`
	CASubType               string `json:"ca_sub_type"`
	InitiatingSymbol        string `json:"initiating_symbol"`
	InitiatingOriginalCusip string `json:"initiating_original_cusip"`
	TargetSymbol            string `json:"target_symbol"`
	TargetOriginalCusip     string `json:"target_original_cusip"`
	DeclarationDate         string `json:"declaration_date"`
	ExpirationDate          string `json:"expiration_date"`
	RecordDate              string `json:"record_date"`
	PayableDate             string `json:"payable_date"`
	Cash                    string `json:"cash"`
	OldRate                 string `json:"old_rate"`
	NewRate                 string `json:"new_rate"`
}

func GetAnnouncement

func GetAnnouncement(announcementID string) (*Announcement, error)

GetAnnouncement returns a single announcement with the default Alpaca client.

func GetAnnouncements

func GetAnnouncements(req GetAnnouncementsRequest) ([]Announcement, error)

GetAnnouncements returns a list of announcements with the default Alpaca client.

func (Announcement) MarshalEasyJSON

func (v Announcement) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Announcement) MarshalJSON

func (v Announcement) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Announcement) UnmarshalEasyJSON

func (v *Announcement) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Announcement) UnmarshalJSON

func (v *Announcement) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Asset

type Asset struct {
	ID                           string      `json:"id"`
	Class                        AssetClass  `json:"class"`
	Exchange                     string      `json:"exchange"`
	Symbol                       string      `json:"symbol"`
	Name                         string      `json:"name"`
	Status                       AssetStatus `json:"status"`
	Tradable                     bool        `json:"tradable"`
	Marginable                   bool        `json:"marginable"`
	MaintenanceMarginRequirement uint        `json:"maintenance_margin_requirement"`
	Shortable                    bool        `json:"shortable"`
	EasyToBorrow                 bool        `json:"easy_to_borrow"`
	Fractionable                 bool        `json:"fractionable"`
	Attributes                   []string    `json:"attributes"`
}

func GetAsset

func GetAsset(symbol string) (*Asset, error)

GetAsset returns an asset for the given symbol.

func GetAssets

func GetAssets(req GetAssetsRequest) ([]Asset, error)

GetAssets returns the list of assets.

func (Asset) MarshalEasyJSON

func (v Asset) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Asset) MarshalJSON

func (v Asset) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Asset) UnmarshalEasyJSON

func (v *Asset) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Asset) UnmarshalJSON

func (v *Asset) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type AssetClass

type AssetClass string
const (
	USEquity AssetClass = "us_equity"
	Crypto   AssetClass = "crypto"
)

type AssetStatus

type AssetStatus string
const (
	AssetActive   AssetStatus = "active"
	AssetInactive AssetStatus = "inactive"
)

type CalendarDay

type CalendarDay struct {
	Date  string `json:"date"`
	Open  string `json:"open"`
	Close string `json:"close"`
}

func GetCalendar

func GetCalendar(req GetCalendarRequest) ([]CalendarDay, error)

GetCalendar returns the market calendar.

func (CalendarDay) MarshalEasyJSON

func (v CalendarDay) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CalendarDay) MarshalJSON

func (v CalendarDay) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CalendarDay) UnmarshalEasyJSON

func (v *CalendarDay) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CalendarDay) UnmarshalJSON

func (v *CalendarDay) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Client

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

Client is the alpaca trading client

func NewClient

func NewClient(opts ClientOpts) *Client

NewClient creates a new Alpaca trading client using the given opts.

func (*Client) AddSymbolToWatchlist

func (c *Client) AddSymbolToWatchlist(watchlistID string, req AddSymbolToWatchlistRequest) (*Watchlist, error)

func (*Client) CancelAllOrders

func (c *Client) CancelAllOrders() error

CancelAllOrders submits a request to cancel all orders.

func (*Client) CancelOrder

func (c *Client) CancelOrder(orderID string) error

CancelOrder submits a request to cancel an open order.

func (*Client) CloseAllPositions

func (c *Client) CloseAllPositions(req CloseAllPositionsRequest) ([]Order, error)

CloseAllPositions liquidates all open positions at market price. It returns the list of orders that were created to close the positions. If errors occur while closing some of the positions, the errors will also be returned (possibly among orders)

func (*Client) ClosePosition

func (c *Client) ClosePosition(symbol string, req ClosePositionRequest) (*Order, error)

ClosePosition liquidates the position for the given symbol at market price.

func (*Client) CreateWatchlist

func (c *Client) CreateWatchlist(req CreateWatchlistRequest) (*Watchlist, error)

func (*Client) DeleteWatchlist

func (c *Client) DeleteWatchlist(watchlistID string) error

func (*Client) GetAccount

func (c *Client) GetAccount() (*Account, error)

GetAccount returns the user's account information.

func (*Client) GetAccountActivities

func (c *Client) GetAccountActivities(req GetAccountActivitiesRequest) ([]AccountActivity, error)

GetAccountActivities returns the account activities.

func (*Client) GetAccountConfigurations

func (c *Client) GetAccountConfigurations() (*AccountConfigurations, error)

GetAccountConfigurations returns the current account configurations

func (*Client) GetAnnouncement

func (c *Client) GetAnnouncement(announcementID string) (*Announcement, error)

func (*Client) GetAnnouncements

func (c *Client) GetAnnouncements(req GetAnnouncementsRequest) ([]Announcement, error)

func (*Client) GetAsset

func (c *Client) GetAsset(symbol string) (*Asset, error)

GetAsset returns an asset for the given symbol.

func (*Client) GetAssets

func (c *Client) GetAssets(req GetAssetsRequest) ([]Asset, error)

GetAssets returns the list of assets.

func (*Client) GetCalendar

func (c *Client) GetCalendar(req GetCalendarRequest) ([]CalendarDay, error)

GetCalendar returns the market calendar.

func (*Client) GetClock

func (c *Client) GetClock() (*Clock, error)

GetClock returns the current market clock.

func (*Client) GetOptionContract

func (c *Client) GetOptionContract(symbolOrID string) (*OptionContract, error)

GetOptionContract returns an option contract by symbol or contract ID.

func (*Client) GetOptionContracts

func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionContract, error)

GetOptionContracts returns the list of Option Contracts.

func (*Client) GetOrder

func (c *Client) GetOrder(orderID string) (*Order, error)

GetOrder submits a request to get an order by the order ID.

func (*Client) GetOrderByClientOrderID

func (c *Client) GetOrderByClientOrderID(clientOrderID string) (*Order, error)

GetOrderByClientOrderID submits a request to get an order by the client order ID.

func (*Client) GetOrders

func (c *Client) GetOrders(req GetOrdersRequest) ([]Order, error)

GetOrders returns the list of orders for an account.

func (*Client) GetPortfolioHistory

func (c *Client) GetPortfolioHistory(req GetPortfolioHistoryRequest) (*PortfolioHistory, error)

GetPortfolioHistory returns the portfolio history.

func (*Client) GetPosition

func (c *Client) GetPosition(symbol string) (*Position, error)

GetPosition returns the account's position for the provided symbol.

func (*Client) GetPositions

func (c *Client) GetPositions() ([]Position, error)

GetPositions returns the account's open positions.

func (*Client) GetWatchlist

func (c *Client) GetWatchlist(watchlistID string) (*Watchlist, error)

func (*Client) GetWatchlists

func (c *Client) GetWatchlists() ([]Watchlist, error)

GetAccount returns the user's account information.

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(req PlaceOrderRequest) (*Order, error)

PlaceOrder submits an order request to buy or sell an asset.

func (*Client) RemoveSymbolFromWatchlist

func (c *Client) RemoveSymbolFromWatchlist(watchlistID string, req RemoveSymbolFromWatchlistRequest) error

func (*Client) ReplaceOrder

func (c *Client) ReplaceOrder(orderID string, req ReplaceOrderRequest) (*Order, error)

ReplaceOrder submits a request to replace an order by id

func (*Client) StreamTradeUpdates

func (c *Client) StreamTradeUpdates(
	ctx context.Context, handler func(TradeUpdate), req StreamTradeUpdatesRequest,
) error

StreamTradeUpdates streams the trade updates of the account.

func (*Client) StreamTradeUpdatesInBackground

func (c *Client) StreamTradeUpdatesInBackground(ctx context.Context, handler func(TradeUpdate))

StreamTradeUpdatesInBackground streams the trade updates of the account. It runs in the background and keeps calling the handler function for each trade update until the context is cancelled. If an error happens it logs it and retries immediately.

func (*Client) UpdateAccountConfigurations

func (c *Client) UpdateAccountConfigurations(req UpdateAccountConfigurationsRequest) (*AccountConfigurations, error)

UpdateAccountConfigurations updates the account configs.

func (*Client) UpdateWatchlist

func (c *Client) UpdateWatchlist(watchlistID string, req UpdateWatchlistRequest) (*Watchlist, error)

type ClientOpts

type ClientOpts struct {
	APIKey       string
	APISecret    string
	BrokerKey    string
	BrokerSecret string
	OAuth        string
	BaseURL      string
	RetryLimit   int
	RetryDelay   time.Duration
	// HTTPClient to be used for each http request.
	HTTPClient *http.Client
}

ClientOpts contains options for the alpaca client

type Clock

type Clock struct {
	Timestamp time.Time `json:"timestamp"`
	IsOpen    bool      `json:"is_open"`
	NextOpen  time.Time `json:"next_open"`
	NextClose time.Time `json:"next_close"`
}

func GetClock

func GetClock() (*Clock, error)

GetClock returns the current market clock.

func (Clock) MarshalEasyJSON

func (v Clock) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Clock) MarshalJSON

func (v Clock) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Clock) UnmarshalEasyJSON

func (v *Clock) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Clock) UnmarshalJSON

func (v *Clock) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type CloseAllPositionsRequest

type CloseAllPositionsRequest struct {
	CancelOrders bool
}

type ClosePositionRequest

type ClosePositionRequest struct {
	// Qty is the number of shares to liquidate. Can accept up to 9 decimal points.
	// Cannot work with percentage.
	Qty decimal.Decimal
	// Percentage of position to liquidate. Must be between 0 and 100.
	// Would only sell fractional if position is originally fractional.
	// Can accept up to 9 decimal points. Cannot work with qty.
	Percentage decimal.Decimal
}

type CreateWatchlistRequest

type CreateWatchlistRequest struct {
	Name    string   `json:"name"`
	Symbols []string `json:"symbols"`
}

func (CreateWatchlistRequest) MarshalEasyJSON

func (v CreateWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (CreateWatchlistRequest) MarshalJSON

func (v CreateWatchlistRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*CreateWatchlistRequest) UnmarshalEasyJSON

func (v *CreateWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*CreateWatchlistRequest) UnmarshalJSON

func (v *CreateWatchlistRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type DTBPCheck

type DTBPCheck string
const (
	Entry DTBPCheck = "entry"
	Exit  DTBPCheck = "exit"
	Both  DTBPCheck = "both"
)

type DateType

type DateType string
const (
	DeclarationDate DateType = "declaration_date"
	RecordDate      DateType = "record_date"
	ExDate          DateType = "ex_date"
	PayableDate     DateType = "payable_date"
)

type DeliverableSettlementMethod

type DeliverableSettlementMethod string
const (
	DeliverableSettlementMethodBTOB DeliverableSettlementMethod = "BTOB"
	DeliverableSettlementMethodCADF DeliverableSettlementMethod = "CADF"
	DeliverableSettlementMethodCAFX DeliverableSettlementMethod = "CAFX"
	DeliverableSettlementMethodCCC  DeliverableSettlementMethod = "CCC"
)

type DeliverableSettlementType

type DeliverableSettlementType string
const (
	DeliverableSettlementTypeT0 DeliverableSettlementType = "T+0"
	DeliverableSettlementTypeT1 DeliverableSettlementType = "T+1"
	DeliverableSettlementTypeT2 DeliverableSettlementType = "T+2"
	DeliverableSettlementTypeT3 DeliverableSettlementType = "T+3"
	DeliverableSettlementTypeT4 DeliverableSettlementType = "T+4"
	DeliverableSettlementTypeT5 DeliverableSettlementType = "T+5"
)

type DeliverableType

type DeliverableType string
const (
	DeliverableTypeCash   DeliverableType = "cash"
	DeliverableTypeEquity DeliverableType = "equity"
)

type GetAccountActivitiesRequest

type GetAccountActivitiesRequest struct {
	ActivityTypes []string  `json:"activity_types"`
	Date          time.Time `json:"date"`
	Until         time.Time `json:"until"`
	After         time.Time `json:"after"`
	Direction     string    `json:"direction"`
	PageSize      int       `json:"page_size"`
	PageToken     string    `json:"page_token"`
	Category      string    `json:"category"`
}

type GetAnnouncementsRequest

type GetAnnouncementsRequest struct {
	CATypes  []string  `json:"ca_types"`
	Since    time.Time `json:"since"`
	Until    time.Time `json:"until"`
	Symbol   string    `json:"symbol"`
	Cusip    string    `json:"cusip"`
	DateType DateType  `json:"date_type"`
}

type GetAssetsRequest

type GetAssetsRequest struct {
	Status     string
	AssetClass string
	Exchange   string
}

type GetCalendarRequest

type GetCalendarRequest struct {
	Start time.Time
	End   time.Time
}

type GetOptionContractsRequest

type GetOptionContractsRequest struct {
	UnderlyingSymbols     string
	ShowDeliverable       bool
	Status                OptionStatus
	ExpirationDate        civil.Date
	ExpirationDateGTE     civil.Date
	ExpirationDateLTE     civil.Date
	RootSymbol            string
	Type                  OptionType
	Style                 OptionStyle
	StrikePriceGTE        decimal.Decimal
	StrikePriceLTE        decimal.Decimal
	PennyProgramIndicator bool
	PageLimit             int
	TotalLimit            int
}

type GetOrdersRequest

type GetOrdersRequest struct {
	// Status to be queried. Possible values: open, closed, all. Defaults to open.
	Status    string    `json:"status"`
	Limit     int       `json:"limit"`
	After     time.Time `json:"after"`
	Until     time.Time `json:"until"`
	Direction string    `json:"direction"`
	Nested    bool      `json:"nested"`
	Side      string    `json:"side"`
	Symbols   []string  `json:"symbols"`
}

type GetPortfolioHistoryRequest

type GetPortfolioHistoryRequest struct {
	Period        string
	TimeFrame     TimeFrame
	DateEnd       time.Time
	ExtendedHours bool
}

type OptionContract

type OptionContract struct {
	ID                string              `json:"id"`
	Symbol            string              `json:"symbol"`
	Name              string              `json:"name"`
	Status            OptionStatus        `json:"status"`
	Tradable          bool                `json:"tradable"`
	ExpirationDate    civil.Date          `json:"expiration_date"`
	RootSymbol        *string             `json:"root_symbol,omitempty"`
	UnderlyingSymbol  string              `json:"underlying_symbol"`
	UnderlyingAssetID string              `json:"underlying_asset_id"`
	Type              OptionType          `json:"type"`
	Style             OptionStyle         `json:"style"`
	StrikePrice       decimal.Decimal     `json:"strike_price"`
	Multiplier        decimal.Decimal     `json:"multiplier"`
	Size              decimal.Decimal     `json:"size"`
	OpenInterest      *decimal.Decimal    `json:"open_interest"`
	OpenInterestDate  *civil.Date         `json:"open_interest_date,omitempty"`
	ClosePrice        *decimal.Decimal    `json:"close_price,omitempty"`
	ClosePriceDate    *civil.Date         `json:"close_price_date,omitempty"`
	Deliverables      []OptionDeliverable `json:"deliverables,omitempty"`
}

func GetOptionContract

func GetOptionContract(symbolOrID string) (*OptionContract, error)

GetOptionContract returns an option contract by symbol or contract ID.

func GetOptionContracts

func GetOptionContracts(req GetOptionContractsRequest) ([]OptionContract, error)

GetOptionContracts returns the list of Option Contracts.

func (OptionContract) MarshalEasyJSON

func (v OptionContract) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (OptionContract) MarshalJSON

func (v OptionContract) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*OptionContract) UnmarshalEasyJSON

func (v *OptionContract) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*OptionContract) UnmarshalJSON

func (v *OptionContract) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type OptionDeliverable

type OptionDeliverable struct {
	Type                 DeliverableType             `json:"type"`
	Symbol               string                      `json:"symbol"`
	AssetID              *string                     `json:"asset_id,omitempty"`
	Amount               decimal.Decimal             `json:"amount"`
	AllocationPercentage decimal.Decimal             `json:"allocation_percentage"`
	SettlementType       DeliverableSettlementType   `json:"settlement_type"`
	SettlementMethod     DeliverableSettlementMethod `json:"settlement_method"`
	DelayedSettlement    bool                        `json:"delayed_settlement"`
}

func (OptionDeliverable) MarshalEasyJSON

func (v OptionDeliverable) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (OptionDeliverable) MarshalJSON

func (v OptionDeliverable) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*OptionDeliverable) UnmarshalEasyJSON

func (v *OptionDeliverable) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*OptionDeliverable) UnmarshalJSON

func (v *OptionDeliverable) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type OptionStatus

type OptionStatus string
const (
	OptionStatusActive   OptionStatus = "active"
	OptionStatusInactive OptionStatus = "inactive"
)

type OptionStyle

type OptionStyle string
const (
	OptionStyleAmerican OptionStyle = "american"
	OptionStyleEuropean OptionStyle = "european"
)

type OptionType

type OptionType string
const (
	OptionTypeCall OptionType = "call"
	OptionTypePut  OptionType = "put"
)

type Order

type Order struct {
	ID             string           `json:"id"`
	ClientOrderID  string           `json:"client_order_id"`
	CreatedAt      time.Time        `json:"created_at"`
	UpdatedAt      time.Time        `json:"updated_at"`
	SubmittedAt    time.Time        `json:"submitted_at"`
	FilledAt       *time.Time       `json:"filled_at"`
	ExpiredAt      *time.Time       `json:"expired_at"`
	CanceledAt     *time.Time       `json:"canceled_at"`
	FailedAt       *time.Time       `json:"failed_at"`
	ReplacedAt     *time.Time       `json:"replaced_at"`
	ReplacedBy     *string          `json:"replaced_by"`
	Replaces       *string          `json:"replaces"`
	AssetID        string           `json:"asset_id"`
	Symbol         string           `json:"symbol"`
	AssetClass     AssetClass       `json:"asset_class"`
	OrderClass     OrderClass       `json:"order_class"`
	Type           OrderType        `json:"type"`
	Side           Side             `json:"side"`
	TimeInForce    TimeInForce      `json:"time_in_force"`
	Status         string           `json:"status"`
	Notional       *decimal.Decimal `json:"notional"`
	Qty            *decimal.Decimal `json:"qty"`
	FilledQty      decimal.Decimal  `json:"filled_qty"`
	FilledAvgPrice *decimal.Decimal `json:"filled_avg_price"`
	LimitPrice     *decimal.Decimal `json:"limit_price"`
	StopPrice      *decimal.Decimal `json:"stop_price"`
	TrailPrice     *decimal.Decimal `json:"trail_price"`
	TrailPercent   *decimal.Decimal `json:"trail_percent"`
	HWM            *decimal.Decimal `json:"hwm"`
	ExtendedHours  bool             `json:"extended_hours"`
	Legs           []Order          `json:"legs"`
}

func CloseAllPositions

func CloseAllPositions(req CloseAllPositionsRequest) ([]Order, error)

CloseAllPositions liquidates all open positions at market price.

func ClosePosition

func ClosePosition(symbol string, req ClosePositionRequest) (*Order, error)

ClosePosition liquidates the position for the given symbol at market price.

func GetOrder

func GetOrder(orderID string) (*Order, error)

GetOrder submits a request to get an order by the order ID.

func GetOrderByClientOrderID

func GetOrderByClientOrderID(clientOrderID string) (*Order, error)

GetOrderByClientOrderID submits a request to get an order by the client order ID.

func GetOrders

func GetOrders(req GetOrdersRequest) ([]Order, error)

GetOrders returns the list of orders for an account.

func PlaceOrder

func PlaceOrder(req PlaceOrderRequest) (*Order, error)

PlaceOrder submits an order request to buy or sell an asset.

func ReplaceOrder

func ReplaceOrder(orderID string, req ReplaceOrderRequest) (*Order, error)

ReplaceOrder submits a request to replace an order by id

func (Order) MarshalEasyJSON

func (v Order) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Order) MarshalJSON

func (v Order) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Order) UnmarshalEasyJSON

func (v *Order) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Order) UnmarshalJSON

func (v *Order) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type OrderClass

type OrderClass string
const (
	Bracket OrderClass = "bracket"
	OTO     OrderClass = "oto"
	OCO     OrderClass = "oco"
	Simple  OrderClass = "simple"
)

type OrderType

type OrderType string
const (
	Market       OrderType = "market"
	Limit        OrderType = "limit"
	Stop         OrderType = "stop"
	StopLimit    OrderType = "stop_limit"
	TrailingStop OrderType = "trailing_stop"
)

type PlaceOrderRequest

type PlaceOrderRequest struct {
	Symbol         string           `json:"symbol"`
	Qty            *decimal.Decimal `json:"qty"`
	Notional       *decimal.Decimal `json:"notional"`
	Side           Side             `json:"side"`
	Type           OrderType        `json:"type"`
	TimeInForce    TimeInForce      `json:"time_in_force"`
	LimitPrice     *decimal.Decimal `json:"limit_price"`
	ExtendedHours  bool             `json:"extended_hours"`
	StopPrice      *decimal.Decimal `json:"stop_price"`
	ClientOrderID  string           `json:"client_order_id"`
	OrderClass     OrderClass       `json:"order_class"`
	TakeProfit     *TakeProfit      `json:"take_profit"`
	StopLoss       *StopLoss        `json:"stop_loss"`
	TrailPrice     *decimal.Decimal `json:"trail_price"`
	TrailPercent   *decimal.Decimal `json:"trail_percent"`
	PositionIntent PositionIntent   `json:"position_intent"`
}

type PortfolioHistory

type PortfolioHistory struct {
	BaseValue     decimal.Decimal   `json:"base_value"`
	Equity        []decimal.Decimal `json:"equity"`
	ProfitLoss    []decimal.Decimal `json:"profit_loss"`
	ProfitLossPct []decimal.Decimal `json:"profit_loss_pct"`
	Timeframe     TimeFrame         `json:"timeframe"`
	Timestamp     []int64           `json:"timestamp"`
}

func GetPortfolioHistory

func GetPortfolioHistory(req GetPortfolioHistoryRequest) (*PortfolioHistory, error)

GetPortfolioHistory returns the portfolio history.

func (PortfolioHistory) MarshalEasyJSON

func (v PortfolioHistory) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (PortfolioHistory) MarshalJSON

func (v PortfolioHistory) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*PortfolioHistory) UnmarshalEasyJSON

func (v *PortfolioHistory) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*PortfolioHistory) UnmarshalJSON

func (v *PortfolioHistory) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Position

type Position struct {
	AssetID                string           `json:"asset_id"`
	Symbol                 string           `json:"symbol"`
	Exchange               string           `json:"exchange"`
	AssetClass             AssetClass       `json:"asset_class"`
	AssetMarginable        bool             `json:"asset_marginable"`
	Qty                    decimal.Decimal  `json:"qty"`
	QtyAvailable           decimal.Decimal  `json:"qty_available"`
	AvgEntryPrice          decimal.Decimal  `json:"avg_entry_price"`
	Side                   string           `json:"side"`
	MarketValue            *decimal.Decimal `json:"market_value"`
	CostBasis              decimal.Decimal  `json:"cost_basis"`
	UnrealizedPL           *decimal.Decimal `json:"unrealized_pl"`
	UnrealizedPLPC         *decimal.Decimal `json:"unrealized_plpc"`
	UnrealizedIntradayPL   *decimal.Decimal `json:"unrealized_intraday_pl"`
	UnrealizedIntradayPLPC *decimal.Decimal `json:"unrealized_intraday_plpc"`
	CurrentPrice           *decimal.Decimal `json:"current_price"`
	LastdayPrice           *decimal.Decimal `json:"lastday_price"`
	ChangeToday            *decimal.Decimal `json:"change_today"`
}

func GetPosition

func GetPosition(symbol string) (*Position, error)

GetPosition returns the account's position for the provided symbol.

func GetPositions

func GetPositions() ([]Position, error)

GetPositions lists the account's open positions.

func (Position) MarshalEasyJSON

func (v Position) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Position) MarshalJSON

func (v Position) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Position) UnmarshalEasyJSON

func (v *Position) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Position) UnmarshalJSON

func (v *Position) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type PositionIntent

type PositionIntent string
const (
	BuyToOpen   PositionIntent = "buy_to_open"
	BuyToClose  PositionIntent = "buy_to_close"
	SellToOpen  PositionIntent = "sell_to_open"
	SellToClose PositionIntent = "sell_to_close"
)

type RemoveSymbolFromWatchlistRequest

type RemoveSymbolFromWatchlistRequest struct {
	Symbol string `json:"symbol"`
}

func (RemoveSymbolFromWatchlistRequest) MarshalEasyJSON

func (v RemoveSymbolFromWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (RemoveSymbolFromWatchlistRequest) MarshalJSON

func (v RemoveSymbolFromWatchlistRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*RemoveSymbolFromWatchlistRequest) UnmarshalEasyJSON

func (v *RemoveSymbolFromWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*RemoveSymbolFromWatchlistRequest) UnmarshalJSON

func (v *RemoveSymbolFromWatchlistRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ReplaceOrderRequest

type ReplaceOrderRequest struct {
	Qty           *decimal.Decimal `json:"qty"`
	LimitPrice    *decimal.Decimal `json:"limit_price"`
	StopPrice     *decimal.Decimal `json:"stop_price"`
	Trail         *decimal.Decimal `json:"trail"`
	TimeInForce   TimeInForce      `json:"time_in_force"`
	ClientOrderID string           `json:"client_order_id"`
}

type Side

type Side string
const (
	Buy  Side = "buy"
	Sell Side = "sell"
)

type StopLoss

type StopLoss struct {
	LimitPrice *decimal.Decimal `json:"limit_price"`
	StopPrice  *decimal.Decimal `json:"stop_price"`
}

type StreamTradeUpdatesRequest

type StreamTradeUpdatesRequest struct {
	Since   time.Time
	Until   time.Time
	SinceID string
	UntilID string
}

type TakeProfit

type TakeProfit struct {
	LimitPrice *decimal.Decimal `json:"limit_price"`
}

type TimeFrame

type TimeFrame string
const (
	Min1  TimeFrame = "1Min"
	Min5  TimeFrame = "5Min"
	Min15 TimeFrame = "15Min"
	Hour1 TimeFrame = "1H"
	Day1  TimeFrame = "1D"
)

type TimeInForce

type TimeInForce string
const (
	Day TimeInForce = "day"
	GTC TimeInForce = "gtc"
	OPG TimeInForce = "opg"
	IOC TimeInForce = "ioc"
	FOK TimeInForce = "fok"
	GTX TimeInForce = "gtx"
	GTD TimeInForce = "gtd"
	CLS TimeInForce = "cls"
)

type TradeConfirmEmail

type TradeConfirmEmail string
const (
	None TradeConfirmEmail = "none"
	All  TradeConfirmEmail = "all"
)

type TradeUpdate

type TradeUpdate struct {
	At          time.Time        `json:"at"`
	Event       string           `json:"event"`
	EventID     string           `json:"event_id"`
	ExecutionID string           `json:"execution_id"`
	Order       Order            `json:"order"`
	PositionQty *decimal.Decimal `json:"position_qty"`
	Price       *decimal.Decimal `json:"price"`
	Qty         *decimal.Decimal `json:"qty"`
	Timestamp   *time.Time       `json:"timestamp"`
}

func (TradeUpdate) MarshalEasyJSON

func (v TradeUpdate) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (TradeUpdate) MarshalJSON

func (v TradeUpdate) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*TradeUpdate) UnmarshalEasyJSON

func (v *TradeUpdate) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*TradeUpdate) UnmarshalJSON

func (v *TradeUpdate) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type UpdateAccountConfigurationsRequest

type UpdateAccountConfigurationsRequest struct {
	DtbpCheck         string `json:"dtbp_check"`
	TradeConfirmEmail string `json:"trade_confirm_email"`
	SuspendTrade      bool   `json:"suspend_trade"`
	NoShorting        bool   `json:"no_shorting"`
	FractionalTrading bool   `json:"fractional_trading"`
}

type UpdateWatchlistRequest

type UpdateWatchlistRequest struct {
	Name    string   `json:"name"`
	Symbols []string `json:"symbols"`
}

func (UpdateWatchlistRequest) MarshalEasyJSON

func (v UpdateWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (UpdateWatchlistRequest) MarshalJSON

func (v UpdateWatchlistRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*UpdateWatchlistRequest) UnmarshalEasyJSON

func (v *UpdateWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*UpdateWatchlistRequest) UnmarshalJSON

func (v *UpdateWatchlistRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Watchlist

type Watchlist struct {
	AccountID string  `json:"account_id"`
	ID        string  `json:"id"`
	CreatedAt string  `json:"created_at"`
	UpdatedAt string  `json:"updated_at"`
	Name      string  `json:"name"`
	Assets    []Asset `json:"assets"`
}

func AddSymbolToWatchlist

func AddSymbolToWatchlist(watchlistID string, req AddSymbolToWatchlistRequest) (*Watchlist, error)

AddSymbolToWatchlist adds an asset to a watchlist by getting the watchlist id with the default Alpaca client.

func CreateWatchlist

func CreateWatchlist(req CreateWatchlistRequest) (*Watchlist, error)

CreateWatchlist creates a new watchlist with the default Alpaca client.

func GetWatchlist

func GetWatchlist(watchlistID string) (*Watchlist, error)

GetWatchlist returns a single watchlist by getting the watchlist id with the default Alpaca client.

func GetWatchlists

func GetWatchlists() ([]Watchlist, error)

GetWatchlists returns a list of watchlists with the default Alpaca client.

func UpdateWatchlist

func UpdateWatchlist(watchlistID string, req UpdateWatchlistRequest) (*Watchlist, error)

UpdateWatchlist updates a watchlist by getting the watchlist id with the default Alpaca client.

func (Watchlist) MarshalEasyJSON

func (v Watchlist) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Watchlist) MarshalJSON

func (v Watchlist) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Watchlist) UnmarshalEasyJSON

func (v *Watchlist) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Watchlist) UnmarshalJSON

func (v *Watchlist) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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