finnhub go
1.0.0
Make sure your project is using Go Modules (it will have a go.mod
file in its
root if it already is):
go mod init
Then, reference finnhub-go in a Go program with import
:
import (
finnhub "github.com/Finnhub-Stock-API/finnhub-go/v2"
)
Run any of the normal go
commands (build
/install
/test
). The Go
toolchain will resolve and fetch the finnhub-go module automatically.
Alternatively, you can also explicitly go get
the package into a project:
$ go get -u github.com/Finnhub-Stock-API/finnhub-go/v2
go get
If you don't want to use Go Modules, you can choose to get the library directly:
$ go get -u github.com/Finnhub-Stock-API/finnhub-go
Then, reference finnhub-go in a Go program with import
(Note that no /v2 at the end):
import (
finnhub "github.com/Finnhub-Stock-API/finnhub-go"
)
Example (check out other methods documentation here):
package main
import (
"context"
"fmt"
finnhub "github.com/Finnhub-Stock-API/finnhub-go/v2"
)
func main() {
cfg := finnhub.NewConfiguration()
cfg.AddDefaultHeader("X-Finnhub-Token", "<API_key>")
finnhubClient := finnhub.NewAPIClient(cfg).DefaultApi
//Earnings calendar
earningsCalendar, _, err := finnhubClient.EarningsCalendar(context.Background()).From("2021-07-01").To("2021-07-25").Execute()
fmt.Printf("%+vn", earningsCalendar)
// NBBO
bboData, _, err := finnhubClient.StockNbbo(context.Background()).Symbol("AAPL").Date("2021-07-23").Limit(50).Skip(0).Execute()
fmt.Printf("%+vn", bboData)
// Bid ask
lastBidAsk, _, err := finnhubClient.StockBidask(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", lastBidAsk)
// Stock dividends 2
dividends2, _, err := finnhubClient.StockBasicDividends(context.Background()).Symbol("KO").Execute()
fmt.Printf("%+vn", dividends2)
//Stock candles
stockCandles, _, err := finnhubClient.StockCandles(context.Background()).Symbol("AAPL").Resolution("D").From(1590988249).To(1591852249).Execute()
fmt.Printf("%+vn", stockCandles)
// Example with required parameters
news, _, err := finnhubClient.CompanyNews(context.Background()).Symbol("AAPL").From("2020-05-01").To("2020-05-01").Execute()
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+vn", news)
// Example with required and optional parameters
ownerships, _, err := finnhubClient.Ownership(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", ownerships)
// Aggregate Indicator
aggregateIndicator, _, err := finnhubClient.AggregateIndicator(context.Background()).Symbol("AAPL").Resolution("D").Execute()
fmt.Printf("%+vn", aggregateIndicator)
// Basic financials
basicFinancials, _, err := finnhubClient.CompanyBasicFinancials(context.Background()).Symbol("MSFT").Metric("all").Execute()
fmt.Printf("%+vn", basicFinancials)
// Company earnings
earningsSurprises, _, err := finnhubClient.CompanyEarnings(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", earningsSurprises)
// Company EPS estimates
epsEstimate, _, err := finnhubClient.CompanyEpsEstimates(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", epsEstimate)
// Company executive
executive, _, err := finnhubClient.CompanyExecutive(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", executive)
// Company peers
peers, _, err := finnhubClient.CompanyPeers(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", peers)
// Company profile
profile, _, err := finnhubClient.CompanyProfile(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", profile)
profileISIN, _, err := finnhubClient.CompanyProfile(context.Background()).Isin("US0378331005").Execute()
fmt.Printf("%+vn", profileISIN)
profileCusip, _, err := finnhubClient.CompanyProfile(context.Background()).Cusip("037833100").Execute()
fmt.Printf("%+vn", profileCusip)
// Company profile2
profile2, _, err := finnhubClient.CompanyProfile2(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", profile2)
// Revenue Estimates
revenueEstimates, _, err := finnhubClient.CompanyRevenueEstimates(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", revenueEstimates)
// List country
countries, _, err := finnhubClient.Country(context.Background()).Execute()
fmt.Printf("%+vn", countries)
// Covid-19
covid19, _, err := finnhubClient.Covid19(context.Background()).Execute()
fmt.Printf("%+vn", covid19)
// FDA Calendar
fdaCalendar, _, err := finnhubClient.FdaCommitteeMeetingCalendar(context.Background()).Execute()
fmt.Printf("%+vn", fdaCalendar)
// Crypto candles
cryptoCandles, _, err := finnhubClient.CryptoCandles(context.Background()).Symbol("BINANCE:BTCUSDT").Resolution("D").From(1590988249).To(1591852249).Execute()
fmt.Printf("%+vn", cryptoCandles)
// Crypto exchanges
cryptoExchange, _, err := finnhubClient.CryptoExchanges(context.Background()).Execute()
fmt.Printf("%+vn", cryptoExchange)
// Crypto symbols
cryptoSymbol, _, err := finnhubClient.CryptoSymbols(context.Background()).Exchange("BINANCE").Execute()
fmt.Printf("%+vn", cryptoSymbol[0:5])
// Economic Calendar
economicCalendar, _, err := finnhubClient.EconomicCalendar(context.Background()).Execute()
fmt.Printf("%+vn", economicCalendar)
// Economic code
economicCode, _, err := finnhubClient.EconomicCode(context.Background()).Execute()
fmt.Printf("%+vn", economicCode)
// Economic data
economicData, _, err := finnhubClient.EconomicData(context.Background()).Code("MA-USA-656880").Execute()
fmt.Printf("%+vn", economicData)
// Filings
filings, _, err := finnhubClient.Filings(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", filings)
// International filings
internationalFilings, _, err := finnhubClient.InternationalFilings(context.Background()).Symbol("RY.TO").Execute()
fmt.Printf("%+vn", internationalFilings)
// Filings Sentiment
filingsSentiment, _, err := finnhubClient.FilingsSentiment(context.Background()).AccessNumber("0000320193-20-000052").Execute()
fmt.Printf("%+vn", filingsSentiment)
// Similarity Index
similarityIndex, _, err := finnhubClient.SimilarityIndex(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", similarityIndex)
// Financials
financials, _, err := finnhubClient.Financials(context.Background()).Symbol("AAPL").Statement("bs").Freq("annual").Execute()
fmt.Printf("%+vn", financials)
// Financials Reported
financialsReported, _, err := finnhubClient.FinancialsReported(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", financialsReported)
// Forex candles
forexCandles, _, err := finnhubClient.ForexCandles(context.Background()).Symbol("OANDA:EUR_USD").Resolution("D").From(1590988249).To(1591852249).Execute()
fmt.Printf("%+vn", forexCandles)
// Forex exchanges
forexExchanges, _, err := finnhubClient.ForexExchanges(context.Background()).Execute()
fmt.Printf("%+vn", forexExchanges)
// Forex rates
forexRates, _, err := finnhubClient.ForexRates(context.Background()).Base("USD").Execute()
fmt.Printf("%+vn", forexRates)
// Forex symbols
forexSymbols, _, err := finnhubClient.ForexSymbols(context.Background()).Exchange("OANDA").Execute()
fmt.Printf("%+vn", forexSymbols)
// Fund ownership
fundOwnership, _, err := finnhubClient.FundOwnership(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", fundOwnership)
// General news
generalNews, _, err := finnhubClient.MarketNews(context.Background()).Category("general").Execute()
fmt.Printf("%+vn", generalNews)
// Ipo calendar
ipoCalendar, _, err := finnhubClient.IpoCalendar(context.Background()).From("2021-01-01").To("2021-06-30").Execute()
fmt.Printf("%+vn", ipoCalendar)
// Press Releases
majorDevelopment, _, err := finnhubClient.PressReleases(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", majorDevelopment)
// News sentiment
newsSentiment, _, err := finnhubClient.NewsSentiment(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", newsSentiment)
// Pattern recognition
patterns, _, err := finnhubClient.PatternRecognition(context.Background()).Symbol("AAPL").Resolution("D").Execute()
fmt.Printf("%+vn", patterns)
// Price target
priceTarget, _, err := finnhubClient.PriceTarget(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", priceTarget)
// Quote
quote, _, err := finnhubClient.Quote(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", quote)
// Recommendation trends
recommendationTrend, _, err := finnhubClient.RecommendationTrends(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", recommendationTrend)
// Stock dividends
dividends, _, err := finnhubClient.StockDividends(context.Background()).Symbol("KO").From("2019-01-01").To("2021-01-01").Execute()
fmt.Printf("%+vn", dividends)
// Splits
splits, _, err := finnhubClient.StockSplits(context.Background()).Symbol("AAPL").From("2000-01-01").To("2020-06-15").Execute()
fmt.Printf("%+vn", splits)
// Stock symbols
stockSymbols, _, err := finnhubClient.StockSymbols(context.Background()).Exchange("US").Execute()
fmt.Printf("%+vn", stockSymbols[0:5])
// Support resistance
supportResitance, _, err := finnhubClient.SupportResistance(context.Background()).Symbol("AAPL").Resolution("D").Execute()
fmt.Printf("%+vn", supportResitance)
// Technical indicator
technicalIndicator, _, err := finnhubClient.TechnicalIndicator(context.Background()).Symbol("AAPL").Resolution("D").From(1583098857).To(1584308457).Indicator("sma").IndicatorFields(map[string]interface{}{"timeperiod": 3}).Execute()
fmt.Printf("%+vn", technicalIndicator)
// Transcripts
transcripts, _, err := finnhubClient.Transcripts(context.Background()).Id("AAPL_162777").Execute()
fmt.Printf("%+vn", transcripts)
// Transcripts list
transcriptsList, _, err := finnhubClient.TranscriptsList(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", transcriptsList)
// Upgrade/downgrade
upgradeDowngrade, _, err := finnhubClient.UpgradeDowngrade(context.Background()).Symbol("BYND").Execute()
fmt.Printf("%+vn", upgradeDowngrade)
// Tick Data
tickData, _, err := finnhubClient.StockTick(context.Background()).Symbol("AAPL").Date("2021-07-23").Limit(50).Skip(0).Execute()
fmt.Printf("%+vn", tickData)
// Indices Constituents
indicesConstData, _, err := finnhubClient.IndicesConstituents(context.Background()).Symbol("^GSPC").Execute()
fmt.Printf("%+vn", indicesConstData)
// Indices Historical Constituents
indicesHistoricalConstData, _, err := finnhubClient.IndicesHistoricalConstituents(context.Background()).Symbol("^GSPC").Execute()
fmt.Printf("%+vn", indicesHistoricalConstData)
// ETFs Profile
etfsProfileData, _, err := finnhubClient.EtfsProfile(context.Background()).Symbol("SPY").Execute()
fmt.Printf("%+vn", etfsProfileData)
// ETFs Holdings
etfsHoldingsData, _, err := finnhubClient.EtfsHoldings(context.Background()).Symbol("SPY").Execute()
fmt.Printf("%+vn", etfsHoldingsData)
// ETFs Industry Exposure
etfsIndustryExposureData, _, err := finnhubClient.EtfsSectorExposure(context.Background()).Symbol("SPY").Execute()
fmt.Printf("%+vn", etfsIndustryExposureData)
// ETFs Country Exposure
etfsCountryExposureData, _, err := finnhubClient.EtfsCountryExposure(context.Background()).Symbol("SPY").Execute()
fmt.Printf("%+vn", etfsCountryExposureData)
// Mutual Funds Profile
mfProfileData, _, err := finnhubClient.MutualFundProfile(context.Background()).Symbol("VTSAX").Execute()
fmt.Printf("%+vn", mfProfileData)
// Mutual Funds Holdings
mfHoldingsData, _, err := finnhubClient.MutualFundHoldings(context.Background()).Symbol("VTSAX").Execute()
fmt.Printf("%+vn", mfHoldingsData)
// Mutual Funds Industry Exposure
mfIndustryExposureData, _, err := finnhubClient.MutualFundSectorExposure(context.Background()).Symbol("VTSAX").Execute()
fmt.Printf("%+vn", mfIndustryExposureData)
// Mutual Funds Country Exposure
mfCountryExposureData, _, err := finnhubClient.MutualFundCountryExposure(context.Background()).Symbol("VTSAX").Execute()
fmt.Printf("%+vn", mfCountryExposureData)
// Insider Transactions
insiderTransactions, _, err := finnhubClient.InsiderTransactions(context.Background()).Symbol("AAPL").From("2021-01-01").To("2021-07-30").Execute()
fmt.Printf("%+vn", insiderTransactions)
// Revenue breakdown
revenueBreakdown, _, err := finnhubClient.RevenueBreakdown(context.Background()).Symbol("AAPL").Execute()
fmt.Printf("%+vn", revenueBreakdown)
// Social Sentiment
socialSentiment, _, err := finnhubClient.SocialSentiment(context.Background()).Symbol("GME").Execute()
fmt.