alpaca

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: Apache-2.0 Imports: 18 Imported by: 23

Documentation

Index

Constants

View Source
const (
	TradeUpdates   = "trade_updates"
	AccountUpdates = "account_updates"
)
View Source
const (
	MaxConnectionAttempts = 3
)

Variables

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

Functions

func CancelOrder

func CancelOrder(orderID string) error

CancelOrder submits a request to cancel an open order with the default Alpaca client.

func GetBars added in v1.8.0

func GetBars(
	symbol string, timeFrame v2.TimeFrame, adjustment v2.Adjustment,
	start, end time.Time, limit int,
) <-chan v2.BarItem

GetBars returns a channel that will be populated with the bars for the given symbol between the given start and end times, limited to the given limit, using the given and timeframe and adjustment.

func GetLatestQuote added in v1.8.2

func GetLatestQuote(symbol string) (*v2.Quote, error)

GetLatestTrade returns the latest quote for a given symbol

func GetLatestTrade added in v1.8.2

func GetLatestTrade(symbol string) (*v2.Trade, error)

GetLatestTrade returns the latest trade for a given symbol

func GetQuotes added in v1.8.0

func GetQuotes(symbol string, start, end time.Time, limit int) <-chan v2.QuoteItem

GetQuotes returns a channel that will be populated with the quotes for the given symbol that happened between the given start and end times, limited to the given limit.

func GetSnapshot added in v1.8.2

func GetSnapshot(symbol string) (*v2.Snapshot, error)

GetSnapshot returns the snapshot for a given symbol

func GetSnapshots added in v1.8.2

func GetSnapshots(symbols []string) (map[string]*v2.Snapshot, error)

GetSnapshots returns the snapshots for a multiple symbols

func GetTrades added in v1.8.0

func GetTrades(symbol string, start, end time.Time, limit int) <-chan v2.TradeItem

GetTrades returns a channel that will be populated with the trades for the given symbol that happened between the given start and end times, limited to the given limit.

func ListBars added in v1.1.0

func ListBars(symbols []string, opts ListBarParams) (map[string][]Bar, error)

ListBars returns a map of bar lists corresponding to the provided symbol list that is filtered by the provided parameters with the default Alpaca client.

func SetBaseUrl added in v1.1.0

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 Account

type Account struct {
	ID                    string          `json:"id"`
	AccountNumber         string          `json:"account_number"`
	CreatedAt             time.Time       `json:"created_at"`
	UpdatedAt             time.Time       `json:"updated_at"`
	DeletedAt             *time.Time      `json:"deleted_at"`
	Status                string          `json:"status"`
	Currency              string          `json:"currency"`
	Cash                  decimal.Decimal `json:"cash"`
	CashWithdrawable      decimal.Decimal `json:"cash_withdrawable"`
	TradingBlocked        bool            `json:"trading_blocked"`
	TransfersBlocked      bool            `json:"transfers_blocked"`
	AccountBlocked        bool            `json:"account_blocked"`
	ShortingEnabled       bool            `json:"shorting_enabled"`
	BuyingPower           decimal.Decimal `json:"buying_power"`
	PatternDayTrader      bool            `json:"pattern_day_trader"`
	DaytradeCount         int64           `json:"daytrade_count"`
	DaytradingBuyingPower decimal.Decimal `json:"daytrading_buying_power"`
	RegTBuyingPower       decimal.Decimal `json:"regt_buying_power"`
	Equity                decimal.Decimal `json:"equity"`
	LastEquity            decimal.Decimal `json:"last_equity"`
	Multiplier            string          `json:"multiplier"`
	InitialMargin         decimal.Decimal `json:"initial_margin"`
	MaintenanceMargin     decimal.Decimal `json:"maintenance_margin"`
	LastMaintenanceMargin decimal.Decimal `json:"last_maintenance_margin"`
	LongMarketValue       decimal.Decimal `json:"long_market_value"`
	ShortMarketValue      decimal.Decimal `json:"short_market_value"`
	PortfolioValue        decimal.Decimal `json:"portfolio_value"`
}

