stocks

package
v0.0.0-...-740a42e Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2014 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DateTimeNull = NullDateTime{Valid: false}
View Source
var DecimalNull = NullDecimal{Value: nil, Valid: false}
View Source
var LocNY, _ = time.LoadLocation("America/New_York")

Get the New York location for stock timezone:

Functions

func FloatToRat

func FloatToRat(v float64) *big.Rat

func IntToRat

func IntToRat(v int64) *big.Rat

func IsWeekend

func IsWeekend(date time.Time) bool

Check if the date is on a weekend:

func RatToFloat

func RatToFloat(v *big.Rat) float64

func ToRat

func ToRat(v string) *big.Rat

Converts a string into a `*big.Rat` which is an arbitrary precision rational number stored in decimal format

func TruncDate

func TruncDate(t time.Time) time.Time

remove the time component of a datetime to get just a date at 00:00:00

Types

type API

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

Our API context struct:

func NewAPI

func NewAPI(dbPath string) (api *API, err error)

Opens the DB and creates the table schema (if not exists):

func (*API) AddStock

func (api *API) AddStock(s *Stock) (err error)

Add a stock for UserID:

func (*API) AddUser

func (api *API) AddUser(user *User) (err error)

func (*API) Close

func (api *API) Close()

Releases all API resources:

func (*API) CurrentHour

func (api *API) CurrentHour() time.Time

func (*API) DeleteHistory

func (api *API) DeleteHistory(symbol string)

Deletes all historical and statistical data for a symbol.

func (*API) GetAllTrackedSymbols

func (api *API) GetAllTrackedSymbols() (symbols []string, err error)

Gets all actively tracked stock symbols (owned or watching):

func (*API) GetCurrentHourlyPrices

func (api *API) GetCurrentHourlyPrices(force bool, symbols ...string) (prices map[string]Decimal)

Checks if the current hourly price has been fetched from Yahoo or not and fetches it into the StockHourly table if needed.

func (*API) GetLastTradeDay

func (api *API) GetLastTradeDay(symbol string) (date DateTime, tradeDay int64, err error)

Gets the last date trading occurred for a stock symbol.

func (*API) GetMinBuyDate

func (api *API) GetMinBuyDate(symbol string) NullDateTime

Get the earliest buy date for a symbol.

func (*API) GetStock

func (api *API) GetStock(stockID StockID) (s *Stock, err error)

Gets a stock by ID:

func (*API) GetStockDetailsForSymbol

func (api *API) GetStockDetailsForSymbol(symbol string) (details []StockDetail, err error)

func (*API) GetStockDetailsForUser

func (api *API) GetStockDetailsForUser(userID UserID) (details []StockDetail, err error)

func (*API) GetUser

func (api *API) GetUser(userID UserID) (user *User, err error)

func (*API) GetUserByEmail

func (api *API) GetUserByEmail(email string) (user *User, err error)

func (*API) LastTradingDate

func (api *API) LastTradingDate() time.Time

func (*API) RecordHistory

func (api *API) RecordHistory(symbol string)

Fetches historical data from Yahoo Finance into the database.

func (*API) RemoveStock

func (api *API) RemoveStock(stockID StockID) (err error)

Removes a stock:

func (*API) Today

func (api *API) Today() time.Time

func (*API) UpdateNotifyTimes

func (api *API) UpdateNotifyTimes(n *Stock) (err error)

Only updates last notification times:

func (*API) UpdateStock

func (api *API) UpdateStock(n *Stock) (err error)

Only updates notify flag columns:

type DateTime

type DateTime struct {
	Value time.Time
}

func ToDateTime

func ToDateTime(format, s string) DateTime

func (DateTime) DateString

func (d DateTime) DateString() string

func (DateTime) Format

func (d DateTime) Format(format string) string

func (DateTime) MarshalJSON

func (d DateTime) MarshalJSON() ([]byte, error)

func (DateTime) String

func (d DateTime) String() string

func (*DateTime) UnmarshalJSON

func (d *DateTime) UnmarshalJSON(data []byte) error

type Decimal

type Decimal struct {
	Value *big.Rat
}

func ToDecimal

func ToDecimal(v string) Decimal

func (Decimal) CurrencyString

func (d Decimal) CurrencyString() string

