Documentation ¶
Index ¶
- Variables
- func APIErrorFromResponse(resp *http.Response) error
- func CancelAllOrders() error
- func CancelOrder(orderID string) error
- func DeleteWatchlist(watchlistID string) error
- func RemoveSymbolFromWatchlist(watchlistID string, req RemoveSymbolFromWatchlistRequest) error
- func RoundLimitPrice(price decimal.Decimal, side Side) *decimal.Decimal
- func StreamTradeUpdates(ctx context.Context, handler func(TradeUpdate), req StreamTradeUpdatesRequest) error
- func StreamTradeUpdatesInBackground(ctx context.Context, handler func(TradeUpdate))
- func Version() string
- type APIError
- type Account
- type AccountActivity
- type AccountConfigurations
- type AddSymbolToWatchlistRequest
- type Announcement
- type Asset
- type AssetClass
- type AssetStatus
- type CalendarDay
- type Client
- func (c *Client) AddSymbolToWatchlist(watchlistID string, req AddSymbolToWatchlistRequest) (*Watchlist, error)
- func (c *Client) CancelAllOrders() error
- func (c *Client) CancelOrder(orderID string) error
- func (c *Client) CloseAllPositions(req CloseAllPositionsRequest) ([]Order, error)
- func (c *Client) ClosePosition(symbol string, req ClosePositionRequest) (*Order, error)
- func (c *Client) CreateWatchlist(req CreateWatchlistRequest) (*Watchlist, error)
- func (c *Client) DeleteWatchlist(watchlistID string) error
- func (c *Client) GetAccount() (*Account, error)
- func (c *Client) GetAccountActivities(req GetAccountActivitiesRequest) ([]AccountActivity, error)
- func (c *Client) GetAccountConfigurations() (*AccountConfigurations, error)
- func (c *Client) GetAnnouncement(announcementID string) (*Announcement, error)
- func (c *Client) GetAnnouncements(req GetAnnouncementsRequest) ([]Announcement, error)
- func (c *Client) GetAsset(symbol string) (*Asset, error)
- func (c *Client) GetAssets(req GetAssetsRequest) ([]Asset, error)
- func (c *Client) GetCalendar(req GetCalendarRequest) ([]CalendarDay, error)
- func (c *Client) GetClock() (*Clock, error)
- func (c *Client) GetOptionContract(symbolOrID string) (*OptionContract, error)
- func (c *Client) GetOptionContracts(req GetOptionContractsRequest) ([]OptionContract, error)
- func (c *Client) GetOrder(orderID string) (*Order, error)
- func (c *Client) GetOrderByClientOrderID(clientOrderID string) (*Order, error)
- func (c *Client) GetOrders(req GetOrdersRequest) ([]Order, error)
- func (c *Client) GetPortfolioHistory(req GetPortfolioHistoryRequest) (*PortfolioHistory, error)
- func (c *Client) GetPosition(symbol string) (*Position, error)
- func (c *Client) GetPositions() ([]Position, error)
- func (c *Client) GetWatchlist(watchlistID string) (*Watchlist, error)
- func (c *Client) GetWatchlists() ([]Watchlist, error)
- func (c *Client) PlaceOrder(req PlaceOrderRequest) (*Order, error)
- func (c *Client) RemoveSymbolFromWatchlist(watchlistID string, req RemoveSymbolFromWatchlistRequest) error
- func (c *Client) ReplaceOrder(orderID string, req ReplaceOrderRequest) (*Order, error)
- func (c *Client) StreamTradeUpdates(ctx context.Context, handler func(TradeUpdate), req StreamTradeUpdatesRequest) error
- func (c *Client) StreamTradeUpdatesInBackground(ctx context.Context, handler func(TradeUpdate))
- func (c *Client) UpdateAccountConfigurations(req UpdateAccountConfigurationsRequest) (*AccountConfigurations, error)
- func (c *Client) UpdateWatchlist(watchlistID string, req UpdateWatchlistRequest) (*Watchlist, error)
- type ClientOpts
- type Clock
- type CloseAllPositionsRequest
- type ClosePositionRequest
- type CreateWatchlistRequest
- type DTBPCheck
- type DateType
- type DeliverableSettlementMethod
- type DeliverableSettlementType
- type DeliverableType
- type GetAccountActivitiesRequest
- type GetAnnouncementsRequest
- type GetAssetsRequest
- type GetCalendarRequest
- type GetOptionContractsRequest
- type GetOrdersRequest
- type GetPortfolioHistoryRequest
- type OptionContract
- type OptionDeliverable
- type OptionStatus
- type OptionStyle
- type OptionType
- type Order
- func CloseAllPositions(req CloseAllPositionsRequest) ([]Order, error)
- func ClosePosition(symbol string, req ClosePositionRequest) (*Order, error)
- func GetOrder(orderID string) (*Order, error)
- func GetOrderByClientOrderID(clientOrderID string) (*Order, error)
- func GetOrders(req GetOrdersRequest) ([]Order, error)
- func PlaceOrder(req PlaceOrderRequest) (*Order, error)
- func ReplaceOrder(orderID string, req ReplaceOrderRequest) (*Order, error)
- type OrderClass
- type OrderType
- type PlaceOrderRequest
- type PortfolioHistory
- type Position
- type PositionIntent
- type RemoveSymbolFromWatchlistRequest
- func (v RemoveSymbolFromWatchlistRequest) MarshalEasyJSON(w *jwriter.Writer)
- func (v RemoveSymbolFromWatchlistRequest) MarshalJSON() ([]byte, error)
- func (v *RemoveSymbolFromWatchlistRequest) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *RemoveSymbolFromWatchlistRequest) UnmarshalJSON(data []byte) error
- type ReplaceOrderRequest
- type Side
- type StopLoss
- type StreamTradeUpdatesRequest
- type TakeProfit
- type TimeFrame
- type TimeInForce
- type TradeConfirmEmail
- type TradeUpdate
- type UpdateAccountConfigurationsRequest
- type UpdateWatchlistRequest
- type Watchlist
- func AddSymbolToWatchlist(watchlistID string, req AddSymbolToWatchlistRequest) (*Watchlist, error)
- func CreateWatchlist(req CreateWatchlistRequest) (*Watchlist, error)
- func GetWatchlist(watchlistID string) (*Watchlist, error)
- func GetWatchlists() ([]Watchlist, error)
- func UpdateWatchlist(watchlistID string, req UpdateWatchlistRequest) (*Watchlist, error)
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = NewClient(ClientOpts{})
DefaultClient uses options from environment variables, or the defaults.
var ErrSymbolMissing = errors.New("symbol missing from request")
Functions ¶
func APIErrorFromResponse ¶
func CancelAllOrders ¶
func CancelAllOrders() error
CancelAllOrders submits a request to cancel all orders.
func CancelOrder ¶
CancelOrder submits a request to cancel an open order.
func DeleteWatchlist ¶
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 ¶
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.
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) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (APIError) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*APIError) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*APIError) UnmarshalJSON ¶
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 ¶
GetAccount returns the user's account information using the default Alpaca client.
func (Account) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Account) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Account) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Account) UnmarshalJSON ¶
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"` 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 GetAssets ¶
func GetAssets(req GetAssetsRequest) ([]Asset, error)
GetAssets returns the list of assets.
func (Asset) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Asset) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Asset) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Asset) UnmarshalJSON ¶
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 ¶
CancelAllOrders submits a request to cancel all orders.
func (*Client) CancelOrder ¶
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 (*Client) GetAccount ¶
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) 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) 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) GetOrderByClientOrderID ¶
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 ¶
GetPosition returns the account's position for the provided symbol.
func (*Client) GetPositions ¶
GetPositions returns the account's open positions.
func (*Client) GetWatchlists ¶
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 (Clock) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Clock) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Clock) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Clock) UnmarshalJSON ¶
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 ¶
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 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 GetAssetsRequest ¶
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 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 GetOrderByClientOrderID ¶
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 ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Order) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Order) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Order) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type OrderClass ¶
type OrderClass string
const ( Bracket OrderClass = "bracket" OTO OrderClass = "oto" OCO OrderClass = "oco" Simple OrderClass = "simple" )
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 ¶
GetPosition returns the account's position for the provided symbol.
func GetPositions ¶
GetPositions lists the account's open positions.
func (Position) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Position) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Position) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Position) UnmarshalJSON ¶
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 TakeProfit ¶
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 UpdateWatchlistRequest ¶
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 ¶
GetWatchlist returns a single watchlist by getting the watchlist id with the default Alpaca client.
func GetWatchlists ¶
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 ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Watchlist) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Watchlist) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Watchlist) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface