Repository navigation
historical: caller-owned requests via historical_data(..).subscribe() - #1189
Merged
Merged
Conversation
fetch() retries on reset under new ids and hides its subscription; stream() keeps bars up to date and rejects ending/between. A caller that owns a finite dated request (#1167) needs its id up front, one send, the raw frames, and cancel_and_drain to settle it. - historical_data(..).request_id(): allocated with the builder. fetch()'s first attempt and stream() now send under it. - historical_data(..).subscribe(): one send, no retry, ending/between and buffer_limit apply; yields the now-public HistoricalDataFrame. - BarRequest folds the six copies of the encode call. - Wire fact: TWS answers a cancel of a running dated request with 162 "query cancelled" (live, server 226). - Examples historical_data_subscribe / async_historical_data_subscribe.
Contributor
|
Suggestion before merge: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1167. Final PR of the series, after #1186, #1187 and #1188.
Why. The reporter's worker owns a finite, dated historical request. It needs the request id before anything is written, exactly one send, the raw frames kept across interrupted waits, and an explicit cancel it can settle.
fetch()retries on reset under new ids and keeps its subscription internal.stream()setskeepUpToDateand rejectsending/between. As agreed on the issue, this reuses the builder and the existingSubscription, with no separate request type.What (sync and async):
historical_data(..).request_id(): allocated when the builder is made, likecontract_details_stream.fetch()'s first attempt andstream()now send under it, and a resend after a reset takes a new id, so request-id numbering is unchanged.historical_data(..).subscribe(): sends once and never retries.ending/betweenandbuffer_limitapply. ReturnsSubscription<HistoricalDataFrame>.HistoricalDataFrameis public:Bars(HistoricalData), thenEnd { start, end }. It derivesCloneandPartialEqand stays exhaustive.HistoricalData::trim_to(historical: public HistoricalData::trim_to #1188) afterbetween, a drop beforeEndcancelling, andcancel_and_drain. The examples read withnext()under the caller's own deadline, keeping bars across a timed-out wait.pub(crate)BarRequestwith oneencodemethod replaces six copies of the 8-argument encode call.historical_data_subscribe(sync) andasync_historical_data_subscribe.Live (paper, server 226, after hours). I cancelled a running 300-day dated request right after sending it. Within about 50 ms TWS sent 162 "API historical data query cancelled: ": no bars and no end marker, 3 of 3 runs, sync and async. So
cancel_and_drainreturnsRejected(162), which confirms TWS is done. This is the check promised on the issue, recorded indocs/wire-facts/protocol.mdand in the rustdoc. Not tested: a cancel that crosses bars already in flight, and RTH.Verified
builder/data_tests.rs:request_id(), withkeep_up_to_date = false, thebetweenend date, andbuffer_limitpassed through;BarsthenEnd, then the stream ends, with no cancel on drop;Endsends one cancel;Rejectedwith no cancel;next(), because the stub queues all frames up front.next()'s cancel-safety is aSubscriptionproperty, and both examples exercised it live.--timeout 0(Rejected(162)).cargo fmt; clippy, rustdoc (-D warnings) andcargo build --exampleson all three feature configs;just test(7191 passed); integration crates build and pass clippy;just rules-check.