79 lines
2.7 KiB
C++
79 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <tuple>
|
|
#include "lib/domain_model/Security.pb.h"
|
|
#include "server/sparkd/orderman/utils/orderman_utils.h"
|
|
|
|
#include "lib/api/services/OrderService.pb.h"
|
|
#include "lib/sparkproto/SparkProtos.pb.h"
|
|
#include "server/sparkd/orderman/md/Book.h"
|
|
#include <boost/container/flat_map.hpp>
|
|
|
|
namespace bts {
|
|
namespace spreader {
|
|
// collection of immutable leg data properties, shared
|
|
// between the Spreader, SingleLegQuoter and SingleFillHedger
|
|
class LegPropertyData
|
|
{
|
|
public:
|
|
const size_t leg_index;
|
|
const bts::api::ContractLeg leg_contract;
|
|
const bts::spark::LegSpreaderParams leg_params;
|
|
const api::Side trading_side;
|
|
LegPropertyData(size_t leg_index_arg,
|
|
const bts::api::ContractLeg& leg_contract_arg,
|
|
const bts::spark::LegSpreaderParams& leg_params_arg,
|
|
api::Side trading_side_arg)
|
|
:
|
|
// copying the values via copy cons
|
|
leg_index(leg_index_arg),
|
|
leg_contract(leg_contract_arg),
|
|
leg_params(leg_params_arg),
|
|
trading_side(trading_side_arg)
|
|
{
|
|
}
|
|
uint32_t security_key() const { return leg_contract.security().id(); }
|
|
const bts::api::Security& security() const { return leg_contract.security(); }
|
|
double price_multiplier() const { return leg_params.price_multiplier(); }
|
|
double size_multiplier() const { return leg_contract.quantity(); }
|
|
double tick_size() const { return leg_contract.security().contract_spec().low_tick(); }
|
|
bool is_active_quoting() const {return leg_params.is_active_quoting();}
|
|
};
|
|
|
|
class LegPropertyDataCollection
|
|
{
|
|
private:
|
|
std::vector<LegPropertyData> _leg_data_vector;
|
|
boost::container::flat_map<uint32_t, size_t> _sec_key_to_index;
|
|
public:
|
|
LegPropertyDataCollection(const std::vector<LegPropertyData>& leg_data_vector)
|
|
: _leg_data_vector(leg_data_vector)
|
|
{
|
|
for (auto it = leg_data_vector.begin(); it != leg_data_vector.end(); ++it)
|
|
_sec_key_to_index.insert(std::pair<uint32_t, size_t>(it->security_key(), it->leg_index));
|
|
}
|
|
const LegPropertyData& get_at_index(size_t index) const
|
|
{
|
|
bts_assert_d(index < _leg_data_vector.size());
|
|
return _leg_data_vector[index];
|
|
}
|
|
LegPropertyData& get_at_index(size_t index)
|
|
{
|
|
bts_assert_d(index < _leg_data_vector.size());
|
|
return _leg_data_vector[index];
|
|
}
|
|
size_t get_security_index(const api::Security& s) const
|
|
{
|
|
return get_security_index(SecurityKey(s.id()));
|
|
}
|
|
size_t get_security_index(bts::SecurityKey sec_key) const
|
|
{
|
|
auto it = _sec_key_to_index.find(sec_key.value());
|
|
bts_assert(it != _sec_key_to_index.end());
|
|
return it->second;
|
|
}
|
|
size_t count() const { return _leg_data_vector.size(); }
|
|
};
|
|
|
|
}}
|