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
- Variables
- func GetUSEquitySymbols() (symbols []string, err error)
- type Bar
- type Contract
- type Datetime
- type Event
- type EventType
- type FXPairQuote
- type Interval
- type OptionsCycle
- func (c *OptionsCycle) GetCallsForExpiration(e Datetime) (calls []Contract, err error)
- func (c *OptionsCycle) GetChainForExpiration(e Datetime) (calls []Contract, puts []Contract, err error)
- func (c *OptionsCycle) GetFrontMonth() (calls []Contract, puts []Contract, err error)
- func (c *OptionsCycle) GetPutsForExpiration(e Datetime) (puts []Contract, err error)
- type Quote
- type Value
Constants ¶
const ( // Day interval. Day = "1d" // Week interval. Week = "1wk" // Month interval. Month = "1mo" // Dividends event type. Dividends = "div" // Splits event type. Splits = "split" )
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 ¶
var ( // OptionsURL option chains OptionsURL = "http://www.google.com/finance/option_chain?" // HistoryURL quote history HistoryURL = "https://query1.finance.yahoo.com/v7/finance/download/" // SymbolsURL symbols list SymbolsURL = "http://www.batstrading.com/market_data/symbol_listing/csv/" // QuoteURL stock quotes QuoteURL = "http://download.finance.yahoo.com/d/quotes.csv" )
Functions ¶
func GetUSEquitySymbols ¶
GetUSEquitySymbols fetches the symbols available through BATS, ~8k symbols.
Types ¶
type Bar ¶
type Bar struct {
Date Datetime
Open decimal.Decimal
High decimal.Decimal
Low decimal.Decimal
Close decimal.Decimal
AdjClose decimal.Decimal
Volume int
Symbol string `yfin:"-"`
}
Bar represents a single bar(candle) in time-series of quotes.
type Contract ¶
type Contract struct {
ID string
Security string
Strike decimal.Decimal
Price decimal.Decimal
Change decimal.Decimal
ChangePercent decimal.Decimal
Bid decimal.Decimal
Ask decimal.Decimal
Volume int
OpenInterest int
}
Contract represents an instance of an option contract.
type Datetime ¶
type Datetime struct {
Month int `json:"m,string"`
Day int `json:"d,string"`
Year int `json:"y,string"`
Hour int `json:",omitempty"`
Minute int `json:",omitempty"`
Second int `json:",omitempty"`
// contains filtered or unexported fields
}
Datetime is a simple time construct.
func NewDatetime ¶
NewDatetime creates a new instance of Datetime.
func ParseDatetime ¶
ParseDatetime creates a new instance of Datetime from a string.
type EventType ¶
type EventType string
EventType is the type of history event, either divs or splits.
type FXPairQuote ¶
type FXPairQuote struct {
Symbol string `yfin:"s"`
PairName string `yfin:"n"`
LastTradeTime Datetime `yfin:"t1"`
LastTradeDate Datetime `yfin:"d1"`
LastRate decimal.Decimal `yfin:"l1"`
ChangeNominal decimal.Decimal `yfin:"c1"`
ChangePercent decimal.Decimal `yfin:"p2"`
DayLow decimal.Decimal `yfin:"g"`
DayHigh decimal.Decimal `yfin:"h"`
FiftyTwoWeekLow decimal.Decimal `yfin:"j"`
FiftyTwoWeekHigh decimal.Decimal `yfin:"k"`
}
FXPairQuote represents the quote of a currency pair.
func GetCurrencyPairQuote ¶
func GetCurrencyPairQuote(symbol string) (fq FXPairQuote, err error)
GetCurrencyPairQuote fetches a single currency pair's quote from Yahoo Finance.
type OptionsCycle ¶
OptionsCycle contains the list of expirations for a symbol.
func NewCycle ¶
func NewCycle(symbol string) (oc OptionsCycle, err error)
NewCycle creates a new OptionsCycle instance.
func (*OptionsCycle) GetCallsForExpiration ¶
func (c *OptionsCycle) GetCallsForExpiration(e Datetime) (calls []Contract, err error)
GetCallsForExpiration fetches calls for the given expiration date.
func (*OptionsCycle) GetChainForExpiration ¶
func (c *OptionsCycle) GetChainForExpiration(e Datetime) (calls []Contract, puts []Contract, err error)
GetChainForExpiration fetches the option chain for the given expiration datetime.
func (*OptionsCycle) GetFrontMonth ¶
func (c *OptionsCycle) GetFrontMonth() (calls []Contract, puts []Contract, err error)
GetFrontMonth fetches the option chain for the front month.
func (*OptionsCycle) GetPutsForExpiration ¶
func (c *OptionsCycle) GetPutsForExpiration(e Datetime) (puts []Contract, err error)
GetPutsForExpiration fetches puts for the given expiration date.
type Quote ¶
type Quote struct {
Symbol string `yfin:"s"`
Name string `yfin:"n"`
LastTradeTime Datetime `yfin:"t1"`
LastTradeDate Datetime `yfin:"d1"`
LastTradePrice decimal.Decimal `yfin:"l1"`
LastTradeSize int `yfin:"k3"`
Ask decimal.Decimal `yfin:"a"`
AskSize int `yfin:"a5"`
Bid decimal.Decimal `yfin:"b"`
BidSize int `yfin:"b6"`
Volume int `yfin:"v"`
ChangeNominal decimal.Decimal `yfin:"c1"`
ChangePercent decimal.Decimal `yfin:"p2"`
Open decimal.Decimal `yfin:"o"`
PreviousClose decimal.Decimal `yfin:"p"`
Exchange string `yfin:"x"`
DayLow decimal.Decimal `yfin:"g"`
DayHigh decimal.Decimal `yfin:"h"`
FiftyTwoWeekLow decimal.Decimal `yfin:"j"`
FiftyTwoWeekHigh decimal.Decimal `yfin:"k"`
Currency string `yfin:"c4"`
MarketCap string `yfin:"j1"`
FiftyDayMA decimal.Decimal `yfin:"m3"`
TwoHundredDayMA decimal.Decimal `yfin:"m4"`
AvgDailyVolume int `yfin:"a2"`
FiftyTwoWeekTarget decimal.Decimal `yfin:"t8"`
ShortRatio decimal.Decimal `yfin:"s7"`
BookValue decimal.Decimal `yfin:"b4"`
EBITDA string `yfin:"j4"`
PriceSales decimal.Decimal `yfin:"p5"`
PriceBook decimal.Decimal `yfin:"p6"`
PERatio decimal.Decimal `yfin:"r"`
PEGRatio decimal.Decimal `yfin:"r5"`
DivYield decimal.Decimal `yfin:"y"`
DivExDate Datetime `yfin:"q"`
DivPayDate Datetime `yfin:"r1"`
EPS decimal.Decimal `yfin:"e"`
EPSEstCurrentYear decimal.Decimal `yfin:"e7"`
EPSEstNextYear decimal.Decimal `yfin:"e8"`
EPSEstNextQuarter decimal.Decimal `yfin:"e9"`
}
Quote is the object that is returned for a quote inquiry.