Version: v0.0.0-...-8c3ffa5 Latest Latest

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

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 12 Imported by: 0



Package monitor provides monitoring of personnanl portfolio of stocks versus market data and statistics, as retrieved from cache/quandl.



This section is empty.


This section is empty.


This section is empty.


type Alert

type Alert func(interface{}) error

Alert is a function that will alert me if special conditions are detected upon checking.

func AlertLog

func AlertLog() Alert

AlertLog will just log the message on stdout.

func AlertSNS

func AlertSNS(snsTopic string) Alert

AlertSNS sends the message to the specified AWS SNS notification topic.

type Check

type Check func(*Monitor) (message string, err error)

Check performs regular checks on the portfolio. If the current situation needs to alert the user, return a message. or an empty string if no message needed, no attention needed. Return non nil error if unable to conduct the check.

func CheckGainLoss

func CheckGainLoss(percent float64) Check

CheckGainLoss provides a check for total value percent change. Percent is expressed as a decimal number, ie 0.3 means 30% change threshold, not 0.3% !

func CheckPriceChange

func CheckPriceChange(ticker string, percent float64) Check

CheckPriceChange alerts if price change more than threshold. Percent is expressed as a decimal number, ie 0.3 means 30% change threshold, not 0.3% !

func CheckPriceChangeAll

func CheckPriceChangeAll(percent float64) Check

CheckPriceChangeAll will check for price change line by line. retun a function that will aggregate the per-ticker functions.

type Measure

type Measure string

Measure specify how to order

type Monitor

type Monitor struct {
	// contains filtered or unexported fields

Monitor allows to monitor share price evolution and send alerts.

func NewMonitor

func NewMonitor(alert Alert, checks ...Check) *Monitor

NewMonitor creates and initialize a new Monitor object. The portfolio is initialized from the configuration file. The cache is created, and the local database created as needed.

func (*Monitor) CheckAll

func (m *Monitor) CheckAll()

CheckAll perform the registred checks and alert if needed.

func (*Monitor) Close

func (m *Monitor) Close() error

Close the Monitor object.

func (*Monitor) LastClosingPrice

func (m *Monitor) LastClosingPrice(ticker string) float64

LastClosingPrice last known closing price (in cache) for ticker.

func (*Monitor) LoadPortfolio

func (m *Monitor) LoadPortfolio() Portfolio

LoadPortfolio constructs and updates a portfolio object from the current Monitor object.

func (*Monitor) NewQuery

func (m *Monitor) NewQuery(ticker string) *Query

NewQuery starts to build a new record query for the provided ticker. If provided ticker is an empty string, cover the entire base.

type Order

type Order string

Order specify the sort order.

type Portfolio

type Portfolio map[string]VLine

Portfolio is a data structure containing current portfolio lines for all tickers.

func (Portfolio) Dump

func (pf Portfolio) Dump()

Dump portfolio

func (Portfolio) Values

func (pf Portfolio) Values() (hist, last float64)

Values calculates the total historical (purchase) and last values of the portfolio.

type Query

type Query struct {

Query is a warpper around gorm.DB

func (*Query) Count

func (q *Query) Count() float64

Count the number of records selected.

func (*Query) Dump

func (q *Query) Dump()

Dump the selected rows. Makes no format assumption

func (*Query) DumpRecords

func (q *Query) DumpRecords()

DumpRecords the selected rows. Assume record format.

func (*Query) Limit

func (q *Query) Limit(n int) *Query

Limit results

func (*Query) Measure

func (q *Query) Measure(ms ...string) *Query

Measure selects any of the provided measures. (Measure are ORed).

func (*Query) MinMax

func (q *Query) MinMax() (min, max float64)

MinMax values for selected query.

func (*Query) OrderDate

func (q *Query) OrderDate(order Order) *Query

OrderDate specify order. Valid Order are : ASC or DESC It is case insensitive. Invalid values are silently ignored.

func (*Query) Select

func (q *Query) Select(fields ...string) *Query

Select manually select fields

func (*Query) Since

func (q *Query) Since(d time.Duration) *Query

Since limit the search from that duration in the past. EX : Since( 30 * 24 * time.Hour) to search past 30 days.

type VLine

type VLine struct {
	LastTurnover float64
	HistTurnover float64
	Volume       float64

VLine is a turnover oriented Line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL