Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all candles to client.rest.on #343

Closed
artdevgame opened this issue Dec 29, 2020 · 4 comments
Closed

Add all candles to client.rest.on #343

artdevgame opened this issue Dec 29, 2020 · 4 comments

Comments

@artdevgame
Copy link

Hello,

Thanks for developing this project.

Would it be possible to add the updated Candles[] array to this callback please: https://github.com/bennycode/coinbase-pro-node/blob/main/src/demo/rest-watch-candles.ts#L12

I would like to know the full candle history from when I called client.rest.product.getCandles up until the latest tick.

@bennycode
Copy link
Owner

Hi @artdevgame, I am happy to hear that you like the project.

The current architecture allows only to get the latest candle. You can subscribe to ProductEvent.NEW_CANDLE events and keep track of all emitted candles in your own application.

Would that be doable for you?

@artdevgame
Copy link
Author

Hey @bennycode

I'm using the demo here:
https://github.com/bennycode/coinbase-pro-node/blob/main/src/demo/rest-watch-candles.ts

Here we retrieve all candles and assign to a variable called candles:
https://github.com/bennycode/coinbase-pro-node/blob/main/src/demo/rest-watch-candles.ts#L17

At the moment, the body of the callback (https://github.com/bennycode/coinbase-pro-node/blob/main/src/demo/rest-watch-candles.ts#L13) in my version is pushing candle to the candles array because I need to keep track of the history (I'm looking for trends).

I don't like that my callback is now causing side effects, and would like to solve that somehow, like how array.map has an optional 'array' param: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Another way I could solve it is to have the ProductEvent.NEW_CANDLE callback call client.rest.product.getCandles again, but that seems a bit wasteful.

@bennycode
Copy link
Owner

@artdevgame, I see your use case now. From my point of view, pushing incoming candles to the existing candles array does not sound like a bad idea. The alternative would be to keep all fetched candles in the memory of the "coinbase-pro-node" library, or do you have another approach?

I wouldn't like to store all fetched candles in the memory of "coinbase-pro-node", because it would consume memory even in applications which don't have your use case and it would go beyond the concerns of a REST API.

In your case using an application state container, like Redux, could be a good idea to manage your candles and handle side effects. What do you think?

@artdevgame
Copy link
Author

Hey @bennycode, happy new year.

I'm ok pushing to candles for now. I share your concern with the memory allocation so don't think it's something for you to implement in hindsight.

I'll close the ticket. Thanks for the feedback.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants