client

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Client is a simple client for testing out the Alpaca and Polygon APIs.

This client relies on a TOML config file located at ~/.alpaca.toml that looks like this:

alpaca apiKeyID="abc...xyz" apiSecretKey="abc...xyz"

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSymbols

func GetSymbols(allSymbols string) []string

GetSymbols splits the comma-separated symbol list and upcases the names.

Types

type Client

type Client struct {
	AClient *alpaca.Client
	PClient *polygon.Client
	AStream *alpaca.Stream
	PStream *polygon.Stream
}

Client contains an Alpaca v2 and Polygon v2 API client. Client implements the API interface.

func New

func New() (*Client, error)

New returns a new Client.

Config values are read from ${HOME}/.alpaca.toml See above.

func (*Client) CancelAllOrders

func (c *Client) CancelAllOrders() error

func (*Client) CancelOrder

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

func (*Client) Close

func (c *Client) Close() error

Close closes the stream connection.

func (*Client) CloseAllPositions

func (c *Client) CloseAllPositions() error

func (*Client) ClosePosition

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

func (*Client) GetAccount

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

Alpaca v2

func (*Client) GetAccountActivities

func (c *Client) GetAccountActivities(activityType *string, opts *alpaca.AccountActivitiesRequest) ([]alpaca.AccountActvity, error)

func (*Client) GetAccountConfigurations

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

func (*Client) GetAggregates

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

func (*Client) GetAsset

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

func (*Client) GetCalendar

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

func (*Client) GetClock

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

func (*Client) GetHistoricAggregatesV2

func (c *Client) GetHistoricAggregatesV2(
	symbol string,
	multiplier int,
	resolution polygon.AggType,
	from, to *time.Time,
	unadjusted *bool) (*polygon.HistoricAggregatesV2, error)

Polygon v2

func (*Client) GetHistoricQuotesV2

func (c *Client) GetHistoricQuotesV2(ticker string, date string, opts *polygon.HistoricTicksV2Params) (*polygon.HistoricQuotesV2, error)

func (*Client) GetHistoricTradesV2

func (c *Client) GetHistoricTradesV2(ticker string, date string, opts *polygon.HistoricTicksV2Params) (*polygon.HistoricTradesV2, error)

func (*Client) GetLastQuote

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

func (*Client) GetLastTrade

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

func (*Client) GetOrder

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

func (*Client) GetPortfolioHistory

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

func (*Client) GetPosition

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

func (*Client) GetPreviousClose

func (c *Client) GetPreviousClose(symbol string) (*polygon.PreviousCloseV2, error)

func (*Client) GetStockExchanges

func (c *Client) GetStockExchanges() ([]polygon.StockExchange, error)

func (*Client) GetSymbolBars

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

func (*Client) ListAssets

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

func (*Client) ListBars

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

func (*Client) ListOrders

func (c *Client) ListOrders(opts alpaca.ListOrdersOptions) ([]alpaca.Order, error)

func (*Client) ListPositions

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

func (*Client) NewAccountHandler

func (c *Client) NewAccountHandler(handler api.AccountHandler) error

NewAccountHandler creates a new account handler.

func (*Client) NewMinuteBarHandler

func (c *Client) NewMinuteBarHandler(symbol string, handler api.MinuteBarHandler) error

NewMinuteBarHandler creates a new minuteBar handler.

func (*Client) NewOrderHandler

func (c *Client) NewOrderHandler(handler api.OrderHandler) error

NewOrderHandler creates a new order handler.

func (*Client) NewQuoteHandler

func (c *Client) NewQuoteHandler(symbol string, handler api.QuoteHandler) error

NewQuoteHandler creates a new quote handler.

func (*Client) NewSecondBarHandler

func (c *Client) NewSecondBarHandler(symbol string, handler api.SecondBarHandler) error

NewSecondBarHandler creates a new secondBar handler.

func (*Client) NewTradeHandler

func (c *Client) NewTradeHandler(symbol string, handler api.TradeHandler) error

NewTradeHandler creates a new trade handler.

func (*Client) PlaceOrder

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

func (*Client) ReplaceOrder

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

func (*Client) StartStreams

func (c *Client) StartStreams(symbols []string, handlerGetter api.HandlerGetter) (<-chan struct{}, error)

StartStreams starts the data streams using the specified source.

symbols is a slice of upper-case symbol names to stream.

handlerGetter gets the handlers for the various streams.

The provided channel is sent an empty struct when the stream ends. For "paper" or "live", the stream ends at 4pm ET. For a filename source, the stream ends at the end of the file.

func (*Client) UpdateAccountConfigurations

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

Jump to

Keyboard shortcuts

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