41 std::optional<native_order::Request>
trail;
79 std::optional<native_order::SubmitResult>
result;
86 std::optional<native_order::RequestHandle>
handle()
const {
91 std::optional<native_order::RequestRejectReason>
reason()
const {
108 std::optional<native_order::RequestHandle>
trail;
144 std::optional<native_order::NativeAnchorRounding> anchor_rounding = std::nullopt) {
149 if (anchor_rounding) {
150 if (
auto* anchor = std::get_if<native_order::FromOwnerFill>(&out.
anchor)) {
151 anchor->rounding = *anchor_rounding;
162 receipt.parent = spec.
parent;
163 const auto place = [&](
const std::optional<native_order::Request>& leg,
BracketLeg which,
165 -> std::optional<native_order::RequestHandle> {
166 if (!leg)
return std::nullopt;
173 const bool accepted = result.status == native_order::SubmitStatus::Accepted;
175 outcome.result = std::move(result);
176 return outcome.handle();
178 receipt.take_profit =
226 std::optional<native_order::ReplaceResult>
replace;
227 std::optional<native_order::SubmitResult>
submit;
241 std::optional<native_order::RequestHandle>
handle()
const {
247 std::optional<native_order::RequestRejectReason>
reason()
const {
279 std::optional<native_order::CancelResult>
result;
286 return result ?
result->status : native_order::CancelStatus::NotWorking;
313 std::optional<native_order::RequestHandle>
handle(
const Key& key)
const {
314 const auto found = entries_.find(key);
315 if (found == entries_.end())
return std::nullopt;
316 return found->second.handle;
318 bool contains(
const Key& key)
const {
return entries_.find(key) != entries_.end(); }
319 std::size_t
size() const noexcept {
return entries_.size(); }
320 bool empty() const noexcept {
return entries_.empty(); }
352 const auto found = entries_.find(key);
353 if (found != entries_.end()) {
354 if (found->second.pending_until_armed || working(found->second.handle)) {
355 const auto result = host_->
replace(found->second.handle, request, options);
357 if (result.status == native_order::ReplaceStatus::Replaced && result.successor) {
358 found->second =
Entry{*result.successor, pending_until_armed(request)};
362 if (result.status == native_order::ReplaceStatus::ReplaceRejected) {
367 entries_.erase(found);
369 const auto submitted = host_->submit(request);
370 outcome.
submit = submitted;
371 if (submitted.status != native_order::SubmitStatus::Accepted || !submitted.handle) {
375 entries_.emplace(key, Entry{*submitted.handle, pending_until_armed(request)});
394 const auto found = entries_.find(key);
395 if (found == entries_.end())
return outcome;
396 outcome.
known =
true;
397 const auto target = found->second;
398 entries_.erase(found);
399 if (!target.pending_until_armed && !working(target.handle))
return outcome;
400 outcome.
result = host_->cancel(target.handle);
405 void forget(
const Key& key) { entries_.erase(key); }
410 bool pending_until_armed =
false;
414 const auto* wait = std::get_if<native_order::WaitForApplied>(&request.owner);
415 return wait !=
nullptr
416 && wait->visibility == native_order::NativeArmVisibility::PendingUntilArmed;
421 if (row.definition && row.definition->handle == target)
return true;
426 NativeStrategyHost* host_ =
nullptr;
427 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::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"}...
The one owner relation that arms (the ArmedEvent).