Coder Social home page Coder Social logo

finnhub-stock-api / finnhub-go Goto Github PK

View Code? Open in Web Editor NEW
61.0 4.0 7.0 583 KB

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

Home Page: https://finnhub.io/

License: Apache License 2.0

Shell 100.00%
finnhub stock api

finnhub-go's People

Contributors

dominhtri1995 avatar finnhubio avatar nongdenchet avatar sam3000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

finnhub-go's Issues

CompanyBasicFinancials throws an error of undefined response type

Hey,

the client library (v1.1.2) fails when retrieving basic financial information:

	metrics, _, err := client.CompanyBasicFinancials(ctx, "AAPL", "all")
	if err != nil {
		fmt.Printf("error: %v",err)
	}

	fmt.Println(metrics)

Will print:

error: undefined response type

ForexCandles and CryptoCandles

Hi!

Is there any reason that ForexCandles.T is of type []float32 and CryptoCandles.T is of type []int64? Looking at the data returned from the HTTP API both seems to be of type []int

Pointers are vastly over used

There is a general overuse of pointers within this library and many make no sense at all (to me).

All return structs fields are pointers to fields, rather than plain fields e.g. string, float or int. This makes this generated code so much less usable as everything has to be nil checked before using. Your own examples using fmt.Printf("%+v", someReturnStruct) produces a nice array of pointer addresses. Look at libraries like AWS SDK, they have made the same mistake and moved away from this thinking. https://aws.amazon.com/blogs/developer/aws-sdk-for-go-version-2-general-availability/

Another example is here: https://github.com/Finnhub-Stock-API/finnhub-go/blob/master/model_earnings_calendar.go#L20

// EarningsCalendar struct for EarningsCalendar
type EarningsCalendar struct {
	// Array of earnings release.
	EarningsCalendar *[]EarningRelease `json:"earningsCalendar,omitempty"`
}

Here we have field that is a pointer to a slice on struct that is a return value. Pointers to slices have their uses (see https://medium.com/swlh/golang-tips-why-pointers-to-slices-are-useful-and-how-ignoring-them-can-lead-to-tricky-bugs-cac90f72e77b ) but as a struct field value on what is essentially api data (i.e. it shouldn't get changed by the application once read from the api), it's pointless.

As an example, perform a query on stock symbols:

symbols, _, _ := finnhubClient.StockSymbols(context.Background()).Exchange("L").Execute()
for _, s := range symbols {
	fmt.Printf("%s : %+v", *s.DisplaySymbol, s)
}

gives a whole array of lines like (one line example)
TIGT.L : {Description:0xc000cb2400 DisplaySymbol:0xc000cb2410 Symbol:0xc000cb2450 Type:0xc000cb2470 Mic:0xc000cb2430 Figi:0xc000cb2420 ShareClassFIGI:0xc000cb2440 Currency:0xc000cb23f0 Symbol2:0xc000cb2460 Isin:<nil>

Please make the library more Go friendly.

CompanyProfile2 MarketCapitalization throws an error because non-int64 is returned

When I try to query the market cap via CompanyProfile2 I'm getting an error from the library because it seems like a float is returned from the API which is being marshalled into an int64, thus failing.

For example, if I query https://finnhub.io/api/v1/stock/profile2?symbol=BMW.DE I get:

{
    "country": "DE",
    "currency": "EUR",
    "exchange": "XETRA",
    "finnhubIndustry": "Automobiles",
    "ipo": "1926-01-01",
    "logo": "https://static.finnhub.io/logo/1c89169a-80e6-11ea-83c5-00000000092a.png",
    "marketCapitalization": 38459.63,
    "name": "Bayerische Motoren Werke AG",
    "phone": "49893820",
    "shareOutstanding": 658.8625,
    "ticker": "BMW.DE",
    "weburl": "https://www.bmwgroup.com/"
}

Where "marketCapitalization": 38459.63.

When I try this in with the client library:

	opts := &finnhub.CompanyProfile2Opts{
		Symbol: optional.NewString("BMW.DE") 
	}
	profile, _, err := client.CompanyProfile2(ctx, opts)
	if err != nil {
		return err
	}

I'll get the following error:

{"level":"error","ts":1591718086.478492,"msg":"query to finnhub failed","error":"json: cannot unmarshal number 38459.63 into Go struct field CompanyProfile2.marketCapitalization of type int64"}

Quote not returning error value when there is an error

I am writing wrapper function to simply get Quotes and pass the data back through a channel:

        quote, _, err := finnhubClient.Quote(context.Background()).Symbol(ticker).Execute()
	if err != nil {
		stockQuote := StockQuoteInfo{CurrentPrice: 0.0, Change: 0.0, PercentChange: 0.0}
		ch <- StockQuoteAndError{StockQuote: stockQuote, Error: err}
		return
	}

	var quoteInfo StockQuoteInfo = StockQuoteInfo{CurrentPrice: *quote.C, Change: *quote.D, PercentChange: *quote.Dp}
	ch <- StockQuoteAndError{StockQuote: quoteInfo, Error: nil}

When I pass an invalid ticker symbol such as "ABCDE", the err != nil block does not get executed and the "err" variable is set to nil, however when I attempt to access values inside the "quote" response they are nil pointers to invalid memory addresses. This causes my application to panic and crash.

Why is no error being returned when the quote data returned is not valid?

Economic Calendar is missing from api_default

The struct and everything is in place for the economic calendar, but there is no exported function that can be called. Should be easy enough to base it on a similar parameter less API such as countries.

Client initialization & auth error from parsing context

Was trying to initialize the client and kept getting error around date parsing.

  finnhubClient := finnhub.NewAPIClient(finnhub.NewConfiguration()).DefaultApi
	auth := context.WithValue(context.Background(), finnhub.ContextAPIKey, finnhub.APIKey{
		Key: FINNHUB_TOKEN,
  })

Error message

2021/01/10 22:30:54 parsing time ""2020-03-13 00:00:00"" as ""2006-01-02T15:04:05Z07:00"": cannot parse " 00:00:00"" as "T"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.