项目作者: Finnhub-Stock-API

项目描述 :
Finnhub Go API client. Finnhub API provides institutional-grade financial data to investors, fintech startups and investment firms. We support real-time stock price, global fundamentals and alternative data. https://finnhub.io/docs/api
高级语言: Shell
项目地址: git://github.com/Finnhub-Stock-API/finnhub-go.git
创建时间: 2020-05-26T21:56:11Z
项目社区:https://github.com/Finnhub-Stock-API/finnhub-go

开源协议:Apache License 2.0

下载


Go API client for finnhub.io

Overview

Installation

Using Go Modules

Make sure your project is using Go Modules (it will have a go.mod file in its
root if it already is):

  1. go mod init

Then, reference finnhub-go in a Go program with import:

  1. import (
  2. finnhub "github.com/Finnhub-Stock-API/finnhub-go/v2"
  3. )

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:

  1. $ go get -u github.com/Finnhub-Stock-API/finnhub-go/v2

Using go get

If you don’t want to use Go Modules, you can choose to get the library directly:

  1. $ 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):

  1. import (
  2. finnhub "github.com/Finnhub-Stock-API/finnhub-go"
  3. )

Examples

Example (check out other methods documentation here):

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. finnhub "github.com/Finnhub-Stock-API/finnhub-go/v2"
  6. )
  7. func main() {
  8. cfg := finnhub.NewConfiguration()
  9. cfg.AddDefaultHeader("X-Finnhub-Token", "<API_key>")
  10. finnhubClient := finnhub.NewAPIClient(cfg).DefaultApi
  11. //Earnings calendar
  12. earningsCalendar, _, err := finnhubClient.EarningsCalendar(context.Background()).From("2021-07-01").To("2021-07-25").Execute()
  13. fmt.Printf("%+v\n", earningsCalendar)
  14. // NBBO
  15. bboData, _, err := finnhubClient.StockNbbo(context.Background()).Symbol("AAPL").Date("2021-07-23").Limit(50).Skip(0).Execute()
  16. fmt.Printf("%+v\n", bboData)
  17. // Bid ask
  18. lastBidAsk, _, err := finnhubClient.StockBidask(context.Background()).Symbol("AAPL").Execute()
  19. fmt.Printf("%+v\n", lastBidAsk)
  20. // Stock dividends 2
  21. dividends2, _, err := finnhubClient.StockBasicDividends(context.Background()).Symbol("KO").Execute()
  22. fmt.Printf("%+v\n", dividends2)
  23. //Stock candles
  24. stockCandles, _, err := finnhubClient.StockCandles(context.Background()).Symbol("AAPL").Resolution("D").From(1590988249).To(1591852249).Execute()
  25. fmt.Printf("%+v\n", stockCandles)
  26. // Example with required parameters
  27. news, _, err := finnhubClient.CompanyNews(context.Background()).Symbol("AAPL").From("2020-05-01").To("2020-05-01").Execute()
  28. if err != nil {
  29. fmt.Println(err)
  30. }
  31. fmt.Printf("%+v\n", news)
  32. // Example with required and optional parameters
  33. ownerships, _, err := finnhubClient.Ownership(context.Background()).Symbol("AAPL").Execute()
  34. fmt.Printf("%+v\n", ownerships)
  35. // Aggregate Indicator
  36. aggregateIndicator, _, err := finnhubClient.AggregateIndicator(context.Background()).Symbol("AAPL").Resolution("D").Execute()
  37. fmt.Printf("%+v\n", aggregateIndicator)
  38. // Basic financials
  39. basicFinancials, _, err := finnhubClient.CompanyBasicFinancials(context.Background()).Symbol("MSFT").Metric("all").Execute()
  40. fmt.Printf("%+v\n", basicFinancials)
  41. // Company earnings
  42. earningsSurprises, _, err := finnhubClient.CompanyEarnings(context.Background()).Symbol("AAPL").Execute()
  43. fmt.Printf("%+v\n", earningsSurprises)
  44. // Company EPS estimates
  45. epsEstimate, _, err := finnhubClient.CompanyEpsEstimates(context.Background()).Symbol("AAPL").Execute()
  46. fmt.Printf("%+v\n", epsEstimate)
  47. // Company executive
  48. executive, _, err := finnhubClient.CompanyExecutive(context.Background()).Symbol("AAPL").Execute()
  49. fmt.Printf("%+v\n", executive)
  50. // Company peers
  51. peers, _, err := finnhubClient.CompanyPeers(context.Background()).Symbol("AAPL").Execute()
  52. fmt.Printf("%+v\n", peers)
  53. // Company profile
  54. profile, _, err := finnhubClient.CompanyProfile(context.Background()).Symbol("AAPL").Execute()
  55. fmt.Printf("%+v\n", profile)
  56. profileISIN, _, err := finnhubClient.CompanyProfile(context.Background()).Isin("US0378331005").Execute()
  57. fmt.Printf("%+v\n", profileISIN)
  58. profileCusip, _, err := finnhubClient.CompanyProfile(context.Background()).Cusip("037833100").Execute()
  59. fmt.Printf("%+v\n", profileCusip)
  60. // Company profile2
  61. profile2, _, err := finnhubClient.CompanyProfile2(context.Background()).Symbol("AAPL").Execute()
  62. fmt.Printf("%+v\n", profile2)
  63. // Revenue Estimates
  64. revenueEstimates, _, err := finnhubClient.CompanyRevenueEstimates(context.Background()).Symbol("AAPL").Execute()
  65. fmt.Printf("%+v\n", revenueEstimates)
  66. // List country
  67. countries, _, err := finnhubClient.Country(context.Background()).Execute()
  68. fmt.Printf("%+v\n", countries)
  69. // Covid-19
  70. covid19, _, err := finnhubClient.Covid19(context.Background()).Execute()
  71. fmt.Printf("%+v\n", covid19)
  72. // FDA Calendar
  73. fdaCalendar, _, err := finnhubClient.FdaCommitteeMeetingCalendar(context.Background()).Execute()
  74. fmt.Printf("%+v\n", fdaCalendar)
  75. // Crypto candles
  76. cryptoCandles, _, err := finnhubClient.CryptoCandles(context.Background()).Symbol("BINANCE:BTCUSDT").Resolution("D").From(1590988249).To(1591852249).Execute()
  77. fmt.Printf("%+v\n", cryptoCandles)
  78. // Crypto exchanges
  79. cryptoExchange, _, err := finnhubClient.CryptoExchanges(context.Background()).Execute()
  80. fmt.Printf("%+v\n", cryptoExchange)
  81. // Crypto symbols
  82. cryptoSymbol, _, err := finnhubClient.CryptoSymbols(context.Background()).Exchange("BINANCE").Execute()
  83. fmt.Printf("%+v\n", cryptoSymbol[0:5])
  84. // Economic Calendar
  85. economicCalendar, _, err := finnhubClient.EconomicCalendar(context.Background()).Execute()
  86. fmt.Printf("%+v\n", economicCalendar)
  87. // Economic code
  88. economicCode, _, err := finnhubClient.EconomicCode(context.Background()).Execute()
  89. fmt.Printf("%+v\n", economicCode)
  90. // Economic data
  91. economicData, _, err := finnhubClient.EconomicData(context.Background()).Code("MA-USA-656880").Execute()
  92. fmt.Printf("%+v\n", economicData)
  93. // Filings
  94. filings, _, err := finnhubClient.Filings(context.Background()).Symbol("AAPL").Execute()
  95. fmt.Printf("%+v\n", filings)
  96. // International filings
  97. internationalFilings, _, err := finnhubClient.InternationalFilings(context.Background()).Symbol("RY.TO").Execute()
  98. fmt.Printf("%+v\n", internationalFilings)
  99. // Filings Sentiment
  100. filingsSentiment, _, err := finnhubClient.FilingsSentiment(context.Background()).AccessNumber("0000320193-20-000052").Execute()
  101. fmt.Printf("%+v\n", filingsSentiment)
  102. // Similarity Index
  103. similarityIndex, _, err := finnhubClient.SimilarityIndex(context.Background()).Symbol("AAPL").Execute()
  104. fmt.Printf("%+v\n", similarityIndex)
  105. // Financials
  106. financials, _, err := finnhubClient.Financials(context.Background()).Symbol("AAPL").Statement("bs").Freq("annual").Execute()
  107. fmt.Printf("%+v\n", financials)
  108. // Financials Reported
  109. financialsReported, _, err := finnhubClient.FinancialsReported(context.Background()).Symbol("AAPL").Execute()
  110. fmt.Printf("%+v\n", financialsReported)
  111. // Forex candles
  112. forexCandles, _, err := finnhubClient.ForexCandles(context.Background()).Symbol("OANDA:EUR_USD").Resolution("D").From(1590988249).To(1591852249).Execute()
  113. fmt.Printf("%+v\n", forexCandles)
  114. // Forex exchanges
  115. forexExchanges, _, err := finnhubClient.ForexExchanges(context.Background()).Execute()
  116. fmt.Printf("%+v\n", forexExchanges)
  117. // Forex rates
  118. forexRates, _, err := finnhubClient.ForexRates(context.Background()).Base("USD").Execute()
  119. fmt.Printf("%+v\n", forexRates)
  120. // Forex symbols
  121. forexSymbols, _, err := finnhubClient.ForexSymbols(context.Background()).Exchange("OANDA").Execute()
  122. fmt.Printf("%+v\n", forexSymbols)
  123. // Fund ownership
  124. fundOwnership, _, err := finnhubClient.FundOwnership(context.Background()).Symbol("AAPL").Execute()
  125. fmt.Printf("%+v\n", fundOwnership)
  126. // General news
  127. generalNews, _, err := finnhubClient.MarketNews(context.Background()).Category("general").Execute()
  128. fmt.Printf("%+v\n", generalNews)
  129. // Ipo calendar
  130. ipoCalendar, _, err := finnhubClient.IpoCalendar(context.Background()).From("2021-01-01").To("2021-06-30").Execute()
  131. fmt.Printf("%+v\n", ipoCalendar)
  132. // Press Releases
  133. majorDevelopment, _, err := finnhubClient.PressReleases(context.Background()).Symbol("AAPL").Execute()
  134. fmt.Printf("%+v\n", majorDevelopment)
  135. // News sentiment
  136. newsSentiment, _, err := finnhubClient.NewsSentiment(context.Background()).Symbol("AAPL").Execute()
  137. fmt.Printf("%+v\n", newsSentiment)
  138. // Pattern recognition
  139. patterns, _, err := finnhubClient.PatternRecognition(context.Background()).Symbol("AAPL").Resolution("D").Execute()
  140. fmt.Printf("%+v\n", patterns)
  141. // Price target
  142. priceTarget, _, err := finnhubClient.PriceTarget(context.Background()).Symbol("AAPL").Execute()
  143. fmt.Printf("%+v\n", priceTarget)
  144. // Quote
  145. quote, _, err := finnhubClient.Quote(context.Background()).Symbol("AAPL").Execute()
  146. fmt.Printf("%+v\n", quote)
  147. // Recommendation trends
  148. recommendationTrend, _, err := finnhubClient.RecommendationTrends(context.Background()).Symbol("AAPL").Execute()
  149. fmt.Printf("%+v\n", recommendationTrend)
  150. // Stock dividends
  151. dividends, _, err := finnhubClient.StockDividends(context.Background()).Symbol("KO").From("2019-01-01").To("2021-01-01").Execute()
  152. fmt.Printf("%+v\n", dividends)
  153. // Splits
  154. splits, _, err := finnhubClient.StockSplits(context.Background()).Symbol("AAPL").From("2000-01-01").To("2020-06-15").Execute()
  155. fmt.Printf("%+v\n", splits)
  156. // Stock symbols
  157. stockSymbols, _, err := finnhubClient.StockSymbols(context.Background()).Exchange("US").Execute()
  158. fmt.Printf("%+v\n", stockSymbols[0:5])
  159. // Support resistance
  160. supportResitance, _, err := finnhubClient.SupportResistance(context.Background()).Symbol("AAPL").Resolution("D").Execute()
  161. fmt.Printf("%+v\n", supportResitance)
  162. // Technical indicator
  163. technicalIndicator, _, err := finnhubClient.TechnicalIndicator(context.Background()).Symbol("AAPL").Resolution("D").From(1583098857).To(1584308457).Indicator("sma").IndicatorFields(map[string]interface{}{"timeperiod": 3}).Execute()
  164. fmt.Printf("%+v\n", technicalIndicator)
  165. // Transcripts
  166. transcripts, _, err := finnhubClient.Transcripts(context.Background()).Id("AAPL_162777").Execute()
  167. fmt.Printf("%+v\n", transcripts)
  168. // Transcripts list
  169. transcriptsList, _, err := finnhubClient.TranscriptsList(context.Background()).Symbol("AAPL").Execute()
  170. fmt.Printf("%+v\n", transcriptsList)
  171. // Upgrade/downgrade
  172. upgradeDowngrade, _, err := finnhubClient.UpgradeDowngrade(context.Background()).Symbol("BYND").Execute()
  173. fmt.Printf("%+v\n", upgradeDowngrade)
  174. // Tick Data
  175. tickData, _, err := finnhubClient.StockTick(context.Background()).Symbol("AAPL").Date("2021-07-23").Limit(50).Skip(0).Execute()
  176. fmt.Printf("%+v\n", tickData)
  177. // Indices Constituents
  178. indicesConstData, _, err := finnhubClient.IndicesConstituents(context.Background()).Symbol("^GSPC").Execute()
  179. fmt.Printf("%+v\n", indicesConstData)
  180. // Indices Historical Constituents
  181. indicesHistoricalConstData, _, err := finnhubClient.IndicesHistoricalConstituents(context.Background()).Symbol("^GSPC").Execute()
  182. fmt.Printf("%+v\n", indicesHistoricalConstData)
  183. // ETFs Profile
  184. etfsProfileData, _, err := finnhubClient.EtfsProfile(context.Background()).Symbol("SPY").Execute()
  185. fmt.Printf("%+v\n", etfsProfileData)
  186. // ETFs Holdings
  187. etfsHoldingsData, _, err := finnhubClient.EtfsHoldings(context.Background()).Symbol("SPY").Execute()
  188. fmt.Printf("%+v\n", etfsHoldingsData)
  189. // ETFs Industry Exposure
  190. etfsIndustryExposureData, _, err := finnhubClient.EtfsSectorExposure(context.Background()).Symbol("SPY").Execute()
  191. fmt.Printf("%+v\n", etfsIndustryExposureData)
  192. // ETFs Country Exposure
  193. etfsCountryExposureData, _, err := finnhubClient.EtfsCountryExposure(context.Background()).Symbol("SPY").Execute()
  194. fmt.Printf("%+v\n", etfsCountryExposureData)
  195. // Mutual Funds Profile
  196. mfProfileData, _, err := finnhubClient.MutualFundProfile(context.Background()).Symbol("VTSAX").Execute()
  197. fmt.Printf("%+v\n", mfProfileData)
  198. // Mutual Funds Holdings
  199. mfHoldingsData, _, err := finnhubClient.MutualFundHoldings(context.Background()).Symbol("VTSAX").Execute()
  200. fmt.Printf("%+v\n", mfHoldingsData)
  201. // Mutual Funds Industry Exposure
  202. mfIndustryExposureData, _, err := finnhubClient.MutualFundSectorExposure(context.Background()).Symbol("VTSAX").Execute()
  203. fmt.Printf("%+v\n", mfIndustryExposureData)
  204. // Mutual Funds Country Exposure
  205. mfCountryExposureData, _, err := finnhubClient.MutualFundCountryExposure(context.Background()).Symbol("VTSAX").Execute()
  206. fmt.Printf("%+v\n", mfCountryExposureData)
  207. // Insider Transactions
  208. insiderTransactions, _, err := finnhubClient.InsiderTransactions(context.Background()).Symbol("AAPL").From("2021-01-01").To("2021-07-30").Execute()
  209. fmt.Printf("%+v\n", insiderTransactions)
  210. // Revenue breakdown
  211. revenueBreakdown, _, err := finnhubClient.RevenueBreakdown(context.Background()).Symbol("AAPL").Execute()
  212. fmt.Printf("%+v\n", revenueBreakdown)
  213. // Social Sentiment
  214. socialSentiment, _, err := finnhubClient.SocialSentiment(context.Background()).Symbol("GME").Execute()
  215. fmt.Printf("%+v\n", socialSentiment)
  216. // Investment theme
  217. investmentTheme, _, err := finnhubClient.InvestmentThemes(context.Background()).Theme("financialExchangesData").Execute()
  218. fmt.Printf("%+v\n", investmentTheme)
  219. // Supply chain
  220. supplyChain, _, err := finnhubClient.SupplyChainRelationships(context.Background()).Symbol("AAPL").Execute()
  221. fmt.Printf("%+v\n", supplyChain)
  222. //Symbol lookup
  223. searchResult, _, err := finnhubClient.SymbolSearch(context.Background()).Q("AAPL").Execute()
  224. fmt.Printf("%+v\n", searchResult)
  225. // Company ESG
  226. companyESGScore, _, err := finnhubClient.CompanyEsgScore(context.Background()).Symbol("AAPL").Execute()
  227. fmt.Printf("%+v\n", companyESGScore)
  228. // Company Earnings Quality Score
  229. earningsQualityScore, _, err := finnhubClient.CompanyEarningsQualityScore(context.Background()).Symbol("AAPL").Freq("quarterly").Execute()
  230. if err != nil {
  231. panic(err)
  232. }
  233. fmt.Printf("%+v\n", earningsQualityScore)
  234. // Crypto Profile
  235. cryptoProfile, _, err := finnhubClient.CryptoProfile(context.Background()).Symbol("BTC").Execute()
  236. if err != nil {
  237. panic(err)
  238. }
  239. fmt.Println(objectString(cryptoProfile))
  240. // EBITDA Estimates
  241. ebitdaEstimates, _, err := finnhubClient.CompanyEbitdaEstimates(context.Background()).Symbol("AAPL").Freq("annual").Execute()
  242. if err != nil {
  243. panic(err)
  244. }
  245. fmt.Printf("%+v\n", ebitdaEstimates)
  246. // EBIT Estimates
  247. ebitEstimates, _, err := finnhubClient.CompanyEbitEstimates(context.Background()).Symbol("AAPL").Freq("annual").Execute()
  248. if err != nil {
  249. panic(err)
  250. }
  251. fmt.Printf("%+v\n", ebitEstimates)
  252. // USPTO Patent
  253. uspto, _, err := finnhubClient.StockUsptoPatent(context.Background()).Symbol("NVDA").From("2021-01-01").To("2021-12-31").Execute()
  254. if err != nil {
  255. panic(err)
  256. }
  257. fmt.Printf("%+v\n", uspto)
  258. // Visa Application
  259. visa, _, err := finnhubClient.StockVisaApplication(context.Background()).Symbol("AAPL").From("2021-01-01").To("2021-12-31").Execute()
  260. if err != nil {
  261. panic(err)
  262. }
  263. fmt.Printf("%+v\n", visa)
  264. sectorMetric, _, err := finnhubClient.SectorMetric(context.Background()).Region("NA").Execute()
  265. if err != nil {
  266. panic(err)
  267. }
  268. fmt.Printf("%+v\n", sectorMetric)
  269. }

License

Apache License