finnhub

package module
v0.0.0-...-d873eda Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2020 License: MIT Imports: 4 Imported by: 5

README

go-finnhub

GoDoc Build Status Go Report Card Release codecov

Simple and easy to use client for stock, forex and crpyto data from finnhub.io written in Go. Access real-time market data from 60+ stock exchanges, 10 forex brokers, and 15+ crypto exchanges

Installation

go get github.com/m1/go-finnhub

Usage

First sign up for your api token here finnhub.io

Follow this basic example, for more in-depth documentation see the docs:

c := client.New("your_token_here")

// Stocks
company, err := c.Stock.GetProfile("AAPL")
ceo, err := c.Stock.GetCEO("AAPL")
recommendation, err := c.Stock.GetRecommendations("AAPL")
target, err := c.Stock.GetPriceTarget("AAPL")
options, err := c.Stock.GetOptionChain("DBD")
peers, err := c.Stock.GetPeers("AAPL")
earnings, err := c.Stock.GetEarnings("AAPL")
candle, err := c.Stock.GetCandle("AAPL", finnhub.CandleResolutionDay, nil)
exchanges, err := c.Stock.GetExchanges()
symbols, err := c.Stock.GetSymbols("US")
gradings, err := c.Stock.GetGradings(&finnhub.GradingParams{Symbol: "AAPL"})

// Crypto
exchanges, err := c.Crypto.GetExchanges()
symbols, err := c.Crypto.GetSymbols("Binance")
candle, err := c.Crypto.GetCandle("BINANCE:BEAMUSDT", finnhub.CandleResolutionMonth, nil)

// Forex
exchanges, err := c.Forex.GetExchanges()
symbols, err := c.Forex.GetSymbols("oanda")
candle, err := c.Forex.GetCandle("OANDA:XAU_GBP", finnhub.CandleResolutionMonth, nil)

// News
news, err := c.News.Get(nil)
news, err = c.News.Get(&finnhub.NewsParams{Category: finnhub.NewsCategoryCrypto})
news, err = c.News.GetCompany("AAPL")
sentiment, err := c.News.GetSentiment("AAPL")

Documentation

Index

Constants

View Source
const (
	// CandleStatusOK candle status ok
	CandleStatusOK = "ok"

	// CandleStatusNoData candle has no data
	CandleStatusNoData = "no_data"

	// CandleDefaultCount default count for returned candles
	CandleDefaultCount = 200
)
View Source
const (
	// DateLayoutDate default date layout
	DateLayoutDate = "2006-01-02"

	// DateLayoutDateTime default datetime layout
	DateLayoutDateTime = "2006-01-02 15:04:05"
)
View Source
const (
	// ParamToken the param for tokens
	ParamToken = "token"

	// ParamSymbol the param for symbols
	ParamSymbol = "symbol"

	// ParamCount the param for count
	ParamCount = "count"

	// ParamFrom the param for from
	ParamFrom = "from"

	// ParamTo the param for to
	ParamTo = "to"

	// ParamResolution the param for resolution
	ParamResolution = "resolution"

	// ParamExchange the param for exchange
	ParamExchange = "exchange"

	// ParamCategory the param for category
	ParamCategory = "category"
)
View Source
const (
	// GradingActionUpgrade upgrade stock
	GradingActionUpgrade = "up"

	// GradingActionDowngrade downgrade stock
	GradingActionDowngrade = "down"

	// GradingActionMaintains maintain stock
	GradingActionMaintains = "main"

	// GradingActionInitiate initiate stock
	GradingActionInitiate = "init"

	// GradingActionReiterate reiterate stock
	GradingActionReiterate = "reit"
)
View Source
const (
	// NewsCategoryGeneral the general news category
	NewsCategoryGeneral = "general"

	// NewsCategoryForex the forex news category
	NewsCategoryForex = "forex"

	// NewsCategoryCrypto the crypto news category
	NewsCategoryCrypto = "crypto"

	// NewsCategoryMerger the merger news category
	NewsCategoryMerger = "merger"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Get(path string, params URLParams, response interface{}) error
	Call(method string, path string, params URLParams, response interface{}) error
}

Backend the interface for the API

type CEO

