Finnhub Python API Client. Finnhub API provides institutional-grade financial data to investors, fintech startups and investment firms. We support real-time stock price, global fundamentals, global ETFs holdings and alternative data. https://finnhub.io/docs/api
Hey,
I have looked at the code, and found several places in the implementation that could be enhanced / fixed:
Inconsistent use of quotes (mixed single quotes as well as double quotes).
Styling issues, such as imports order, line length, etc.
Unnecessary functions (one liners, that are used once).
Static methods that were declared as class functions.
_request implementation.
_handle_response does not handle csv format.
The internal session is never closed.
Formatting boolean parameters.
_request Implementation
As far as I'm concerned, the _request implementation has several things to be improved:
_create_api_uri is redundant.
_request_api is redundant, and _create_api_uri should be called from _request.
Using data, and then removing it and setting it as params is messy.
The parameter of the API token should be passed as a default argument inside session.params or session.headers (both of them are valid, according to the documentation).
_handle_response Implementation
_handle_response function will raise exception when the format of the output is csv. It can be fixed by checking the returned content type from the server.
Internal Session Object
The internal session object is never (but should be) closed. Therefore, we should add close function, and support for the Client as a context manger (by implementing __enter__ and __exit__).
Formatting Boolean Parameters
The current implementation tries to format the whole keyword arguments dictionary. In other words, the keyword arguments themselves are checked inside _str_to_bool (e.g, the data dictionary, instead of its content). Therefore, there is no conversion.
After execution it, we can notice that r1 == r2, but r1 != r3 and r2 != r3. As a result, we can see there is no conversion.
Future Changes
In my opinion, the code can be enhanced even more. In general, I think it will be great if you add tests, that will check the API responses, as well as linters and formatting tools.
Consider using:
Current Changes
Hey, I have looked at the code, and found several places in the implementation that could be enhanced / fixed:
_request
implementation._handle_response
does not handle csv format._request
ImplementationAs far as I'm concerned, the
_request
implementation has several things to be improved:_create_api_uri
is redundant._request_api
is redundant, and_create_api_uri
should be called from_request
.data
, and then removing it and setting it asparams
is messy.session.params
orsession.headers
(both of them are valid, according to the documentation)._handle_response
Implementation_handle_response
function will raise exception when the format of the output is csv. It can be fixed by checking the returned content type from the server.Internal Session Object
The internal session object is never (but should be) closed. Therefore, we should add
close
function, and support for theClient
as a context manger (by implementing__enter__
and__exit__
).Formatting Boolean Parameters
The current implementation tries to format the whole keyword arguments dictionary. In other words, the keyword arguments themselves are checked inside
_str_to_bool
(e.g, thedata
dictionary, instead of its content). Therefore, there is no conversion.For example:
After execution it, we can notice that
r1 == r2
, butr1 != r3
andr2 != r3
. As a result, we can see there is no conversion.Future Changes
In my opinion, the code can be enhanced even more. In general, I think it will be great if you add tests, that will check the API responses, as well as linters and formatting tools. Consider using:
Also, consider add documentation to the library.