Refactor orderman
This commit is contained in:
1 parent
0a6b3e46a3
commit
3a519f748b
4 files changed
+121
No files matched your search
@@ -0,0 +1 @@
|
||||
#include "fix_order_codec.h"
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <cstring>
|
||||
|
||||
#include "orderman_utils.h"
|
||||
#include "server/sparkd/jetfix/codec/i32_toa.h"
|
||||
#include "server/sparkd/jetfix/codec/MessageDefinitions.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {class Security;}
|
||||
|
||||
namespace orderman {
|
||||
|
||||
constexpr int clordid_sz() {return 20;}
|
||||
constexpr int price_sz() {return 20;}
|
||||
constexpr int quantity_sz() {return 6;}
|
||||
|
||||
inline void encode_clorid(OrderKey ok, SecurityKey sk,std::string *out) {
|
||||
u32_toa(sk.value(),&((*out)[0]),clordid_sz()/2);
|
||||
u32_toa(ok.value(),&((*out)[clordid_sz()/2]),clordid_sz()/2);
|
||||
}
|
||||
|
||||
inline void decode_clorid(std::string const&in, OrderKey *ok, SecurityKey *sk)
|
||||
{
|
||||
bts_assert(in.size() == clordid_sz());
|
||||
char buffer[clordid_sz()/2+1];
|
||||
buffer[clordid_sz()/2] = 0;
|
||||
|
||||
std::memcpy(buffer,&in[0],clordid_sz()/2);
|
||||
*sk = SecurityKey(std::atoi(buffer));
|
||||
|
||||
std::memcpy(buffer,&in[clordid_sz()/2],clordid_sz()/2);
|
||||
*ok = OrderKey(std::atoi(buffer));
|
||||
}
|
||||
|
||||
template <class MSG>
|
||||
OrderKey get_order_key(MSG const &msg)
|
||||
{
|
||||
|
||||
bts_assert(msg.template has<jetfix::fix::ClOrdID> ());
|
||||
OrderKey result;
|
||||
SecurityKey dummy;
|
||||
decode_clorid(msg.template get<jetfix::fix::ClOrdID>(),&result,&dummy);
|
||||
return result;
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "orderman_utils.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {class Security;}
|
||||
namespace orderman {
|
||||
using OrderKey = utils::ValueWrapper<struct OrderKeyTag,uint32_t>;
|
||||
using FIXSessionName = utils::ValueWrapper<struct FIXSessionNameTag,std::string>;
|
||||
using GatewayName = utils::ValueWrapper<struct GatewayNameTag,std::string>;
|
||||
using OperatorID = utils::ValueWrapper<struct OperatorIDTag,std::array<char,18>>;
|
||||
using ExchangeOrderID = utils::ValueWrapper<struct ExchangeOrderIDTag,std::array<char,17>>;
|
||||
using OrderTimeStamp = utils::ValueWrapper<struct OrderTimeStampTag,std::array<char, sizeof("20121204-14:44:02.000")-1>> ;
|
||||
using SecurityPtr = const api::Security *;
|
||||
using AccountName = utils::ValueWrapper<struct AccountNameTag,std::array<char,12>>;
|
||||
|
||||
template <size_t N> void to_array(std::string const&str,std::array<char,N>*out )
|
||||
{
|
||||
auto &result = *out;
|
||||
bts_assert(str.size() <= N);
|
||||
memset(&result[0],' ', N);
|
||||
memcpy(&result[0],str.data(),str.size());
|
||||
}
|
||||
|
||||
template <size_t N> void to_str(std::array<char,N> const&in ,std::string *out)
|
||||
{
|
||||
auto &result = *out;
|
||||
result.resize(N);
|
||||
memcpy(&result[0],in.data(),N);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T to(std::string const&str)
|
||||
{
|
||||
T result;
|
||||
to_array(str,&result.value());
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline std::string to_str (T const&t)
|
||||
{
|
||||
std::string result;
|
||||
to_str(t.value(),&result);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
std::pair<const char*,size_t> to_trim_str(std::array<char,N> const&in)
|
||||
{
|
||||
for (auto i = (size_t) 0; i < N; i++)
|
||||
if (in[i] == ' ')
|
||||
return std::make_pair (&in[0],i);
|
||||
return std::make_pair (&in[0],N);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user