github.com/Finnhub-Stock-API/finnhub-go@v1.2.1/README.md (about)

     1  # Go API client for finnhub.io
     2  
     3  ## Overview
     4  - API documentation: https://finnhub.io/docs/api
     5  - API version: 1.0.0
     6  - Package version: 1.2.1
     7  
     8  ## Installation
     9  
    10  Install package:
    11  
    12  ```shell
    13  $ go get -u github.com/Finnhub-Stock-API/finnhub-go
    14  ```
    15  
    16  Example (check out other methods documentation [here](https://pkg.go.dev/github.com/Finnhub-Stock-API/finnhub-go?tab=doc#DefaultApiService)):
    17  
    18  ```golang
    19  package main
    20  
    21  import (
    22  	"context"
    23  	"fmt"
    24  	finnhub "github.com/Finnhub-Stock-API/finnhub-go"
    25  	"github.com/antihax/optional"
    26  )
    27  
    28  func main() {
    29  	finnhubClient := finnhub.NewAPIClient(finnhub.NewConfiguration()).DefaultApi
    30  	auth := context.WithValue(context.Background(), finnhub.ContextAPIKey, finnhub.APIKey{
    31  		Key: "<API_KEY>", // Replace this
    32  	})
    33  
    34  	//Stock candles
    35  	stockCandles, _, err := finnhubClient.StockCandles(auth, "AAPL", "D", 1590988249, 1591852249, nil)
    36  	fmt.Printf("%+v\n", stockCandles)
    37  
    38  	// Example with required parameters
    39  	news, _, err := finnhubClient.CompanyNews(auth, "AAPL", "2020-05-01", "2020-05-01")
    40  	if err != nil {
    41  		panic(err)
    42  	}
    43  	fmt.Printf("%+v\n", news)
    44  
    45  	// Example with required and optional parameters
    46  	investorsOwnershipOpts := &finnhub.InvestorsOwnershipOpts{Limit: optional.NewInt64(10)}
    47  	ownerships, _, err := finnhubClient.InvestorsOwnership(auth, "AAPL", investorsOwnershipOpts)
    48  	fmt.Printf("%+v\n", ownerships)
    49  
    50  	//Aggregate Indicator
    51  	aggregateIndicator, _, err := finnhubClient.AggregateIndicator(auth, "AAPL", "D")
    52  	fmt.Printf("%+v\n", aggregateIndicator)
    53  
    54  	// Basic financials
    55  	basicFinancials, _, err := finnhubClient.CompanyBasicFinancials(auth, "MSFT", "margin")
    56  	fmt.Printf("%+v\n", basicFinancials)
    57  
    58  	// Company earnings
    59  	earningsSurprises, _, err := finnhubClient.CompanyEarnings(auth, "AAPL", nil)
    60  	fmt.Printf("%+v\n", earningsSurprises)
    61  
    62  	// Company EPS estimates
    63  	epsEstimate, _, err := finnhubClient.CompanyEpsEstimates(auth, "AAPL", nil)
    64  	fmt.Printf("%+v\n", epsEstimate)
    65  
    66  	// Company executive
    67  	executive, _, err := finnhubClient.CompanyExecutive(auth, "AAPL")
    68  	fmt.Printf("%+v\n", executive)
    69  
    70  	// Company peers
    71  	peers, _, err := finnhubClient.CompanyPeers(auth, "AAPL")
    72  	fmt.Printf("%+v\n", peers)
    73  
    74  	// Company profile
    75  	profile, _, err := finnhubClient.CompanyProfile(auth, &finnhub.CompanyProfileOpts{Symbol: optional.NewString("AAPL")})
    76  	fmt.Printf("%+v\n", profile)
    77  	profileISIN, _, err := finnhubClient.CompanyProfile(auth, &finnhub.CompanyProfileOpts{Isin: optional.NewString("US0378331005")})
    78  	fmt.Printf("%+v\n", profileISIN)
    79  	profileCusip, _, err := finnhubClient.CompanyProfile(auth, &finnhub.CompanyProfileOpts{Cusip: optional.NewString("037833100")})
    80  	fmt.Printf("%+v\n", profileCusip)
    81  
    82  	//Company profile2
    83  	profile2, _, err := finnhubClient.CompanyProfile2(auth, &finnhub.CompanyProfile2Opts{Symbol: optional.NewString("AAPL")})
    84  	fmt.Printf("%+v\n", profile2)
    85  
    86  	// Revenue Estimates
    87  	revenueEstimates, _, err := finnhubClient.CompanyRevenueEstimates(auth, "AAPL", nil)
    88  	fmt.Printf("%+v\n", revenueEstimates)
    89  
    90  	// List country
    91  	countries, _, err := finnhubClient.Country(auth)
    92  	fmt.Printf("%+v\n", countries)
    93  
    94  	// Covid-19
    95  	covid19, _, err := finnhubClient.Covid19(auth)
    96  	fmt.Printf("%+v\n", covid19)
    97  
    98  	// Crypto candles
    99  	cryptoCandles, _, err := finnhubClient.CryptoCandles(auth, "BINANCE:BTCUSDT", "D", 1590988249, 1591852249)
   100  	fmt.Printf("%+v\n", cryptoCandles)
   101  
   102  	// Crypto exchanges
   103  	cryptoExchange, _, err := finnhubClient.CryptoExchanges(auth)
   104  	fmt.Printf("%+v\n", cryptoExchange)
   105  
   106  	//Crypto symbols
   107  	cryptoSymbol, _, err := finnhubClient.CryptoSymbols(auth, "BINANCE")
   108  	fmt.Printf("%+v\n", cryptoSymbol[0:5])
   109  
   110  	// Earnings calendar
   111  	earningsCalendar, _, err := finnhubClient.EarningsCalendar(auth, &finnhub.EarningsCalendarOpts{
   112  		From: optional.NewString("2020-06-12"), To: optional.NewString("2020-06-20")})
   113  	fmt.Printf("%+v\n", earningsCalendar)
   114  
   115  	// Economic code
   116  	economicCode, _, err := finnhubClient.EconomicCode(auth)
   117  	fmt.Printf("%+v\n", economicCode)
   118  
   119  	// Economic data
   120  	economicData, _, err := finnhubClient.EconomicData(auth, "MA-USA-656880")
   121  	fmt.Printf("%+v\n", economicData)
   122  
   123  	// Filings
   124  	filings, _, err := finnhubClient.Filings(auth, &finnhub.FilingsOpts{Symbol: optional.NewString("AAPL")})
   125  	fmt.Printf("%+v\n", filings)
   126  
   127  	//Financials
   128  	financials, _, err := finnhubClient.Financials(auth, "AAPL", "bs", "annual")
   129  	fmt.Printf("%+v\n", financials)
   130  
   131  	// Financials Reported
   132  	financialsReported, _, err := finnhubClient.FinancialsReported(auth, &finnhub.FinancialsReportedOpts{Symbol: optional.NewString("AAPL")})
   133  	fmt.Printf("%+v\n", financialsReported)
   134  
   135  	// Forex candles
   136  	forexCandles, _, err := finnhubClient.ForexCandles(auth, "OANDA:EUR_USD", "D", 1590988249, 1591852249)
   137  	fmt.Printf("%+v\n", forexCandles)
   138  
   139  	// Forex exchanges
   140  	forexExchanges, _, err := finnhubClient.ForexExchanges(auth)
   141  	fmt.Printf("%+v\n", forexExchanges)
   142  	// Forex rates
   143  	forexRates, _, err := finnhubClient.ForexRates(auth, nil)
   144  	fmt.Printf("%+v\n", forexRates)
   145  
   146  	// Forex symbols
   147  	forexSymbols, _, err := finnhubClient.ForexSymbols(auth, "OANDA")
   148  	fmt.Printf("%+v\n", forexSymbols)
   149  
   150  	//Fund ownership
   151  	fundOwnership, _, err := finnhubClient.FundOwnership(auth, "AAPL", nil)
   152  	fmt.Printf("%+v\n", fundOwnership)
   153  
   154  	// General news
   155  	generalNews, _, err := finnhubClient.GeneralNews(auth, "general", nil)
   156  	fmt.Printf("%+v\n", generalNews)
   157  
   158  	// Ipo calendar
   159  	ipoCalendar, _, err := finnhubClient.IpoCalendar(auth, "2020-01-01", "2020-06-15")
   160  	fmt.Printf("%+v\n", ipoCalendar)
   161  
   162  	//Major development
   163  	majorDevelopment, _, err := finnhubClient.MajorDevelopments(auth, "AAPL", nil)
   164  	fmt.Printf("%+v\n", majorDevelopment)
   165  
   166  	// News sentiment
   167  	newsSentiment, _, err := finnhubClient.NewsSentiment(auth, "AAPL")
   168  	fmt.Printf("%+v\n", newsSentiment)
   169  
   170  	// Pattern recognition
   171  	patterns, _, err := finnhubClient.PatternRecognition(auth, "AAPL", "D")
   172  	fmt.Printf("%+v\n", patterns)
   173  
   174  	// Price target
   175  	priceTarget, _, err := finnhubClient.PriceTarget(auth, "AAPL")
   176  	fmt.Printf("%+v\n", priceTarget)
   177  
   178  	//Quote
   179  	quote, _, err := finnhubClient.Quote(auth, "AAPL")
   180  	fmt.Printf("%+v\n", quote)
   181  
   182  	// Recommendation trends
   183  	recommendationTrend, _, err := finnhubClient.RecommendationTrends(auth, "AAPL")
   184  	fmt.Printf("%+v\n", recommendationTrend)
   185  
   186  	// Stock dividens
   187  	dividends, _, err := finnhubClient.StockDividends(auth, "KO", "2019-01-01", "2020-06-30")
   188  	fmt.Printf("%+v\n", dividends)
   189  
   190  	// Splits
   191  	splits, _, err := finnhubClient.StockSplits(auth, "AAPL", "2000-01-01", "2020-06-15")
   192  	fmt.Printf("%+v\n", splits)
   193  
   194  	// Stock symbols
   195  	stockSymbols, _, err := finnhubClient.StockSymbols(auth, "US")
   196  	fmt.Printf("%+v\n", stockSymbols[0:5])
   197  
   198  	// Support resistance
   199  	supportResitance, _, err := finnhubClient.SupportResistance(auth, "AAPL", "D")
   200  	fmt.Printf("%+v\n", supportResitance)
   201  
   202  	// Technical indicator
   203  	technicalIndicator, _, err := finnhubClient.TechnicalIndicator(auth, "AAPL", "D", 1583098857, 1584308457, "sma", &finnhub.TechnicalIndicatorOpts{
   204  		IndicatorFields: map[string]interface{}{
   205  			"timeperiod": 3,
   206  		},
   207  	})
   208  	fmt.Printf("%+v\n", technicalIndicator)
   209  
   210  	// Transcripts
   211  	transcripts, _, err := finnhubClient.Transcripts(auth, "AAPL_162777")
   212  	fmt.Printf("%+v\n", transcripts)
   213  
   214  	// Transcripts list
   215  	transcriptsList, _, err := finnhubClient.TranscriptsList(auth, "AAPL")
   216  	fmt.Printf("%+v\n", transcriptsList)
   217  
   218  	// Upgrade/downgrade
   219  	upgradeDowngrade, _, err := finnhubClient.UpgradeDowngrade(auth, &finnhub.UpgradeDowngradeOpts{Symbol: optional.NewString("BYND")})
   220  	fmt.Printf("%+v\n", upgradeDowngrade)
   221  
   222  	// Tick Data
   223  	tickData, _, err := client.StockTick(auth, "AAPL", "2020-03-25", 500, 0)
   224      fmt.Printf("%+v\n", tickData)
   225  
   226      // Indices Constituents
   227      indicesConstData, _, err := client.IndicesConstituents(auth, "^GSPC")
   228      fmt.Printf("%+v\n", indicesConstData)
   229  
   230      // Indices Historical Constituents
   231      indicesHistoricalConstData, _, err := client.IndicesHistoricalConstituents(auth, "^GSPC")
   232      fmt.Printf("%+v\n", indicesHistoricalConstData)
   233  
   234      // ETFs Profile
   235      etfsProfileData, _, err := client.EtfsProfile(auth, "^GSPC")
   236      fmt.Printf("%+v\n", etfsProfileData)
   237  
   238      // ETFs Holdings
   239      etfsHoldingsData, _, err := client.EtfsHoldings(auth, "^GSPC")
   240      fmt.Printf("%+v\n", etfsHoldingsData)
   241  
   242      // ETFs Industry Exposure
   243      etfsIndustryExposureData, _, err := client.EtfsIndustryExposure(auth, "^GSPC")
   244      fmt.Printf("%+v\n", etfsIndustryExposureData)
   245  
   246      // ETFs Country Exposure
   247      etfsCountryExposureData, _, err := client.EtfsCountryExposure(auth, "^GSPC")
   248      fmt.Printf("%+v\n", etfsCountryExposureData)
   249  }
   250  
   251  ```
   252  
   253  ## License
   254  
   255  Apache License