func GetAccount

func GetAccount() (*Account, error)

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

type AccountActivitiesRequest added in v1.3.8

type AccountActivitiesRequest 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"`
}

type AccountActivity added in v1.6.0

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            time.Time       `json:"date"`
	NetAmount       decimal.Decimal `json:"net_amount"`
	Description     string          `json:"description"`
	PerShareAmount  decimal.Decimal `json:"per_share_amount"`
}

func GetAccountActivities added in v1.3.8

func GetAccountActivities(activityType *string, opts *AccountActivitiesRequest) ([]AccountActivity, error)

type AccountConfigurations added in v1.3.7

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 added in v1.3.7

func GetAccountConfigurations() (*AccountConfigurations, error)

GetAccountConfigurations returns the account configs using the default Alpaca client.

func UpdateAccountConfigurations added in v1.3.7

func UpdateAccountConfigurations(newConfigs AccountConfigurationsRequest) (*AccountConfigurations, error)

UpdateAccountConfigurations changes the account configs and returns the new configs using the default Alpaca client

type AccountConfigurationsRequest added in v1.3.7

type AccountConfigurationsRequest struct {
	DtbpCheck            *string `json:"dtbp_check"`
	NoShorting           *bool   `json:"no_shorting"`
	TradeConfirmEmail    *string `json:"trade_confirm_email"`
	TradeSuspendedByUser *bool   `json:"trade_suspended_by_user"`
}

type AggV2 added in v1.5.0

type AggV2 struct {
	Timestamp     int64   `json:"t"`
	Ticker        string  `json:"T"`
	Open          float32 `json:"O"`
	High          float32 `json:"H"`
	Low           float32 `json:"L"`
	Close         float32 `json:"C"`
	Volume        int32   `json:"V"`
	NumberOfItems int     `json:"n"`
}

type Aggregates added in v1.5.0

type Aggregates struct {
	Ticker       string  `json:"ticker"`
	Status       string  `json:"status"`
	Adjusted     bool    `json:"adjusted"`
	QueryCount   int     `json:"queryCount"`
	ResultsCount int     `json:"resultsCount"`
	Results      []AggV2 `json:"results"`
}

func GetAggregates added in v1.5.0

func GetAggregates(symbol, timespan, from, to string) (*Aggregates, error)

GetAggregates returns the bars for the given symbol, timespan and date-range

type Asset

type Asset struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Exchange     string `json:"exchange"`
	Class        string `json:"asset_class"`
	Symbol       string `json:"symbol"`
	Status       string `json:"status"`
	Tradable     bool   `json:"tradable"`
	Marginable   bool   `json:"marginable"`
	Shortable    bool   `json:"shortable"`
	EasyToBorrow bool   `json:"easy_to_borrow"`
}

func GetAsset

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

GetAsset returns an asset for the given symbol with the default Alpaca client.

func ListAssets

func ListAssets(status *string) ([]Asset, error)

ListAssets returns the list of assets, filtered by the input parameters with the default Alpaca client.

type Bar

type Bar struct {
	Time   int64   `json:"t"`
	Open   float32 `json:"o"`
	High   float32 `json:"h"`
	Low    float32 `json:"l"`
	Close  float32 `json:"c"`
	Volume int32   `json:"v"`
}

func GetSymbolBars added in v1.1.0

func GetSymbolBars(symbol string, opts ListBarParams) ([]Bar, error)

GetSymbolBars returns a list of bars corresponding to the provided symbol that is filtered by the provided parameters with the default Alpaca client.

func (*Bar) GetTime added in v1.1.0

func (bar *Bar) GetTime() time.Time

type CalendarDay

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

func GetCalendar

func GetCalendar(start, end *string) ([]CalendarDay, error)

