aastocks

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 11 Imported by: 0

README

aastocks : AAStocks financial market data extractor

Overview

GoDoc Go Report Card codecov

AAStocks financial market data extractor

Install

go get github.com/horacehylee/aastocks

License

MIT.

Documentation

Overview

Package aastocks is an extractor for AAStocks financial market data.

Quote

Quote can be fetched from AAStocks with its symbol.

quote, err := aastocks.Get("00006")
if err != nil {
	logger.Fatal(err)
}
... Use quote to get its financial data (i.e. for its dividends and historical price).

Real Time Prices

Prices can be served in real time by polling AAStocks for its price. Context can be used to control and stop the real time prices.

priceChan, errChan := quote.ServePrice(context.Background(), 5*time.Second)
for {
select {
	case p := <-priceChan:
		logger.Printf("price: %v\n", p)
	case err = <-errChan:
		logger.Printf("error: %v\n", err)
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dividend

type Dividend struct {
	AnnounceDate time.Time
	YearEnded    time.Time
	Event        string
	Particular   string
	Type         string
	ExDate       time.Time
	PayableDate  time.Time
}

Dividend fetched from AAStocks

type HistoricalPrice

type HistoricalPrice struct {
	Time  time.Time
	Open  float64
	High  float64
	Low   float64
	Close float64
}

HistoricalPrice is the historical price of quote.

type Option

type Option func(q *Quote)

Option for getting symbol from AAStocks

func WithClient

func WithClient(client *http.Client) Option

WithClient to customize the HTTP client used for AAStocks

type PriceFrequency

type PriceFrequency int

PriceFrequency is the frequency of historical data to be provided.

const (
	// Hourly price frequency
	Hourly PriceFrequency = 23
	// Daily price frequency
	Daily PriceFrequency = 56
	// Weekly price frequency
	Weekly PriceFrequency = 67
	// Monthly price frequency
	Monthly PriceFrequency = 68
)

type PriceResult

type PriceResult struct {
	Price  float64
	Symbol string
	Time   time.Time
}

PriceResult is the result of serving real time prices.

type Quote

type Quote struct {
	Symbol     string
	Name       string
	Price      float64
	Yield      float64
	PeRatio    float64
	PbRatio    float64
	Lots       int
	Eps        float64
	UpdateTime time.Time
	// contains filtered or unexported fields
}

Quote of AAStocks data

func Get

func Get(symbol string, opts ...Option) (*Quote, error)

Get quote from AAStocks with symbol

func (*Quote) Dividends

func (q *Quote) Dividends() ([]Dividend, error)

Dividends of the quote from AAStocks

func (*Quote) HistoricalPrices

func (q *Quote) HistoricalPrices(frequency PriceFrequency) ([]HistoricalPrice, error)

HistoricalPrices fetches historical price of the quote from AAStocks.

func (*Quote) Refresh

func (q *Quote) Refresh() error

Refresh quote details

func (*Quote) ServePrices

func (q *Quote) ServePrices(ctx context.Context, delay time.Duration) (<-chan PriceResult, <-chan error)

ServePrices continuously fetching latest price from AAStocks. It will start goroutine to fetch real time prices.

Jump to

Keyboard shortcuts

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