func (Decimal) MarshalJSON

func (d Decimal) MarshalJSON() ([]byte, error)

func (Decimal) String

func (d Decimal) String() string

func (*Decimal) UnmarshalJSON

func (d *Decimal) UnmarshalJSON(data []byte) error

type Detail

type Detail struct {
	CurrPrice       NullDecimal
	CurrHour        NullDateTime
	FetchedDateTime NullDateTime

	N1CloseDate  NullDateTime
	N1ClosePrice NullDecimal
	N1SMAPercent NullFloat64
	N1Avg200Day  NullFloat64
	N1Avg50Day   NullFloat64

	N2CloseDate  NullDateTime
	N2ClosePrice NullDecimal
	N2SMAPercent NullFloat64

	TStopPrice      NullDecimal
	GainLossPercent NullFloat64
	GainLossDollar  NullDecimal
}

type Float64

type Float64 struct {
	Value float64
}

func (Float64) MarshalJSON

func (d Float64) MarshalJSON() ([]byte, error)

func (Float64) String

func (d Float64) String() string

func (*Float64) UnmarshalJSON

func (d *Float64) UnmarshalJSON(data []byte) error

type NullDateTime

type NullDateTime struct {
	Value time.Time
	// TODO: store format here too.
	Valid bool
}

func ToNullDateTime

func ToNullDateTime(format, s string) NullDateTime

func (NullDateTime) Format

func (d NullDateTime) Format(format string) string

func (NullDateTime) MarshalJSON

func (d NullDateTime) MarshalJSON() ([]byte, error)

func (NullDateTime) String

func (d NullDateTime) String() string

func (*NullDateTime) UnmarshalJSON

func (d *NullDateTime) UnmarshalJSON(data []byte) error

type NullDecimal

type NullDecimal struct {
	Value *big.Rat
	// TODO: store precision here too.
	Valid bool
}

func ToNullDecimal

func ToNullDecimal(v string) NullDecimal

func (NullDecimal) CurrencyString

func (d NullDecimal) CurrencyString() string

func (NullDecimal) MarshalJSON

func (d NullDecimal) MarshalJSON() ([]byte, error)

func (NullDecimal) String

func (d NullDecimal) String() string

func (*NullDecimal) UnmarshalJSON

func (d *NullDecimal) UnmarshalJSON(data []byte) error

type NullFloat64

type NullFloat64 struct {
	Value float64
	Valid bool
}

func ToNullFloat64

func ToNullFloat64(v string) NullFloat64

func (NullFloat64) MarshalJSON

func (d NullFloat64) MarshalJSON() ([]byte, error)

func (NullFloat64) String

func (d NullFloat64) String() string

func (*NullFloat64) UnmarshalJSON

func (d *NullFloat64) UnmarshalJSON(data []byte) error

type Stock

type Stock struct {
	StockID   StockID
	UserID    UserID
	Symbol    string
	BuyDate   DateTime
	BuyPrice  Decimal
	Shares    int64
	IsWatched bool // false = owned, true = watched

	TStopPercent     NullDecimal
	BuyStopPrice     NullDecimal
	SellStopPrice    NullDecimal
	RisePercent      NullDecimal
	FallPercent      NullDecimal
	NotifyTStop      bool
	NotifyBuyStop    bool
	NotifySellStop   bool
	NotifyRise       bool
	NotifyFall       bool
	NotifyBullBear   bool
	LastTimeTStop    NullDateTime
	LastTimeBuyStop  NullDateTime
	LastTimeSellStop NullDateTime
	LastTimeRise     NullDateTime
	LastTimeFall     NullDateTime
	LastTimeBullBear NullDateTime
}

A stock owned/watched by UserID.

type StockDetail

type StockDetail struct {
	Stock  Stock
	Detail Detail
}

A stock with calculated stats:

type StockID

type StockID int64

type User

type User struct {
	UserID UserID
	Name   string
	Emails []UserEmail

	NotificationTimeout time.Duration
}

func (*User) PrimaryEmail

func (u *User) PrimaryEmail() string

type UserEmail

type UserEmail struct {
	Email     string
	UserID    UserID
	IsPrimary bool
}

type UserID

type UserID int64

Jump to

Keyboard shortcuts

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