GetCalendar returns the market calendar, sliced by the start and end dates using the default Alpaca client.

type Client

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

Client is an Alpaca REST API client

func NewClient

func NewClient(credentials *common.APIKey) *Client

NewClient creates a new Alpaca client with specified credentials

func (*Client) CancelAllOrders added in v1.3.0

func (c *Client) CancelAllOrders() error

CancelAllOrders submits a request to cancel an open order.

func (*Client) CancelOrder

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

CancelOrder submits a request to cancel an open order.

func (*Client) CloseAllPositions added in v1.3.1

func (c *Client) CloseAllPositions() error

CloseAllPositions liquidates all open positions at market price.

func (*Client) ClosePosition added in v1.3.1

func (c *Client) ClosePosition(symbol string) error

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

func (*Client) GetAccount

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

GetAccount returns the user's account information.

func (*Client) GetAccountActivities added in v1.3.8

func (c *Client) GetAccountActivities(activityType *string, opts *AccountActivitiesRequest) ([]AccountActivity, error)

func (*Client) GetAccountConfigurations added in v1.3.7

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

GetConfigs returns the current account configurations

func (*Client) GetAggregates added in v1.5.0

func (c *Client) GetAggregates(symbol, timespan, from, to string) (*Aggregates, error)

GetAggregates returns the bars for the given symbol, timespan and date-range

func (*Client) GetAsset

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

GetAsset returns an asset for the given symbol.

func (*Client) GetBars added in v1.8.0

func (c *Client) GetBars(
	symbol string, timeFrame v2.TimeFrame, adjustment v2.Adjustment,
	start, end time.Time, limit int,
) <-chan v2.BarItem

GetBars returns a channel that will be populated with the bars for the given symbol between the given start and end times, limited to the given limit, using the given and timeframe and adjustment.

func (*Client) GetCalendar

func (c *Client) GetCalendar(start, end *string) ([]CalendarDay, error)

GetCalendar returns the market calendar, sliced by the start and end dates.

func (*Client) GetClock

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

GetClock returns the current market clock.

func (*Client) GetLastQuote added in v1.5.0

func (c *Client) GetLastQuote(symbol string) (*LastQuoteResponse, error)

GetLastQuote returns the last quote for the given symbol

func (*Client) GetLastTrade added in v1.5.0

func (c *Client) GetLastTrade(symbol string) (*LastTradeResponse, error)

GetLastTrade returns the last trade for the given symbol

func (*Client) GetLatestQuote added in v1.8.2

func (c *Client) GetLatestQuote(symbol string) (*v2.Quote, error)

GetLatestQuote returns the latest quote for a given symbol

func (*Client) GetLatestTrade added in v1.8.2

func (c *Client) GetLatestTrade(symbol string) (*v2.Trade, error)

GetLatestTrade returns the latest trade for a given symbol

func (*Client) GetOrder added in v1.1.2

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

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

func (*Client) GetOrderByClientOrderID added in v1.7.0

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

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

func (*Client) GetPortfolioHistory added in v1.3.14

func (c *Client) GetPortfolioHistory(period *string, timeframe *RangeFreq, dateEnd *time.Time, extendedHours bool) (*PortfolioHistory, error)

func (*Client) GetPosition

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

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

func (*Client) GetQuotes added in v1.8.0

func (c *Client) GetQuotes(symbol string, start, end time.Time, limit int) <-chan v2.QuoteItem

GetQuotes returns a channel that will be populated with the quotes for the given symbol that happened between the given start and end times, limited to the given limit.

func (*Client) GetSnapshot added in v1.8.2

func (c *Client) GetSnapshot(symbol string) (*v2.Snapshot, error)

GetSnapshot returns the snapshot for a given symbol

func (*Client) GetSnapshots added in v1.8.2

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

GetSnapshots returns the snapshots for multiple symbol

func (*Client) GetSymbolBars added in v1.1.0

func (c *Client) GetSymbolBars(symbol string, opts ListBarParams) ([]Bar, error)

GetSymbolBars is a convenience method for getting the market data for one symbol

func (*Client) GetTrades added in v1.8.0

func (c *Client) GetTrades(symbol string, start, end time.Time, limit int) <-chan v2.TradeItem

GetTrades returns a channel that will be populated with the trades for the given symbol that happened between the given start and end times, limited to the given limit.

func (*Client) ListAssets

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

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

func (*Client) ListBars added in v1.1.0

func (c *Client) ListBars(symbols []string, opts ListBarParams) (map[string][]Bar, error)

ListBars returns a list of bar lists corresponding to the provided symbol list, and filtered by the provided parameters.

func (*Client) ListOrders

func (c *Client) ListOrders(status *string, until *time.Time, limit *int, nested *bool) ([]Order, error)

ListOrders returns the list of orders for an account, filtered by the input parameters.

func (*Client) ListPositions

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

ListPositions lists the account's open positions.

func (*Client) PlaceOrder

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

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

func (*Client) ReplaceOrder added in v1.3.7

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

ReplaceOrder submits a request to replace an order by id

func (*Client) UpdateAccountConfigurations added in v1.3.7

func (c *Client) UpdateAccountConfigurations(newConfigs AccountConfigurationsRequest) (*AccountConfigurations, error)

EditConfigs patches the account configs

type ClientMsg

type ClientMsg struct {
	Action string      `json:"action" msgpack:"action"`
	Data   interface{} `json:"data" msgpack:"data"`
}

ClientMsg is the standard message sent by clients of the stream interface

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 using the default Alpaca client.

type DtbpCheck added in v1.3.7

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

type Fundamental

type Fundamental struct {
	AssetID           string          `json:"asset_id"`
	Symbol            string          `json:"symbol"`
	FullName          string          `json:"full_name"`
	IndustryName      string          `json:"industry_name"`
	IndustryGroup     string          `json:"industry_group"`
	Sector            string          `json:"sector"`
	PERatio           float32         `json:"pe_ratio"`
	PEGRatio          float32         `json:"peg_ratio"`
	Beta              float32         `json:"beta"`
	EPS               float32         `json:"eps"`
	MarketCap         int64           `json:"market_cap"`
	SharesOutstanding int64           `json:"shares_outstanding"`
	AvgVol            int64           `json:"avg_vol"`
	DivRate           float32         `json:"div_rate"`
	ROE               float32         `json:"roe"`
	ROA               float32         `json:"roa"`
	PS                float32         `json:"ps"`
	PC                float32         `json:"pc"`
	GrossMargin       float32         `json:"gross_margin"`
	FiftyTwoWeekHigh  decimal.Decimal `json:"fifty_two_week_high"`
	FiftyTwoWeekLow   decimal.Decimal `json:"fifty_two_week_low"`
	ShortDescription  string          `json:"short_description"`
	LongDescription   string          `json:"long_description"`
}

type LastQuote added in v1.5.0

type LastQuote struct {
	AskPrice    float32 `json:"askprice"`
	AskSize     int32   `json:"asksize"`
	AskExchange int     `json:"askexchange"`
	BidPrice    float32 `json:"bidprice"`
	BidSize     int32   `json:"bidsize"`
	BidExchange int     `json:"bidexchange"`
	Timestamp   int64   `json:"timestamp"`
}

func (*LastQuote) Time added in v1.5.0

func (l *LastQuote) Time() time.Time

type LastQuoteResponse added in v1.5.0

type LastQuoteResponse struct {
	Status string    `json:"status"`
	Symbol string    `json:"symbol"`
	Last   LastQuote `json:"last"`
}

func GetLastQuote added in v1.5.0

func GetLastQuote(symbol string) (*LastQuoteResponse, error)

GetLastQuote returns the last quote for the given symbol

type LastTrade added in v1.5.0

