refactor: Add new glbx variable ticks to security (shm and proto)
This commit is contained in:
1 parent
ca96e41391
commit
8fea31bdf6
9 files changed
+252
-2
No files matched your search
@@ -790,6 +790,7 @@ void MDP3Listener::onOption(
|
||||
int8_t tick_rule;
|
||||
if (sec.tickRule(tick_rule)) {
|
||||
decode_ticks(tick_rule, double_of_price(min_tick, 0), fsec);
|
||||
fsec.glbx_vtick_code = static_cast<std::uint8_t>(tick_rule);
|
||||
}
|
||||
fsec.cash_per_point = double_of_price(min_tick_amount, 0) / fsec.low_tick /
|
||||
pow10(fsec.display_factor);
|
||||
@@ -843,6 +844,7 @@ void MDP3Listener::onSpread(
|
||||
int8_t tick_rule;
|
||||
if (sec.tickRule(tick_rule)) {
|
||||
decode_ticks(tick_rule, double_of_price(min_tick, 0), fsec);
|
||||
fsec.glbx_vtick_code = static_cast<std::uint8_t>(tick_rule);
|
||||
} else {
|
||||
double mintick = double_of_price(min_tick, 0);
|
||||
fsec.low_tick = mintick;
|
||||
|
||||
@@ -86,6 +86,7 @@ function(get_cpp_sources dest)
|
||||
${PROJECT_NAME}/md/SecurityStore.cpp
|
||||
${PROJECT_NAME}/md/ShmSegmentName.cpp
|
||||
${PROJECT_NAME}/md/Shm/FixedSecurity.cpp
|
||||
${PROJECT_NAME}/md/Shm/glbx_variable_tick.cpp
|
||||
${PROJECT_NAME}/md/SyntheticSecurityService.cpp
|
||||
${PROJECT_NAME}/md/cme/MDP3Utils.cpp
|
||||
${PROJECT_NAME}/md/common.cpp
|
||||
|
||||
@@ -25,18 +25,34 @@
|
||||
case type::v: \
|
||||
return #v;
|
||||
|
||||
#define ENUM_VALUE_TO_NAME_CASE_EXPLICIT(type, n, v) \
|
||||
case type::n: \
|
||||
return #n;
|
||||
|
||||
#define ENUM_NAME_TO_VALUE_CLAUSE(type, v) \
|
||||
if (name == #v) { \
|
||||
*value = type::v; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define ENUM_NAME_TO_VALUE_CLAUSE_EXPLICIT(type, n, v) \
|
||||
if (name == #n) { \
|
||||
*value = type::n; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define ENUM_NAMEC_TO_VALUE_CLAUSE(type, v) \
|
||||
if (std::string_view(name) == #v) { \
|
||||
*value = type::v; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define ENUM_NAMEC_TO_VALUE_CLAUSE_EXPLICIT(type, n, v) \
|
||||
if (std::string_view(name) == #n) { \
|
||||
*value = type::n; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
#define ENUM_NAME_DEF(type, for_all) \
|
||||
constexpr const char *type::name() const noexcept { \
|
||||
@@ -47,6 +63,16 @@
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
// clang-format off
|
||||
#define ENUM_NAME_DEF_EXPLICIT(type, for_all) \
|
||||
constexpr const char *type::name() const noexcept { \
|
||||
switch (value) { \
|
||||
for_all(ENUM_VALUE_TO_NAME_CASE_EXPLICIT) \
|
||||
default: return "ENUM_UNKNOWN"; \
|
||||
} \
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
#define ENUM_PARSE_DEF(type, for_all) \
|
||||
constexpr bool type::parse(const char *name, type *value) noexcept { \
|
||||
for_all(ENUM_NAMEC_TO_VALUE_CLAUSE) return false; \
|
||||
@@ -55,6 +81,14 @@
|
||||
for_all(ENUM_NAME_TO_VALUE_CLAUSE) return false; \
|
||||
}
|
||||
|
||||
#define ENUM_PARSE_DEF_EXPLICIT(type, for_all) \
|
||||
constexpr bool type::parse(const char *name, type *value) noexcept { \
|
||||
for_all(ENUM_NAMEC_TO_VALUE_CLAUSE_EXPLICIT) return false; \
|
||||
} \
|
||||
inline bool type::parse(const std::string &name, type *value) noexcept { \
|
||||
for_all(ENUM_NAME_TO_VALUE_CLAUSE_EXPLICIT) return false; \
|
||||
}
|
||||
|
||||
#define ENUM_EQUALITY_OPS(type) \
|
||||
constexpr bool operator==(type lhs, type rhs) noexcept { \
|
||||
return lhs.value == rhs.value; \
|
||||
@@ -110,6 +144,23 @@
|
||||
ENUM_TO_JSON(type) \
|
||||
ENUM_EQUALITY_OPS(type)
|
||||
|
||||
#define ENUM_DECLARE_VALUE_EXPLICIT(t, x, v) x = v,
|
||||
|
||||
#define ENUM_CLASS_DEF_EXPLICIT(type, scalar_type, for_all) \
|
||||
class type { \
|
||||
public: \
|
||||
enum Value : scalar_type { for_all(ENUM_DECLARE_VALUE_EXPLICIT) }; \
|
||||
\
|
||||
ENUM_BASIC_MEMBERS(type) \
|
||||
}; \
|
||||
\
|
||||
ENUM_OUTPUT_OPS(type) \
|
||||
ENUM_NAME_DEF_EXPLICIT(type, for_all) \
|
||||
ENUM_PARSE_DEF_EXPLICIT(type, for_all) \
|
||||
ENUM_FROM_JSON(type) \
|
||||
ENUM_TO_JSON(type) \
|
||||
ENUM_EQUALITY_OPS(type)
|
||||
|
||||
#define ENUM_CLASS_DEF_NO_JSON(type, for_all) \
|
||||
class type { \
|
||||
public: \
|
||||
|
||||
@@ -84,6 +84,7 @@ message GLBXExchangeData {
|
||||
uint32 do_not_use_sub_fraction = 31;
|
||||
uint32 do_not_use_price_display_format = 32;
|
||||
uint32 market_segment_id = 33;
|
||||
uint32 vtick_code = 34;
|
||||
}
|
||||
message CBOEExchangeData {
|
||||
int64 exchange_id = 10;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#include "spark/domain_model/Security.h"
|
||||
#include "spark/md/Shm/glbx_variable_tick.h"
|
||||
#include "spark/utils/bts_array_size.h"
|
||||
#include "spark/utils/bts_assert.h"
|
||||
#ifndef NO_CPP0X
|
||||
|
||||
#include "../PriceSize.h"
|
||||
#include "FixedSecurity.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(disable : 4351)
|
||||
@@ -163,7 +166,7 @@ void convert_security(const FixedSecurity &source, Security *presult) {
|
||||
|
||||
switch (source.exchange) {
|
||||
case Venue::VENUE_GLBX:
|
||||
case Venue::VENUE_SIM:
|
||||
case Venue::VENUE_SIM: {
|
||||
dest.mutable_glbx()->set_exchange_id(source.numeric_id);
|
||||
dest.mutable_glbx()->set_security_desc(source.security_desc());
|
||||
dest.mutable_glbx()->set_cfi_code(source.cfi_code());
|
||||
@@ -171,7 +174,9 @@ void convert_security(const FixedSecurity &source, Security *presult) {
|
||||
if (source.cme_market_segment_id != 0)
|
||||
dest.mutable_glbx()->set_market_segment_id(
|
||||
source.cme_market_segment_id);
|
||||
dest.mutable_glbx()->set_vtick_code(source.glbx_vtick_code);
|
||||
break;
|
||||
}
|
||||
case Venue::VENUE_ICE:
|
||||
dest.mutable_ice()->set_exchange_id(source.numeric_id);
|
||||
dest.mutable_ice()->set_security_desc(source.security_desc());
|
||||
@@ -371,6 +376,7 @@ void convert_security(
|
||||
dest.currency(src.currency());
|
||||
dest.exchange = src.exchange();
|
||||
dest.display_factor = to_exponent(src.contract_spec().price_multiplier());
|
||||
dest.glbx_vtick_code = src.glbx().vtick_code();
|
||||
|
||||
switch (src.ExchangeData_case()) {
|
||||
case Security::ExchangeDataCase::kGlbx:
|
||||
@@ -563,6 +569,7 @@ void to_json(nlohmann::json &j, const FixedSecurity &f) {
|
||||
{"high_tick", f.high_tick},
|
||||
{"cpp", f.cash_per_point},
|
||||
|
||||
{"glbx_vtick", f.glbx_vtick_code},
|
||||
{"ice_market_description", f.ice_market_description()},
|
||||
{"ice_cleared_alias", f.ice_cleared_alias()},
|
||||
{"ice_product_name", f.ice_product_name()},
|
||||
@@ -590,7 +597,6 @@ void to_json(nlohmann::json &j, const FixedSecurity &f) {
|
||||
}
|
||||
j["qty_infos"] = std::move(qty_infos_j);
|
||||
}
|
||||
|
||||
switch (f.type) {
|
||||
case api::SECURITYTYPE_SPOT:
|
||||
break;
|
||||
|
||||
@@ -67,6 +67,10 @@ class BTS_EXPORT FixedSecurity {
|
||||
double low_tick;
|
||||
double high_tick;
|
||||
double cash_per_point;
|
||||
// Glbx Variable Tick Table code
|
||||
// Pseudo enum that indicates the variable ticks to use - list of pairs [tick size, max price]
|
||||
// https://cmegroupclientsite.atlassian.net/wiki/spaces/EPICSANDBOX/pages/457225869/MDP+3.0+-+CME+Globex+Pricing#Variable-Tick-Table
|
||||
uint8_t glbx_vtick_code;
|
||||
|
||||
uint32_t cboe_class_key;
|
||||
uint8_t cme_market_segment_id;
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "glbx_variable_tick.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace bts::md {
|
||||
|
||||
using std::array;
|
||||
using std::pair;
|
||||
using std::size_t;
|
||||
using std::uint32_t;
|
||||
using std::uint8_t;
|
||||
using std::vector;
|
||||
|
||||
static const array<uint8_t, 11> tick_codes_length3{1, 2, 3, 4, 10, 11,
|
||||
12, 13, 14, 15, 16};
|
||||
static const float tick_sizes_length3[]{
|
||||
10, 5, 10, /* code 1 */
|
||||
1, 0.5, 1, /* code 2 */
|
||||
2, 1, 2, /* code 3 */
|
||||
25, 5, 25, /* code 4 */
|
||||
25, 5, 25, /* code 10 */
|
||||
10, 5, 10, /* code 11 */
|
||||
0.5, 0.25, 0.5, /* code 12 */
|
||||
5, 1, 5, /* code 13 */
|
||||
5, 2.5, 5, /* code 14 */
|
||||
25, 5, 25, /* code 15 */
|
||||
50, 25, 50, /* code 16 */
|
||||
};
|
||||
static const float tick_maxes_length3[]{
|
||||
-500, 500, /* code 1 */
|
||||
-5, 5, /* code 2 */
|
||||
-10, 10, /* code 3 */
|
||||
-500, 500, /* code 4 */
|
||||
-300, 300, /* code 10 */
|
||||
-300, 300, /* code 11 */
|
||||
-5, 5, /* code 12 */
|
||||
-25, 25, /* code 13 */
|
||||
-25, 25, /* code 14 */
|
||||
-1000, 1000, /* code 15 */
|
||||
-5000, 5000, /* code 16 */
|
||||
};
|
||||
|
||||
static const array<uint8_t, 2> tick_codes_length7{17, 18};
|
||||
static const float tick_sizes_length7[]{
|
||||
50, 25, 10, 5, 10, 25, 50, /* code 17 */
|
||||
100, 50, 25, 5, 25, 50, 100 /* code 18 */
|
||||
};
|
||||
static const float tick_maxes_length7[]{
|
||||
-10000, -2000, -500, 500, 2000, 10000, /* code 17 */
|
||||
-50000, -10000, -500, 500, 1000, 50000, /* code 18 */
|
||||
};
|
||||
|
||||
template <size_t M, size_t N>
|
||||
static int get_glbx_vtick_code_index(
|
||||
const std::vector<std::pair<float, float>> &tick_rules,
|
||||
const float *known_size_arrays) {
|
||||
if (tick_rules.size() != N) {
|
||||
return -1;
|
||||
}
|
||||
// Each tick size array in the vtick table is unique (no need to check tick maxes).
|
||||
static constexpr float epsilon = std::numeric_limits<float>::epsilon() * 10;
|
||||
for (int m = 0; static_cast<size_t>(m) < M; m++) {
|
||||
const float *szs = known_size_arrays + m * N;
|
||||
for (size_t n = 0; n < N; n++) {
|
||||
if (std::abs(tick_rules.at(n).second - *(szs + n)) > epsilon) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool GlbxVariableTickCode_rules(
|
||||
GlbxVariableTickCode code,
|
||||
const float **tick_sizes,
|
||||
const float **tick_maxes,
|
||||
size_t *len) {
|
||||
#define CASE(n, l, i) \
|
||||
case n: \
|
||||
*len = l; \
|
||||
*tick_sizes = &tick_sizes_length##l[l * i]; \
|
||||
*tick_maxes = &tick_maxes_length##l[(l - 1) * i]; \
|
||||
break
|
||||
|
||||
switch (static_cast<uint8_t>(code.value)) {
|
||||
CASE(1, 3, 0);
|
||||
CASE(2, 3, 1);
|
||||
CASE(3, 3, 2);
|
||||
CASE(4, 3, 3);
|
||||
CASE(10, 3, 4);
|
||||
CASE(11, 3, 5);
|
||||
CASE(12, 3, 6);
|
||||
CASE(13, 3, 7);
|
||||
CASE(14, 3, 8);
|
||||
CASE(15, 3, 9);
|
||||
CASE(16, 3, 10);
|
||||
CASE(17, 7, 0);
|
||||
CASE(18, 7, 1);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
GlbxVariableTickCode GlbxVariableTickCode_from_rules(
|
||||
const vector<pair<float, float>> &tick_rules) {
|
||||
int i;
|
||||
#define CASE(n, m) \
|
||||
case n: \
|
||||
i = get_glbx_vtick_code_index<n, m>( \
|
||||
tick_rules, &tick_sizes_length##n[0]); \
|
||||
if (i != -1) { \
|
||||
return static_cast<GlbxVariableTickCode::Value>( \
|
||||
tick_codes_length##n[i]); \
|
||||
} \
|
||||
break
|
||||
|
||||
switch (tick_rules.size()) {
|
||||
CASE(3, 11);
|
||||
CASE(7, 2);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return GlbxVariableTickCode::NONE;
|
||||
#undef CASE
|
||||
}
|
||||
|
||||
} // namespace bts::md
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "spark/core/FMT_IMPL.h"
|
||||
#include "spark/core/enum_macros.h"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
namespace bts::md {
|
||||
|
||||
// clang-format off
|
||||
#define GLBX_VTICK_CODES(add_case) \
|
||||
add_case(GlbxVariableTickCode, NONE, 0) \
|
||||
add_case(GlbxVariableTickCode, VTT_1, 1) \
|
||||
add_case(GlbxVariableTickCode, VTT_2, 2) \
|
||||
add_case(GlbxVariableTickCode, VTT_3, 3) \
|
||||
add_case(GlbxVariableTickCode, VTT_4, 4) \
|
||||
add_case(GlbxVariableTickCode, VTT_10, 10) \
|
||||
add_case(GlbxVariableTickCode, VTT_11, 11) \
|
||||
add_case(GlbxVariableTickCode, VTT_12, 12) \
|
||||
add_case(GlbxVariableTickCode, VTT_13, 13) \
|
||||
add_case(GlbxVariableTickCode, VTT_14, 14) \
|
||||
add_case(GlbxVariableTickCode, VTT_15, 15) \
|
||||
add_case(GlbxVariableTickCode, VTT_16, 16) \
|
||||
add_case(GlbxVariableTickCode, VTT_17, 17) \
|
||||
add_case(GlbxVariableTickCode, VTT_18, 18)
|
||||
// clang-format on
|
||||
|
||||
ENUM_CLASS_DEF_EXPLICIT(GlbxVariableTickCode, std::uint8_t, GLBX_VTICK_CODES);
|
||||
|
||||
#undef GLBX_VTICK_CODES
|
||||
|
||||
GlbxVariableTickCode GlbxVariableTickCode_from_rules(
|
||||
const std::vector<std::pair<float, float>> &tick_rules);
|
||||
|
||||
bool GlbxVariableTickCode_to_rules(
|
||||
GlbxVariableTickCode code,
|
||||
const float **tick_sizes,
|
||||
const float **tick_maxes,
|
||||
std::size_t *len);
|
||||
|
||||
} // namespace bts::md
|
||||
|
||||
FMT_IMPL(bts::md::GlbxVariableTickCode, c, "{}", c.name());
|
||||
@@ -82,6 +82,18 @@ inline void decode_ticks(int vtt, double mintick, FixedSecurity &dest) {
|
||||
dest.low_tick = 25;
|
||||
dest.high_tick = 50;
|
||||
break;
|
||||
case 17:
|
||||
// Note: vtick code 17 actually actually has 7 tick levels (we're just using the first 2)
|
||||
dest.price_break = 500;
|
||||
dest.low_tick = 5;
|
||||
dest.high_tick = 10;
|
||||
break;
|
||||
case 18:
|
||||
// Note: vtick code 18 actually actually has 7 tick levels (we're just using the first 2)
|
||||
dest.price_break = 500;
|
||||
dest.low_tick = 5;
|
||||
dest.high_tick = 25;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user