alpacahq / alpaca-ts

A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.
ISC License
156 stars 42 forks source link

Expand timeframe options for getBars #88

Closed jerrami closed 2 years ago

jerrami commented 2 years ago

First, thanks so much for putting this together and maintaining it. I'm a big fan & it's saved me a TON of time in doing a typescript integration with Alpaca APIs.

Is your feature request related to a problem? Please describe. In using the getBars API, I noticed that you're missing a decent amount of documented and undocumented accepted timeframes. Currently, the timeframe accepts '1Sec' | '1Min' | '1Hour' | '1Day' options. After researching the Alpaca docs and some trial and error, there are a handful of other values that are acceptable.

Not all-inclusive, but some of the more common (maybe a better word is more useful) ones are :

At least the 15Min one is referenced at Alpaca bars v2. Additional testing (via Postman) has shown that you can seemingly input any number followed by 'Min' and get actual formatted responses back - e.g., '37Min' actually works and spaces the bars by 37 minutes.

Describe the solution you'd like I would like the ability to input at least the listed above values (5min, 15min, etc.) as viable union type selections for the GetBars timeframe.

Describe alternatives you've considered It is absolutely easily possible to add "as ..." for the timeframe options. But since timeframes that you support are not individually exported, it is not currently feasible to do timeframe: '5min' as TimeFrame for example, which would also suffice.

Additional context Would greatly appreciate it if selectable timeframes included additional values or were implemented as an individual exported type that could be imported & extended. Again, thanks so much for the work on this as a whole!.

117 commented 2 years ago

I agree it should be more extensible. If you submit a PR I'll review and merge it asap, otherwise I will get to this feature sometime this week and ping you. Thank you for the kind words πŸ˜ƒ I'm glad this library is of use to you.

jerrami commented 2 years ago

I agree it should be more extensible. If you submit a PR I'll review and merge it asap, otherwise I will get to this feature sometime this week and ping you. Thank you for the kind words πŸ˜ƒ I'm glad this library is of use to you.

I'll gladly take the opportunity to provide a PR. Gimme a few days to balance work & family obligations. You can park this for now until I provide a PR πŸ˜ƒ. At the least, I should be able to get to it later this week/weekend.