go-finance: github.com/FlashBoys/go-finance Index | Files

package finance

import "github.com/FlashBoys/go-finance"

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

Package Files

datetime.go doc.go fetch.go fields.go history.go option.go options.go pairs.go quotes.go symbols.go utils.go

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"
)

func GetUSEquitySymbols Uses

func GetUSEquitySymbols() (symbols []string, err error)

GetUSEquitySymbols fetches the symbols available through BATS, ~8k symbols.

type Bar Uses

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.

func GetHistory Uses

func GetHistory(symbol string, start Datetime, end Datetime, interval Interval) (b []Bar, err error)

GetHistory fetches a single symbol's quote history from Yahoo Finance.

type Contract Uses

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 Uses

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 Uses

func NewDatetime(t time.Time) Datetime

NewDatetime creates a new instance of Datetime.

func ParseDatetime Uses

func ParseDatetime(s string) Datetime

ParseDatetime creates a new instance of Datetime from a string.

type Event Uses

type Event struct {
    Date   Datetime
    Val    Value
    Type   EventType `yfin:"-"`
    Symbol string    `yfin:"-"`
}

Event contains one historical event (either a split or a dividend).

func GetEventHistory Uses

func GetEventHistory(symbol string, start Datetime, end Datetime, eventType EventType) (e []Event, err error)

GetEventHistory fetches a single symbol's dividend and split history from Yahoo Finance.

type EventType Uses

type EventType string

EventType is the type of history event, either divs or splits.

type FXPairQuote Uses

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 Uses

func GetCurrencyPairQuote(symbol string) (fq FXPairQuote, err error)

GetCurrencyPairQuote fetches a single currency pair's quote from Yahoo Finance.

type Interval Uses

type Interval string

Interval is the duration of the bars returned from the query.

type OptionsCycle Uses

type OptionsCycle struct {
    Symbol          string
    UnderlyingPrice decimal.Decimal
    Expirations     []Datetime
}

OptionsCycle contains the list of expirations for a symbol.

func NewCycle Uses

func NewCycle(symbol string) (oc OptionsCycle, err error)

NewCycle creates a new OptionsCycle instance.

func (*OptionsCycle) GetCallsForExpiration Uses

func (c *OptionsCycle) GetCallsForExpiration(e Datetime) (calls []Contract, err error)

GetCallsForExpiration fetches calls for the given expiration date.

func (*OptionsCycle) GetChainForExpiration Uses

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 Uses

func (c *OptionsCycle) GetFrontMonth() (calls []Contract, puts []Contract, err error)

GetFrontMonth fetches the option chain for the front month.

func (*OptionsCycle) GetPutsForExpiration Uses

func (c *OptionsCycle) GetPutsForExpiration(e Datetime) (puts []Contract, err error)

GetPutsForExpiration fetches puts for the given expiration date.

type Quote Uses

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"`
    DivPerShare        decimal.Decimal `yfin:"d"`
    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.

func GetQuote Uses

func GetQuote(symbol string) (q Quote, err error)

GetQuote fetches a single symbol's quote from Yahoo Finance.

func GetQuotes Uses

func GetQuotes(symbols []string) (q []Quote, err error)

GetQuotes fetches multiple symbol's quotes from Yahoo Finance.

type Value Uses

type Value struct {
    Dividend decimal.Decimal
    Ratio    string
}

Value is an event object that contains either a div amt or a split ratio.

Package finance imports 14 packages (graph) and is imported by 3 packages. Updated 2018-03-09. Refresh now. Tools for package owners.