70 lines
2.7 KiB
C++
70 lines
2.7 KiB
C++
#include "lib/orderman/limiter/SecurityLimitTree.h"
|
|
#include "lib/api/service_helpers/AdminServiceUtils.h"
|
|
|
|
using namespace bts::api::admin;
|
|
using namespace bts::admin;
|
|
|
|
namespace bts {
|
|
namespace orderman {
|
|
|
|
SecurityLimitTree::QtyNormalization get_qty_norm (const api::Security& s){
|
|
if(s.has_ice())
|
|
return SecurityLimitTree::QtyNormalization
|
|
{
|
|
s.ice().exchange_qty_mult(),
|
|
bts::securities::get_risk_qty(s)
|
|
};
|
|
else
|
|
return SecurityLimitTree::QtyNormalization {1,1};
|
|
}
|
|
|
|
SecurityLimitTree::SecurityLimitTree(
|
|
const api::Security &security,
|
|
ProductLimitTree &product_tree,
|
|
const AdminData &admin_data,
|
|
const bts::api::admin::SecurityRiskLimitUnit& bypass_sec_limit)
|
|
:
|
|
_sec_key(security.id()),
|
|
_is_residual_pos_spread(
|
|
bts::admin::AdminServiceUtils::residual_pos_spread(security)),
|
|
_qty_norm(get_qty_norm(security)){
|
|
LOG(OrderMan,Info,"SecurityLimitTree sec:{} qty_ratio:{} risk_qty:{}",
|
|
security.id(),
|
|
_qty_norm.exchange_qty_mult,
|
|
_qty_norm.unit_risk_qty);
|
|
for (const auto &account : admin_data.accounts()) {
|
|
ProductLimitNode *product_node_ptr =
|
|
product_tree.find_account(account.id());
|
|
bts_assert(product_node_ptr != nullptr);
|
|
uint32_t clip_size =
|
|
AdminServiceUtils::find_account_security_clip_size(account,
|
|
security);
|
|
SecurityRiskLimitUnit const* sec_lim = AdminServiceUtils::get_sec_limit(
|
|
admin_data,
|
|
account.id(),
|
|
security.id());
|
|
_tree.emplace_back(
|
|
account.id(),
|
|
*product_node_ptr,
|
|
clip_size,
|
|
sec_lim == nullptr ? bypass_sec_limit : *sec_lim);
|
|
}
|
|
}
|
|
void SecurityLimitTree::set_parent_child (bool is_child,
|
|
SecurityLimitTree* relation){
|
|
if(relation != nullptr){
|
|
bts_assert(relation->_tree.size()==_tree.size());
|
|
for (auto& node : _tree){
|
|
SecurityLimitNode* other_node =
|
|
relation->_find_account(node.account_id());
|
|
bts_assert(other_node != nullptr);
|
|
node.set_parent_child(is_child, other_node);
|
|
}
|
|
}
|
|
else
|
|
for (auto& node : _tree)
|
|
node.set_parent_child(is_child, nullptr);
|
|
}
|
|
} // namespace orderman
|
|
} // namespace bts
|