type CEO struct {
	Symbol              string `json:"symbol"`
	Name                string `json:"name"`
	CompanyName         string `json:"companyName"`
	Location            string `json:"location"`
	Salary              int    `json:"salary"`
	Bonus               int    `json:"bonus"`
	StockAwards         int    `json:"stockAwards"`
	OptionAwards        int    `json:"optionAwards"`
	NonEquityIncentives int    `json:"nonEquityIncentives"`
	PensionAndDeferred  int    `json:"pensionAndDeferred"`
	OtherComp           int    `json:"otherComp"`
	Total               int    `json:"total"`
	Year                string `json:"year"`
}

CEO is the company CEO

type Candle

type Candle struct {
	Close  []float64   `json:"c"`
	High   []float64   `json:"h"`
	Low    []float64   `json:"l"`
	Open   []float64   `json:"o"`
	Status string      `json:"s"`
	Times  []time.Time `json:"t"`
	Volume []float64   `json:"v"`
}

Candle is candlestick data for stocks

func (*Candle) UnmarshalJSON

func (c *Candle) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes json

type CandleParams

type CandleParams struct {
	Count *int
	From  *time.Time
	To    *time.Time
}

CandleParams the params for the candle endpoint

type CandleResolution

type CandleResolution int

CandleResolution the type for candle resolutions

const (
	// CandleResolutionSecond resolution 1 second
	CandleResolutionSecond CandleResolution = iota

	// CandleResolution5Second resolution 5 seconds
	CandleResolution5Second

	// CandleResolution15Second resolution 15 seconds
	CandleResolution15Second

	// CandleResolution30Second resolution 30 seconds
	CandleResolution30Second

	// CandleResolutionMinute resolution 1 minute
	CandleResolutionMinute

	// CandleResolutionDay resolution 1 day
	CandleResolutionDay

	// CandleResolutionWeek resolution 1 week
	CandleResolutionWeek

	// CandleResolutionMonth resolution 1 month
	CandleResolutionMonth
)

func (CandleResolution) String

func (d CandleResolution) String() string

type Company

type Company struct {
	Address           string   `json:"address"`
	City              string   `json:"city"`
	Country           string   `json:"country"`
	Currency          string   `json:"currency"`
	CUSIP             string   `json:"cusip"`
	Description       string   `json:"description"`
	Exchange          string   `json:"exchange"`
	GICSIndustryGroup string   `json:"ggroup"`
	GICSIndustry      string   `json:"gind"`
	GICSSector        string   `json:"gsector"`
	GICSSubIndustry   string   `json:"gsubind"`
	ISIN              string   `json:"isin"`
	NAICS             string   `json:"naics"`
	Name              string   `json:"name"`
	Phone             string   `json:"phone"`
	State             string   `json:"state"`
	Ticker            string   `json:"ticker"`
	WebURL            *url.URL `json:"weburl"`
}

Company data structure for companies

func (*Company) UnmarshalJSON

func (c *Company) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type Earning

type Earning struct {
	Actual   float64   `json:"actual"`
	Estimate float64   `json:"estimate"`
	Period   time.Time `json:"period"`
	Symbol   string    `json:"symbol"`
}

Earning are the earnings for a company

func (*Earning) UnmarshalJSON

func (e *Earning) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type Exchange

type Exchange struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

Exchange is the data structure for forex/crypto exchanges

type Grading

type Grading struct {
	Symbol    string    `json:"symbol"`
	Company   string    `json:"company"`
	FromGrade string    `json:"fromGrade"`
	ToGrade   string    `json:"toGrade"`
	Action    string    `json:"action"`
	Time      time.Time `json:"gradeTime"`
}

Grading the data structure for upgrade/downgrade

func (*Grading) UnmarshalJSON

func (g *Grading) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type GradingParams

type GradingParams struct {
	Symbol string `json:"symbol"`
}

GradingParams the url params for the grading endpoint

type News

type News struct {
	Category string    `json:"category"`
	DateTime time.Time `json:"dateTime"`
	Headline string    `json:"headline"`
	ID       int       `json:"id"`
	Image    *url.URL  `json:"image"`
	Related  string    `json:"related"`
	Source   string    `json:"source"`
	Summary  string    `json:"summary"`
	URL      *url.URL  `json:"url"`
}

News the data structure for news

func (*News) UnmarshalJSON

func (n *News) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type NewsParams

type NewsParams struct {
	Category string
}

NewsParams the url params for the news endpoint

type NewsSentiment

