You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
I've used this wrapper to perform some simple interactions with the Robinhood API and have a few things on a wishlist that would improve developer experience (IMO). These changes would mean a breaking 2.0 change so it's not a small piece of work, but I'd like to hear your thoughts.
Response Structure
Presently, the library uses request format callbacks because under the covers it's wrapping using the request module. That means I need to check res.statusCode and body in my callback.
It would be great if the library instead gave me just what I want - the response body JSON or a structured error like this
api.positions((err,json)=>{// just provided json and error (if defined), no need to check res.statusCode since // the library verifies it is a 200 for me and just gives me json})
This would work great with TypeScript since each response type could be defined for code completion and documentation and you'd also be able to declare robinhood types elsewhere as arguments throughout your code, like so:
functiondoSomethingWithPositions(p: RobinhoodPositions){// I now have intellisense for p and know its structure}
Promise Support
Having promise support would be great.
returnPromise.props([positions: api.positions(),user: api.user()]).then(results=>{// results.user// results.positions}).catch(e=>{// catch all errors })
Along with the usual Promise benefits, it would allow using async/await for cleaner code in newer node versions:
try{constpositions=awaitapi.positions()constuser=awaitapi.user()}catch(e){// catch all errors}
Refined Error Checks
Currently all error handling is deferred to the developer, i.e I, as a developer, always need to check status codes but the library could easily do this:
api.positions((err,res,positions)=>{if(err){// Check error type, handle appropriatelyconsole.log('error making https call for permissions. could be a connectivity issue')console.log(err)}elseif(res.statusCode!==200){// Handle status code typeconsole.log('error response returned from robinhood')console.log(res.statusCode)console.log(body)}else{// Awesome, it workedconsole.log(positions)}})
It would be great instead if the library checked the status code for me:
api.positions((err,positions)=>{if(err){// something happened, either non 200 status or connectivity issue}else{console.log(positions)}})
We could extend it so specific error classes are used so developers can identify errors easily:
if(errinstanceofrobinhood.RestApiError){// used when the API returns non 200 status or unexpected response format// the error could have "res" from request attached if the developer need more info}elseif(errinstanceofrobinhood.CommunicationError){// passed when "err" param in request callback was non null// the original error could be attached too for extra info}else{// generic/unknown error handling}
The text was updated successfully, but these errors were encountered:
If you or someone else wants to start working on a proof of concept for it let me know, otherwise I'll give it a go when work gives me some free time 😄
I've used this wrapper to perform some simple interactions with the Robinhood API and have a few things on a wishlist that would improve developer experience (IMO). These changes would mean a breaking 2.0 change so it's not a small piece of work, but I'd like to hear your thoughts.
Response Structure
Presently, the library uses
request
format callbacks because under the covers it's wrapping using therequest
module. That means I need to checkres.statusCode
andbody
in my callback.It would be great if the library instead gave me just what I want - the response body JSON or a structured error like this
This would work great with TypeScript since each response type could be defined for code completion and documentation and you'd also be able to declare robinhood types elsewhere as arguments throughout your code, like so:
Promise Support
Having promise support would be great.
Along with the usual Promise benefits, it would allow using async/await for cleaner code in newer node versions:
Refined Error Checks
Currently all error handling is deferred to the developer, i.e I, as a developer, always need to check status codes but the library could easily do this:
It would be great instead if the library checked the status code for me:
We could extend it so specific error classes are used so developers can identify errors easily:
The text was updated successfully, but these errors were encountered: