Comments (4)
I have a functional solution to this now. Thanks.
Just to clarify though:
If I use it inside the current loop it will be blocking (of the other polled items) while the command is in progress?
It's possible I am misunderstanding, but it's still an
async
function, so conceptually everything else should be able to make progress, I'd say. But (and I am not sure I am understanding your sample code 100%), I'd think you may run into borrowing issues with respect tostream
.
Sorry, to be more clear, if I used drive within the select which is supposed to be polling the data stream, I would not be polling the other streams, i.e. the order updates and the command channel, not to mention any data items that came in during the subscription change would be lost as mentioned below. While that would probably be fine in normal use, if I'm building a proxy for the streams, that would be rather bad to drop data and of course have the latency issues on the other channels.
What I was considering is spinning up two separate tasks: one for all the data stuff as I have it now and the other that takes the subscription portion from connect and simply resolves the future returned from subscribe. If I'm reading things correctly, as long as I await the future and the other task is still polling the stream, it should work?
I think so, yeah.
So, this does seemingly work, I'll know more when the actual market opens of course.
from apca.
Could you use drive
function to resolve the future on the command dispatch path itself, i.e., in the Commands::ChangeSubscriptions
handler block? Do you have the stream available there (I suppose you may into borrowing issues then, but not 100% sure)? It's not great, I agree, and certainly questionable if you intend to have high throughput in your proxy, but if I recall correctly it's all you will get.
Just conceptually (again, if I remember correctly), you can only ever have a single Subscription::subscribe
operation in flight (which is kind of where the mut self
comes from). The reason is that all it does in the background is to send a control message (request) over the stream and then wait for a control message response. From the Alpaca side, at least last I checked, there was no correlation between control message requests and responses, so we can't infer that this response belongs to that request and then dispatch accordingly. All we can say is that this is a control message that we just received, give it to the entity that made the last request. So in order to be correct, there can only be one requestor and all authenticate/subscribe/unsubscribe operations need to be serialized.
from apca.
I don't think that whatever I do will actually use the drive macro due to it requiring both the subscribe future and the mut stream. I.e. I can't use the drive macro outside of the current select because it needs the mut stream in addition to the future. If I use it inside the current loop it will be blocking (of the other polled items) while the command is in progress? (Also, I think any data messages that happen to show up get eaten? Wasn't sure about that bit.) What I was considering is spinning up two separate tasks: one for all the data stuff as I have it now and the other that takes the subscription portion from connect and simply resolves the future returned from subscribe. If I'm reading things correctly, as long as I await the future and the other task is still polling the stream, it should work?
from apca.
I don't think that whatever I do will actually use the drive macro due to it requiring both the subscribe future and the mut stream.
Fair enough. Your use case is different than what it was designed for.
If I use it inside the current loop it will be blocking (of the other polled items) while the command is in progress?
It's possible I am misunderstanding, but it's still an async
function, so conceptually everything else should be able to make progress, I'd say. But (and I am not sure I am understanding your sample code 100%), I'd think you may run into borrowing issues with respect to stream
.
(Also, I think any data messages that happen to show up get eaten? Wasn't sure about that bit.)
Yep. I thought the documentation made that clear, but looking at it I don't see it mentioned either...
What I was considering is spinning up two separate tasks: one for all the data stuff as I have it now and the other that takes the subscription portion from connect and simply resolves the future returned from subscribe. If I'm reading things correctly, as long as I await the future and the other task is still polling the stream, it should work?
I think so, yeah.
from apca.
Related Issues (20)
- Add support for gzip response data HOT 9
- unknown variant ``, expected one of `simple`, `bracket`, `oco`, `oto` HOT 3
- Oauth support? HOT 6
- Hook up portfolio history HOT 3
- support for Latest Multi Trades HOT 1
- Discussion: GPL? HOT 2
- Calendar date/time. HOT 2
- Tokio using Mio prevents compiling to WASM HOT 1
- UUID using Getrandom and Rand prevents compiling to WASM HOT 1
- Support more Trade properties HOT 11
- Proposal: Use a dedicated data type for stock symbols instead of String HOT 2
- Live trading example not updated HOT 1
- Adding support for crypto streaming HOT 7
- Optionally use rustls instead of hyper-tls HOT 5
- example of streaming data with handlers HOT 3
- Support missing real-time streaming channels HOT 2
- automatic websocket reconnection HOT 3
- Parent type for `RequestError<_>` HOT 1
- What's the point to have Get/Post errors if all what you can get is `the endpoint reported an error`... HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apca.