14bool valid_utf8(std::string_view text)
noexcept {
15 std::size_t index = 0;
16 while (index <
text.size()) {
17 const auto lead =
static_cast<unsigned char>(
text[index++]);
18 if (lead < 0x80)
continue;
19 std::size_t tails = 0;
20 if (lead >= 0xc2 && lead <= 0xdf) tails = 1;
21 else if (lead >= 0xe0 && lead <= 0xef) tails = 2;
22 else if (lead >= 0xf0 && lead <= 0xf4) tails = 3;
24 if (tails >
text.size() - index)
return false;
25 for (std::size_t tail = 0; tail < tails; ++tail) {
26 const auto byte =
static_cast<unsigned char>(
text[index + tail]);
27 if (byte < 0x80 || byte > 0xbf)
return false;
29 if (lead == 0xe0 &&
byte < 0xa0)
return false;
30 if (lead == 0xed &&
byte > 0x9f)
return false;
31 if (lead == 0xf0 &&
byte < 0x90)
return false;
32 if (lead == 0xf4 &&
byte > 0x8f)
return false;
40void admit_comment(
const std::string& text,
const char* field) {
41 if (!valid_utf8(text))
45void admit_text(
const std::string& text,
const char* field) {
46 admit_comment(text, field);
49 if (
text.find(
'\x1f') != std::string::npos ||
text.find(
'\0') != std::string::npos) {
50 const std::string_view name(field);
51 const auto dot = name.find(
'.');
52 throw coded<std::invalid_argument>(
54 RunFailureArgs{{
"function", std::string(
"strategy.") + std::string(name.substr(0, dot))},
55 {
"argument", std::string(name.substr(dot + 1))},
56 {
"rule",
"unsupported_combination"}},
57 "strategy identifiers cannot contain NUL or unit separator");
61void admit_level(
double value,
const char* field) {
63 if (std::isinf(value))
70 double limit_price,
double stop_price,
double,
71 const std::string& comment,
const std::string& oca_name,
82 double,
double,
bool) {
88 double qty,
double qty_percent,
bool immediately,
96 double limit_price,
double,
97 double,
double trail_offset,
double trail_price,
98 double,
const std::string& comment,
double,
99 const std::string& oca_name,
double profit_ticks,
double loss_ticks) {
115 const std::string& from_entry,
116 const std::string& comment) {
129 double limit_price,
double stop_price,
130 const std::string& oca_name,
int) {
constexpr const char * order_oca_name
constexpr const char * exit_limit_price
constexpr const char * entry_oca_name
constexpr const char * exit_from_entry
constexpr const char * order_limit_price
constexpr const char * close_comment
constexpr const char * cancel_id
constexpr const char * exit_cancel_bracket_exit_id
constexpr const char * order_stop_price
constexpr const char * exit_cancel_bracket_comment
constexpr const char * exit_loss_ticks
constexpr const char * entry_comment
constexpr const char * entry_stop_price
constexpr const char * exit_trail_price
constexpr const char * exit_comment
constexpr const char * exit_trail_offset
constexpr const char * exit_profit_ticks
constexpr const char * order_id
constexpr const char * entry_limit_price
constexpr const char * exit_id
constexpr const char * entry_id
constexpr const char * exit_cancel_bracket_from_entry
constexpr const char * close_id
constexpr const char * exit_oca_name
void admit_strategy_exit(const std::string &id, const std::string &from_entry, double limit_price, double, double, double trail_offset, double trail_price, double, const std::string &comment, double, const std::string &oca_name, double profit_ticks, double loss_ticks)
void admit_strategy_close_token(const std::string &id, const std::string &comment, double qty, double qty_percent, bool immediately, std::uint64_t)
void throw_strategy_value_invalid(const char *field, StrategyValueReason reason)
The coded failure of a source-owned invalid actionable value.
void admit_strategy_cancel(const std::string &id)
void admit_strategy_close_all() noexcept
void admit_strategy_entry(const std::string &id, bool, double limit_price, double stop_price, double, const std::string &comment, const std::string &oca_name, int, int)
void admit_strategy_exit_cancel_bracket(const std::string &exit_id, const std::string &from_entry, const std::string &comment)
void admit_strategy_close(const std::string &id, const std::string &comment, double, double, bool)
void admit_strategy_cancel_all() noexcept
void admit_strategy_order(const std::string &id, bool, double, double limit_price, double stop_price, const std::string &oca_name, int)
std::vector< RunFailureArg > RunFailureArgs