type LastTrade struct {
	Price     float32 `json:"price"`
	Size      int32   `json:"size"`
	Exchange  int     `json:"exchange"`
	Cond1     int     `json:"cond1"`
	Cond2     int     `json:"cond2"`
	Cond3     int     `json:"cond3"`
	Cond4     int     `json:"cond4"`
	Timestamp int64   `json:"timestamp"`
}

func (*LastTrade) Time added in v1.5.0

func (l *LastTrade) Time() time.Time

type LastTradeResponse added in v1.5.0

type LastTradeResponse struct {
	Status string    `json:"status"`
	Symbol string    `json:"symbol"`
	Last   LastTrade `json:"last"`
}

func GetLastTrade added in v1.5.0

func GetLastTrade(symbol string) (*LastTradeResponse, error)

GetLastTrade returns the last trade for the given symbol

type ListBarParams added in v1.1.0

type ListBarParams struct {
	Timeframe string     `url:"timeframe,omitempty"`
	StartDt   *time.Time `url:"start_dt,omitempty"`
	EndDt     *time.Time `url:"end_dt,omitempty"`
	Limit     *int       `url:"limit,omitempty"`
}

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"`
	Replaces       *string          `json:"replaces"`
	ReplacedBy     *string          `json:"replaced_by"`
	AssetID        string           `json:"asset_id"`
	Symbol         string           `json:"symbol"`
	Exchange       string           `json:"exchange"`
	Class          string           `json:"asset_class"`
	Qty            decimal.Decimal  `json:"qty"`
	Notional       decimal.Decimal  `json:"notional"`
	FilledQty      decimal.Decimal  `json:"filled_qty"`
	Type           OrderType        `json:"order_type"`
	Side           Side             `json:"side"`
	TimeInForce    TimeInForce      `json:"time_in_force"`
	LimitPrice     *decimal.Decimal `json:"limit_price"`
	FilledAvgPrice *decimal.Decimal `json:"filled_avg_price"`
	StopPrice      *decimal.Decimal `json:"stop_price"`
	TrailPrice     *decimal.Decimal `json:"trail_price"`
	TrailPercent   *decimal.Decimal `json:"trail_percent"`
	Hwm            *decimal.Decimal `json:"hwm"`
	Status         string           `json:"status"`
	ExtendedHours  bool             `json:"extended_hours"`
	Legs           *[]Order         `json:"legs"`
}

func GetOrder added in v1.1.2

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

GetOrder returns a single order for the given `orderID` using the default Alpaca client.

func GetOrderByClientOrderID added in v1.7.0

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

GetOrderByClientOrderID returns a single order for the given `clientOrderID` using the default Alpaca client.

func ListOrders

func ListOrders(status *string, until *time.Time, limit *int, nested *bool) ([]Order, error)

ListOrders returns the list of orders for an account, filtered by the input parameters using the default Alpaca client.

func PlaceOrder

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

PlaceOrder submits an order request to buy or sell an asset with the default Alpaca client.

func ReplaceOrder added in v1.3.7

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

ReplaceOrder changes an order by order id using the default Alpaca client.

type OrderAttributes added in v1.3.10

type OrderAttributes struct {
	TakeProfitLimitPrice *decimal.Decimal `json:"take_profit_limit_price,omitempty"`
	StopLossStopPrice    *decimal.Decimal `json:"stop_loss_stop_price,omitempty"`
	StopLossLimitPrice   *decimal.Decimal `json:"stop_loss_limit_price,omitempty"`
}

type OrderClass added in v1.3.10

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 {
	AccountID     string           `json:"-"`
	AssetKey      *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"`
}

func (PlaceOrderRequest) MarshalJSON added in v1.8.2

func (req PlaceOrderRequest) MarshalJSON() ([]byte, error)

type PortfolioHistory added in v1.3.14

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     RangeFreq         `json:"timeframe"`
	Timestamp     []int64           `json:"timestamp"`
}

