Merge branch 'spartan_tas' of bitbucket.org:bluetradesys/spark into spartan_tas
This commit is contained in:
commit
722750faeb
5 files changed
+58
-35
No files matched your search
+2
-2
@@ -86,7 +86,7 @@ FifoPriceLevelMatcher::_one_pass_cross_order(MDP3OrderKey cross_ord_key,
|
||||
MDP3Quantity(filled),
|
||||
_price
|
||||
};
|
||||
UtilFunctions::validate_update(passive_upd);
|
||||
MatcherUtils::validate_outgoing_update(passive_upd);
|
||||
res->push_back(passive_upd);
|
||||
OrderUpdate agg_upd =
|
||||
{
|
||||
@@ -99,7 +99,7 @@ FifoPriceLevelMatcher::_one_pass_cross_order(MDP3OrderKey cross_ord_key,
|
||||
MDP3Quantity(filled),
|
||||
_price
|
||||
};
|
||||
UtilFunctions::validate_update(agg_upd);
|
||||
MatcherUtils::validate_outgoing_update(agg_upd);
|
||||
res->push_back(agg_upd);
|
||||
}
|
||||
if(_trace.log(o.key) || _trace.log(cross_ord_key))
|
||||
|
||||
+15
-3
@@ -39,8 +39,10 @@ FifoSecurityMatcher::_find_order(MDP3OrderKey key) {
|
||||
auto map_it = _order_map.find(key);
|
||||
if(map_it != _order_map.end()){
|
||||
auto& ord = map_it->second;
|
||||
FifoPriceLevelMatcher* p_level = _find_price_level(ord.side,ord.price);
|
||||
return std::make_tuple(p_level,&ord);
|
||||
if(ord.is_active){
|
||||
FifoPriceLevelMatcher* p_level = _find_price_level(ord.side,ord.price);
|
||||
return std::make_tuple(p_level,&ord);
|
||||
}
|
||||
}
|
||||
return std::tuple<FifoPriceLevelMatcher *, MatcherOrder *>(
|
||||
nullptr, nullptr);
|
||||
@@ -66,7 +68,7 @@ void FifoSecurityMatcher::_cleanup() {
|
||||
});
|
||||
}
|
||||
void FifoSecurityMatcher::_on_new_order(const MDP3Order &ord,
|
||||
std::vector<MatchEffect>* res) {
|
||||
std::vector<MatchEffect>* res) {
|
||||
_log_trace_order(ord,"FifoSecurityMatcher::_on_new_order begin");
|
||||
auto& opp_book = _book(_opp_side(ord.side));
|
||||
uint32_t new_ord_rem = total_quantity(ord).value();
|
||||
@@ -114,6 +116,16 @@ void FifoSecurityMatcher::_on_new_order(const MDP3Order &ord,
|
||||
ord_corrected.quantity = MDP3Quantity(new_ord_rem);
|
||||
price_level->on_new_same_side_order(ord_corrected);
|
||||
}
|
||||
else{
|
||||
// since _on_new_order is also the same code path
|
||||
// thats called when an order changes price levels
|
||||
auto it = _order_map.find(ord.key);
|
||||
if(it != _order_map.end()){
|
||||
MatcherOrder& ex_ord = it->second;
|
||||
ex_ord.quantity = MDP3Quantity(0);
|
||||
ex_ord.is_active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FifoSecurityMatcher::_on_order_update(const MDP3Order &ord,
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
#include "Matcher.h"
|
||||
#include "MatchingCommon.h"
|
||||
|
||||
namespace bts::spartan::mdp3{
|
||||
|
||||
void validate_order_change(const OrderChange& c){
|
||||
if(c.change == OrderChange::ChangeType::added ||
|
||||
c.change == OrderChange::ChangeType::updated)
|
||||
bts_assert(c.order.quantity.value()>0);
|
||||
}
|
||||
|
||||
Matcher::Matcher()
|
||||
:
|
||||
_matcher_map(){
|
||||
_matcher_map(),
|
||||
_trace(){
|
||||
}
|
||||
|
||||
Matcher::Matcher(Matcher&& src) {
|
||||
@@ -26,14 +22,19 @@ Matcher::Matcher (std::vector<MDP3SecurityID> const& inst_defs){
|
||||
void Matcher::match(ChangeSrc,
|
||||
const std::vector<OrderChange>& changes,
|
||||
std::vector<MatchEffect>* res) {
|
||||
for (const auto& c : changes){
|
||||
validate_order_change(c);
|
||||
for (const auto& c : changes){
|
||||
_trace.log_incoming_change(c);
|
||||
MatcherUtils::validate_incoming_order_change(c);
|
||||
auto it = _matcher_map.find(c.order.security);
|
||||
bts_assert (it != _matcher_map.end());
|
||||
auto& sec_matcher = it->second.matcher;
|
||||
sec_matcher.on_order_change(c, res);
|
||||
it->second.dirty = true;
|
||||
}
|
||||
for(const auto& u : *res)
|
||||
_trace.log_outgoing_update(std::get<OrderUpdate>(u));
|
||||
for(const auto& u : *res)
|
||||
MatcherUtils::validate_outgoing_update(std::get<OrderUpdate>(u));
|
||||
// all order activity is not reflecting in the
|
||||
// books
|
||||
for (auto& kv : _matcher_map){
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../simulator/AlgoEvent.h"
|
||||
#include "../../common/mdp3_common.h"
|
||||
#include "FifoSecurityMatcher.h"
|
||||
#include "MatchingCommon.h"
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
@@ -16,6 +17,7 @@ private:
|
||||
bool dirty = false;
|
||||
};
|
||||
std::map<MDP3SecurityID,CheckedMatcher> _matcher_map;
|
||||
Trace _trace;
|
||||
public:
|
||||
Matcher ();
|
||||
Matcher (std::vector<MDP3SecurityID> const&);
|
||||
|
||||
@@ -11,25 +11,10 @@ struct Trace{
|
||||
public:
|
||||
const std::map<MDP3OrderKey,bool> traced_orders =
|
||||
{
|
||||
{MDP3OrderKey(647262819778),true}
|
||||
};
|
||||
const std::map<size_t,bool> traced_events =
|
||||
{
|
||||
{4416,true},
|
||||
{4498 ,true},
|
||||
{25041,true},
|
||||
{32518,true},
|
||||
{32843,true},
|
||||
{33264,true},
|
||||
{37687,true},
|
||||
{40431,true},
|
||||
{41833,true},
|
||||
{42948,true},
|
||||
{44973,true},
|
||||
};
|
||||
const std::map<size_t,bool> ignored_events =
|
||||
{
|
||||
{MDP3OrderKey(765159167395),true}
|
||||
};
|
||||
const std::map<size_t,bool> traced_events = {};
|
||||
const std::map<size_t,bool> ignored_events = {};
|
||||
bool log(MDP3OrderKey key, size_t eid=0) const{
|
||||
return traced_orders.find(key) != traced_orders.end() ||
|
||||
traced_events.find(eid) != traced_events.end();
|
||||
@@ -40,17 +25,40 @@ public:
|
||||
bool is_ignored_event(size_t eid) const{
|
||||
return ignored_events.find(eid) != ignored_events.end();
|
||||
}
|
||||
std::string _side(api::Side s){
|
||||
return s == api::Side::SIDE_BUY ? "BUY" : "SELL";
|
||||
}
|
||||
void log_incoming_change(const OrderChange& c){
|
||||
if(traced_orders.find(c.order.key) != traced_orders.end())
|
||||
LOG(OrderMan, Info,
|
||||
"Matcher incoming change:{} ok:{} side:{} price:{} qty:{} ib:{}",
|
||||
c.change, c.order.key, _side(c.order.side), c.order.price,
|
||||
c.order.quantity,
|
||||
c.order.iceberg_quantity.has_value() ?
|
||||
c.order.iceberg_quantity.value().value() : 0);
|
||||
}
|
||||
void log_outgoing_update(const OrderUpdate& u){
|
||||
if(traced_orders.find(u.key) != traced_orders.end())
|
||||
LOG(OrderMan, Info,
|
||||
"Matcher outgoing update:{} ok:{} side:{} last_fp:{} last_fq:{}",
|
||||
u.status, u.key, _side(u.side), u.last_price, u.last_fills);
|
||||
}
|
||||
};
|
||||
|
||||
class UtilFunctions{
|
||||
class MatcherUtils{
|
||||
public:
|
||||
static void validate_update(const OrderUpdate& u){
|
||||
static void validate_incoming_order_change(const OrderChange& c){
|
||||
if(c.change == OrderChange::ChangeType::added ||
|
||||
c.change == OrderChange::ChangeType::updated)
|
||||
bts_assert(c.order.quantity.value()>0);
|
||||
}
|
||||
static void validate_outgoing_update(const OrderUpdate& u){
|
||||
if (u.status == OrderUpdate::Status::PARTIALLY_FILLED ||
|
||||
u.status == OrderUpdate::Status::FILLED)
|
||||
bts_assert(u.last_fills.value() > 0);
|
||||
if (u.status == OrderUpdate::Status::CANCELED)
|
||||
bts_assert(u.last_fills.value() == 0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct MatcherIB {
|
||||
|
||||
Reference in new issue
Block a user