Documentation ¶
Overview ¶
Package finance implements a growing set of financial data retrieval functions. It aims to provide a clean, flexible, and easy way to pull in basic financial markets quotes and information for analytical purposes.
Features ¶
- Single security quotes
- Multiple security quotes
- Historical quotes in custom time frames and intervals
- Dividend and Split history
- FX pair quotes for all major pairs
- Option chains for multiple future expiration dates
- Updating symbols list of traded US Equities
Index ¶
- Constants
- func GetUSEquitySymbols() ([]string, error)
- type Bar
- type Event
- type Expiration
- type FXPairQuote
- type Interval
- type Option
- type OptionChain
- func (chain *OptionChain) GetCallsForExpiration(e *Expiration) (calls []*Option, err error)
- func (chain *OptionChain) GetExpirations() []*Expiration
- func (chain *OptionChain) GetOptionsExpiringNext() (calls []*Option, puts []*Option, err error)
- func (chain *OptionChain) GetOptionsForExpiration(e *Expiration) (calls []*Option, puts []*Option, err error)
- func (chain *OptionChain) GetPutsForExpiration(e *Expiration) (puts []*Option, err error)
- func (chain *OptionChain) GetStrikes() (strikes []decimal.Decimal, err error)
- type Quote
Constants ¶
const ( // Dividend constant. Dividend = "DIVIDEND" // Split constant. Split = "SPLIT" )
const ( // IntervalDaily daily interval. IntervalDaily = "d" // IntervalWeekly weekly interval. IntervalWeekly = "w" // IntervalMonthly monthly interval. IntervalMonthly = "m" )
const ( // USDGBP pair. USDGBP = "USDGBP=X" // USDEUR pair. USDEUR = "USDEUR=X" // USDAUD pair. USDAUD = "USDAUD=X" // USDCHF pair. USDCHF = "USDCHF=X" // USDJPY pair. USDJPY = "USDJPY=X" // USDCAD pair. USDCAD = "USDCAD=X" // USDSGD pair. USDSGD = "USDSGD=X" // USDNZD pair. USDNZD = "USDNZD=X" // USDHKD pair. USDHKD = "USDHKD=X" // GBPUSD pair. GBPUSD = "GBPUSD=X" // GBPEUR pair. GBPEUR = "GBPEUR=X" // GBPAUD pair. GBPAUD = "GBPAUD=X" // GBPCHF pair. GBPCHF = "GBPCHF=X" // GBPJPY pair. GBPJPY = "GBPJPY=X" // GBPCAD pair. GBPCAD = "GBPCAD=X" // GBPSGD pair. GBPSGD = "GBPSGD=X" // GBPNZD pair. GBPNZD = "GBPNZD=X" // GBPHKD pair. GBPHKD = "GBPHKD=X" // EURUSD pair. EURUSD = "EURUSD=X" // EURGBP pair. EURGBP = "EURGBP=X" // EURAUD pair. EURAUD = "EURAUD=X" // EURCHF pair. EURCHF = "EURCHF=X" // EURJPY pair. EURJPY = "EURJPY=X" // EURCAD pair. EURCAD = "EURCAD=X" // EURSGD pair. EURSGD = "EURSGD=X" // EURNZD pair. EURNZD = "EURNZD=X" // EURHKD pair. EURHKD = "EURHKD=X" // AUDUSD pair. AUDUSD = "AUDUSD=X" // AUDGBP pair. AUDGBP = "AUDGBP=X" // AUDEUR pair. AUDEUR = "AUDEUR=X" // AUDCHF pair. AUDCHF = "AUDCHF=X" // AUDJPY pair. AUDJPY = "AUDJPY=X" // AUDCAD pair. AUDCAD = "AUDCAD=X" // AUDSGD pair. AUDSGD = "AUDSGD=X" // AUDNZD pair. AUDNZD = "AUDNZD=X" // AUDHKD pair. AUDHKD = "AUDHKD=X" // CHFGBP pair. CHFGBP = "CHFGBP=X" // CHFEUR pair. CHFEUR = "CHFEUR=X" // CHFAUD pair. CHFAUD = "CHFAUD=X" // CHFJPY pair. CHFJPY = "CHFJPY=X" // CHFCAD pair. CHFCAD = "CHFCAD=X" // CHFSGD pair. CHFSGD = "CHFSGD=X" // CHFNZD pair. CHFNZD = "CHFNZD=X" // CHFHKD pair. CHFHKD = "CHFHKD=X" // JPYUSD pair. JPYUSD = "JPYUSD=X" // JPYGBP pair. JPYGBP = "JPYGBP=X" // JPYEUR pair. JPYEUR = "JPYEUR=X" // JPYAUD pair. JPYAUD = "JPYAUD=X" // JPYCHF pair. JPYCHF = "JPYCHF=X" // JPYCAD pair. JPYCAD = "JPYCAD=X" // JPYSGD pair. JPYSGD = "JPYSGD=X" // JPYNZD pair. JPYNZD = "JPYNZD=X" // JPYHKD pair. JPYHKD = "JPYHKD=X" // CADUSD pair. CADUSD = "CADUSD=X" // CADGBP pair. CADGBP = "CADGBP=X" // CADEUR pair. CADEUR = "CADEUR=X" // CADAUD pair. CADAUD = "CADAUD=X" // CADCHF pair. CADCHF = "CADCHF=X" // CADJPY pair. CADJPY = "CADJPY=X" // CADSGD pair. CADSGD = "CADSGD=X" // CADNZD pair. CADNZD = "CADNZD=X" // CADHKD pair. CADHKD = "CADHKD=X" // SGDUSD pair. SGDUSD = "SGDUSD=X" // SGDGBP pair. SGDGBP = "SGDGBP=X" // SGDEUR pair. SGDEUR = "SGDEUR=X" // SGDAUD pair. SGDAUD = "SGDAUD=X" // SGDCHF pair. SGDCHF = "SGDCHF=X" // SGDJPY pair. SGDJPY = "SGDJPY=X" // SGDCAD pair. SGDCAD = "SGDCAD=X" // SGDNZD pair. SGDNZD = "SGDNZD=X" // SGDHKD pair. SGDHKD = "SGDHKD=X" // NZDUSD pair. NZDUSD = "NZDUSD=X" // NZDGBP pair. NZDGBP = "NZDGBP=X" // NZDEUR pair. NZDEUR = "NZDEUR=X" // NZDAUD pair. NZDAUD = "NZDAUD=X" // NZDCHF pair. NZDCHF = "NZDCHF=X" // NZDJPY pair. NZDJPY = "NZDJPY=X" // NZDCAD pair. NZDCAD = "NZDCAD=X" // NZDSGD pair. NZDSGD = "NZDSGD=X" // NZDHKD pair. NZDHKD = "NZDHKD=X" // HKDUSD pair. HKDUSD = "HKDUSD=X" // HKDGBP pair. HKDGBP = "HKDGBP=X" // HKDEUR pair. HKDEUR = "HKDEUR=X" // HKDAUD pair. HKDAUD = "HKDAUD=X" // HKDCHF pair. HKDCHF = "HKDCHF=X" // HKDJPY pair. HKDJPY = "HKDJPY=X" // HKDCAD pair. HKDCAD = "HKDCAD=X" // HKDSGD pair. HKDSGD = "HKDSGD=X" // HKDNZD pair. HKDNZD = "HKDNZD=X" )
Variables ¶
This section is empty.
Functions ¶
func GetUSEquitySymbols ¶
GetUSEquitySymbols fetches the symbols available through BATS, ~8k symbols.
Types ¶
type Bar ¶
type Bar struct { Symbol string Date time.Time Open decimal.Decimal High decimal.Decimal Low decimal.Decimal Close decimal.Decimal Volume int AdjClose decimal.Decimal }
Bar represents a single bar(candle) in time-series of quotes.
type Event ¶
type Event struct { Symbol string EventType string Date time.Time DividendAmt decimal.Decimal SplitRatio string }
Event contains one historical event (either a split or a dividend).
type Expiration ¶
type Expiration struct { Month string `json:"m"` Day string `json:"d"` Year string `json:"y"` Date time.Time `json:",omitempty"` }
Expiration is a date for options expiry.
func ExpirationFromDate ¶
func ExpirationFromDate(date time.Time) *Expiration
ExpirationFromDate builds an expiration object from a proper date.
func NewExpiration ¶
func NewExpiration(month, day, year string) *Expiration
NewExpiration builds an expiration object from month-day-year strings.
type FXPairQuote ¶
type FXPairQuote struct { Symbol string PairName string LastTime time.Time LastRate decimal.Decimal ChangeNominal decimal.Decimal ChangePercent decimal.Decimal DayLow decimal.Decimal DayHigh decimal.Decimal FiftyTwoWeekLow decimal.Decimal FiftyTwoWeekHigh decimal.Decimal }
FXPairQuote represents the quote of a currency pair.
func GetCurrencyPairQuote ¶
func GetCurrencyPairQuote(symbol string) (*FXPairQuote, error)
GetCurrencyPairQuote fetches a single currency pair's quote from Yahoo Finance.
type Option ¶
type Option struct { ContractID string Security string Strike decimal.Decimal Price decimal.Decimal ChangeNominal decimal.Decimal ChangePercent decimal.Decimal Bid decimal.Decimal Ask decimal.Decimal Volume int OpenInterest int }
Option represents an instance of an option contract.
type OptionChain ¶
type OptionChain struct { Symbol string UnderlyingPrice decimal.Decimal Expirations []*Expiration }
OptionChain contains the option contracts for a given symbol and expiration.
func NewOptionsChain ¶
func NewOptionsChain(symbol string) (oc *OptionChain, err error)
NewOptionsChain creates a new OptionChain instance.
func (*OptionChain) GetCallsForExpiration ¶
func (chain *OptionChain) GetCallsForExpiration(e *Expiration) (calls []*Option, err error)
GetCallsForExpiration fetches calls for the given expiration date.
func (*OptionChain) GetExpirations ¶
func (chain *OptionChain) GetExpirations() []*Expiration
GetExpirations returns the specified option's expirations
func (*OptionChain) GetOptionsExpiringNext ¶
func (chain *OptionChain) GetOptionsExpiringNext() (calls []*Option, puts []*Option, err error)
GetOptionsExpiringNext fetches calls and puts with the shortest expiration date.
func (*OptionChain) GetOptionsForExpiration ¶
func (chain *OptionChain) GetOptionsForExpiration(e *Expiration) (calls []*Option, puts []*Option, err error)
GetOptionsForExpiration fetches calls and puts for the given expiration date.
func (*OptionChain) GetPutsForExpiration ¶
func (chain *OptionChain) GetPutsForExpiration(e *Expiration) (puts []*Option, err error)
GetPutsForExpiration fetches puts for the given expiration date.
func (*OptionChain) GetStrikes ¶
func (chain *OptionChain) GetStrikes() (strikes []decimal.Decimal, err error)
GetStrikes returns the specified option's strikes.
type Quote ¶
type Quote struct { Symbol string Name string LastTradeTime time.Time LastTradePrice decimal.Decimal LastTradeSize int Ask decimal.Decimal AskSize int Bid decimal.Decimal BidSize int Volume int ChangeNominal decimal.Decimal ChangePercent decimal.Decimal Open decimal.Decimal PreviousClose decimal.Decimal Exchange string DayLow decimal.Decimal DayHigh decimal.Decimal FiftyTwoWeekLow decimal.Decimal FiftyTwoWeekHigh decimal.Decimal Currency string MarketCap string FiftyDayMA decimal.Decimal TwoHundredDayMA decimal.Decimal AvgDailyVolume int FiftyTwoWeekTarget decimal.Decimal ShortRatio decimal.Decimal BookValue decimal.Decimal EBITDA string PriceSales decimal.Decimal PriceBook decimal.Decimal PERatio decimal.Decimal PEGRatio decimal.Decimal DivYield decimal.Decimal DivExDate time.Time DivPayDate time.Time EPS decimal.Decimal EPSEstCurrentYear decimal.Decimal EPSEstNextYear decimal.Decimal EPSEstNextQuarter decimal.Decimal }
Quote is the object that is returned for a quote inquiry.