41 std::optional<native_order::Request>
trail;
52 std::optional<native_order::RequestHandle>
stop_loss;
53 std::optional<native_order::RequestHandle>
trail;
72 std::optional<native_order::NativeAnchorRounding> anchor_rounding = std::nullopt) {
77 if (anchor_rounding) {
78 if (
auto* anchor = std::get_if<native_order::FromOwnerFill>(&out.
anchor)) {
79 anchor->rounding = *anchor_rounding;
91 const auto place = [&](
const std::optional<native_order::Request>& leg,
BracketLeg which)
92 -> std::optional<native_order::RequestHandle> {
93 if (!leg)
return std::nullopt;
96 if (result.status != native_order::SubmitStatus::Accepted || !result.handle) {
128 std::optional<native_order::RequestHandle>
handle(
const Key& key)
const {
129 const auto found = entries_.find(key);
130 if (found == entries_.end())
return std::nullopt;
131 return found->second.handle;
133 bool contains(
const Key& key)
const {
return entries_.find(key) != entries_.end(); }
134 std::size_t
size() const noexcept {
return entries_.size(); }
135 bool empty() const noexcept {
return entries_.empty(); }
150 const auto found = entries_.find(key);
151 if (found != entries_.end()) {
152 if (found->second.pending_until_armed || working(found->second.handle)) {
153 const auto result = host_->
replace(found->second.handle, request, options);
154 if (result.status == native_order::ReplaceStatus::Replaced && result.successor) {
155 found->second =
Entry{*result.successor, pending_until_armed(request)};
156 return found->second.handle;
158 if (result.status == native_order::ReplaceStatus::ReplaceRejected) {
162 entries_.erase(found);
164 const auto submitted = host_->submit(request);
165 if (submitted.status != native_order::SubmitStatus::Accepted || !submitted.handle) {
168 entries_.emplace(key, Entry{*submitted.handle, pending_until_armed(request)});
169 return *submitted.handle;
176 const auto found = entries_.find(key);
177 if (found == entries_.end())
return native_order::CancelStatus::NotWorking;
178 const auto target = found->second;
179 entries_.erase(found);
180 if (!target.pending_until_armed && !working(target.handle)) {
181 return native_order::CancelStatus::NotWorking;
183 return host_->cancel(target.handle).status;
187 void forget(
const Key& key) { entries_.erase(key); }
192 bool pending_until_armed =
false;
196 const auto* wait = std::get_if<native_order::WaitForApplied>(&request.
owner);
197 return wait !=
nullptr
198 && wait->visibility == native_order::NativeArmVisibility::PendingUntilArmed;
203 if (row.definition && row.definition->handle == target)
return true;
208 NativeStrategyHost* host_ =
nullptr;
209 std::map<Key, Entry> entries_;
The public native host: an abstract subclass of BacktestEngine with no PineScript on it.
std::vector< NativeWorkingRequest > native_working_requests() const
Working-book snapshot and bulk cancellation.
native_order::SubmitResult submit(const native_order::Request &request)
Accept one complete request.
native_order::ReplaceResult replace(const native_order::RequestHandle &target, const native_order::Request &request)
Replace one live request: validate first, then retire that incarnation and birth a successor with a n...
NativeArmVisibility
Whether an owner-related request that arms is a working order before its arm.
Replacement behaviour that is not expressible in the successor request.
Aggregate field order keeps market construction: Request{Transact{1.0}, "buy", "comment"}...
std::optional< RequestHandle > handle
The one owner relation that arms (the ArmedEvent).