func GetPortfolioHistory added in v1.3.14

func GetPortfolioHistory(period *string, timeframe *RangeFreq, dateEnd *time.Time, extendedHours bool) (*PortfolioHistory, error)

type Position

type Position struct {
	AssetID        string           `json:"asset_id"`
	Symbol         string           `json:"symbol"`
	Exchange       string           `json:"exchange"`
	Class          string           `json:"asset_class"`
	AccountID      string           `json:"account_id"`
	EntryPrice     decimal.Decimal  `json:"avg_entry_price"`
	Qty            decimal.Decimal  `json:"qty"`
	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"`
	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 using the default Alpaca client.

func ListPositions

func ListPositions() ([]Position, error)

ListPositions lists the account's open positions using the default Alpaca client.

type RangeFreq added in v1.3.14

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

type ReplaceOrderRequest added in v1.3.7

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 ServerMsg

type ServerMsg struct {
	Stream string      `json:"stream" msgpack:"stream"`
	Data   interface{} `json:"data"`
}

ServerMsg is the standard message sent by the server to update clients of the stream interface

type Side

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

type StopLoss added in v1.3.13

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

type Stream

type Stream struct {
	sync.Mutex
	sync.Once
	// contains filtered or unexported fields
}

func GetDataStream added in v1.5.0

func GetDataStream() *Stream

func GetStream

func GetStream() *Stream

GetStream returns the singleton Alpaca stream structure.

func (*Stream) Close

func (s *Stream) Close() error

Close gracefully closes the Alpaca stream.

func (*Stream) Subscribe

func (s *Stream) Subscribe(channel string, handler func(msg interface{})) (err error)

Subscribe to the specified Alpaca stream channel.

func (*Stream) Unsubscribe added in v1.7.0

func (s *Stream) Unsubscribe(channel string) (err error)

Unsubscribe the specified Polygon stream channel.

type StreamAgg added in v1.5.0

type StreamAgg struct {
	Event             string  `json:"ev"`
	Symbol            string  `json:"T"`
	Open              float32 `json:"o"`
	High              float32 `json:"h"`
	Low               float32 `json:"l"`
	Close             float32 `json:"c"`
	Volume            int32   `json:"v"`
	Start             int64   `json:"s"`
	End               int64   `json:"e"`
	OpenPrice         float32 `json:"op"`
	AccumulatedVolume int32   `json:"av"`
	VWAP              float32 `json:"vw"`
}

func (*StreamAgg) Time added in v1.5.0

func (s *StreamAgg) Time() time.Time

type StreamQuote added in v1.5.0

type StreamQuote struct {
	Event       string  `json:"ev"`
	Symbol      string  `json:"T"`
	BidPrice    float32 `json:"p"`
	BidSize     int32   `json:"s"`
	BidExchange int     `json:"x"`
	AskPrice    float32 `json:"P"`
	AskSize     int32   `json:"S"`
	AskExchange int     `json:"X"`
	Timestamp   int64   `json:"t"`
}

func (*StreamQuote) Time added in v1.5.0

func (s *StreamQuote) Time() time.Time

type StreamTrade added in v1.5.0

type StreamTrade struct {
	Event      string  `json:"ev"`
	Symbol     string  `json:"T"`
	TradeID    string  `json:"i"`
	Exchange   int     `json:"x"`
	Price      float32 `json:"p"`
	Size       int32   `json:"s"`
	Timestamp  int64   `json:"t"`
	Conditions []int   `json:"c"`
	TapeID     int     `json:"z"`
}

func (*StreamTrade) Time added in v1.5.0

func (s *StreamTrade) Time() time.Time

type TakeProfit added in v1.3.13

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

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 added in v1.3.7

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

type TradeUpdate added in v1.2.0

type TradeUpdate struct {
	Event string `json:"event"`
	Order Order  `json:"order"`
}

Jump to

Keyboard shortcuts

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