chore: Replace magic strings w/ CCAPI macros
These come from ccapi, so the code should never break due to an update (not necessarily the case with the magic strings).
This commit is contained in:
1 parent
481380f883
commit
019c3dd8db
1 file changed
+17
-6
@@ -4,6 +4,7 @@
|
||||
#include "lib/domain/Security.h"
|
||||
|
||||
#include <ccapi_cpp/ccapi_element.h>
|
||||
#include <ccapi_cpp/ccapi_macro.h>
|
||||
#include <string>
|
||||
|
||||
namespace bts::md {
|
||||
@@ -40,34 +41,44 @@ inline void CCApiSecurityParser::parse(
|
||||
domain::Security &security, const TMap &props) {
|
||||
auto &scomm = security.security_common;
|
||||
for (const auto &[name, value] : props) {
|
||||
if (name == "INSTRUMENT") {
|
||||
if (name == CCAPI_INSTRUMENT) {
|
||||
scomm.desc = value;
|
||||
continue;
|
||||
}
|
||||
if (name == "PRICE_INCREMENT") {
|
||||
if (name == CCAPI_ORDER_PRICE_INCREMENT) {
|
||||
double min_price_inc = std::stod(value);
|
||||
scomm.min_price_increment = domain::Price::from_double(min_price_inc);
|
||||
continue;
|
||||
}
|
||||
if (name == "QUANTITY_INCREMENT") {
|
||||
if (name == CCAPI_ORDER_QUANTITY_INCREMENT) {
|
||||
scomm.min_quantity_increment = std::stod(value);
|
||||
continue;
|
||||
}
|
||||
if (name == "UNDERLYING_SYMBOL") {
|
||||
if (name == CCAPI_UNDERLYING_SYMBOL) {
|
||||
scomm.symbol = value;
|
||||
// TODO: make sure these name-mappings are appropriate
|
||||
core::StringFiller::fill_if_empty(scomm.asset, value);
|
||||
core::StringFiller::fill_if_empty(scomm.group, value);
|
||||
continue;
|
||||
}
|
||||
if (name == "BASE_ASSET") {
|
||||
if (name == CCAPI_BASE_ASSET) {
|
||||
scomm.asset = value;
|
||||
// TODO: make sure these name-mappings are appropriate
|
||||
core::StringFiller::fill_if_empty(scomm.symbol, value);
|
||||
core::StringFiller::fill_if_empty(scomm.group, value);
|
||||
continue;
|
||||
}
|
||||
if (name == "QUANTITY_MIN") {
|
||||
if (name == CCAPI_QUOTE_ASSET) {
|
||||
if (!api::domain::Currency_Parse(value, &scomm.currency)) {
|
||||
const auto default_currency = api::domain::Currency::USD;
|
||||
scomm.currency = default_currency;
|
||||
LOG(md, Error,
|
||||
"Failed to parse currency type from string '{}'. Falling back "
|
||||
"to default value '{}'",
|
||||
value, default_currency);
|
||||
}
|
||||
}
|
||||
if (name == CCAPI_ORDER_QUANTITY_MIN) {
|
||||
scomm.min_quantity = std::stod(value);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user