type NewsSentiment struct {
	Buzz struct {
		ArticlesInLastWeek int     `json:"articlesInLastWeek"`
		Buzz               float64 `json:"buzz"`
		WeeklyAverage      float64 `json:"weeklyAverage"`
	} `json:"buzz"`
	CompanyNewsScore            float64 `json:"companyNewsScore"`
	SectorAverageBullishPercent float64 `json:"sectorAverageBullishPercent"`
	SectorAverageNewsScore      float64 `json:"sectorAverageNewsScore"`
	Sentiment                   struct {
		BearishPercent float64 `json:"bearishPercent"`
		BullishPercent float64 `json:"bullishPercent"`
	} `json:"sentiment"`
	Symbol string `json:"symbol"`
}

NewsSentiment the data structure for companies news sentiment and statistics

type Option

type Option struct {
	ContractName      string     `json:"contractName"`
	ContractSize      string     `json:"contractSize"`
	Currency          string     `json:"currency"`
	Type              string     `json:"type"`
	InTheMoney        bool       `json:"inTheMoney"`
	LastTradeDateTime *time.Time `json:"lastTradeDateTime"`
	ExpirationDate    time.Time  `json:"expirationDate"`
	Strike            float64    `json:"strike,string"`
	LastPrice         float64    `json:"lastPrice,string"`
	Bid               float64    `json:"bid,string"`
	Ask               float64    `json:"ask,string"`
	Change            float64    `json:"change,string"`
	ChangePercent     float64    `json:"changePercent,string"`
	Volume            int        `json:"volume"`
	OpenInterest      int        `json:"openInterest"`
	ImpliedVolatility float64    `json:"impliedVolatility,string"`
	Delta             float64    `json:"delta,string"`
	Gamma             float64    `json:"gamma,string"`
	Theta             float64    `json:"theta,string"`
	Vega              float64    `json:"vega,string"`
	Rho               float64    `json:"rho,string"`
	Theoretical       float64    `json:"theoretical,string"`
	IntrinsicValue    float64    `json:"intrinsicValue,string"`
	TimeValue         float64    `json:"timeValue,string"`
	UpdatedAt         time.Time  `json:"updatedAt"`
}

Option the data structure for options

func (*Option) UnmarshalJSON

func (o *Option) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type OptionChain

type OptionChain struct {
	Code     string            `json:"code"`
	Exchange string            `json:"exchange"`
	Data     []OptionChainData `json:"data"`
}

OptionChain the data structure for option chains

type OptionChainData

type OptionChainData struct {
	ExpirationDate time.Time `json:"expirationDate"`
	Options        struct {
		Call []Option `json:"CALL"`
		Put  []Option `json:"PUT"`
	} `json:"options"`
}

OptionChainData the option chain data structure

func (*OptionChainData) UnmarshalJSON

func (o *OptionChainData) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type PriceTarget

type PriceTarget struct {
	LastUpdated  time.Time `json:"lastUpdated"`
	Symbol       string    `json:"symbol"`
	TargetHigh   float64   `json:"targetHigh"`
	TargetLow    float64   `json:"targetLow"`
	TargetMean   float64   `json:"targetMean"`
	TargetMedian float64   `json:"targetMedian"`
}

PriceTarget the data structure for price targets

func (*PriceTarget) UnmarshalJSON

func (p *PriceTarget) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type Quote

type Quote struct {
	Open          float64 `json:"o"`
	High          float64 `json:"h"`
	Low           float64 `json:"l"`
	Current       float64 `json:"c"`
	PreviousClose float64 `json:"pc"`
}

Quote the data structure for quotes

type Recommendation

type Recommendation struct {
	Buy        int       `json:"buy"`
	Hold       int       `json:"hold"`
	Period     time.Time `json:"period"`
	Sell       int       `json:"sell"`
	StrongBuy  int       `json:"strongBuy"`
	StrongSell int       `json:"strongSell"`
	Symbol     string    `json:"symbol"`
}

Recommendation the data structure for recommendations

func (*Recommendation) UnmarshalJSON

func (r *Recommendation) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the json data

type Symbol

type Symbol struct {
	Description   string `json:"description"`
	DisplaySymbol string `json:"displaySymbol"`
	Symbol        string `json:"symbol"`
}

Symbol the data structure for symbols

type URLParams

type URLParams map[string]string

URLParams the data structure to hold the URL parameters

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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