cleaning
This commit is contained in:
1 parent
ff6d0f0e1b
commit
46c2d2e916
2 files changed
+24
-25
No files matched your search
@@ -28,28 +28,28 @@ inline api::Side _opp_side(api::Side side){
|
||||
}
|
||||
|
||||
inline FifoPriceLevelMatcher* FifoSecurityMatcher::_top(api::Side side){
|
||||
auto& price_levels = _price_levels(side);
|
||||
auto it = price_levels.begin();
|
||||
return it != price_levels.end() ? &*it : nullptr;
|
||||
auto& bk = _book(side);
|
||||
auto it = bk.begin();
|
||||
return it != bk.end() ? &*it : nullptr;
|
||||
}
|
||||
|
||||
FifoPriceLevelMatcher* FifoSecurityMatcher::_find_price_level(
|
||||
api::Side side,
|
||||
md::IntPrice price){
|
||||
auto& price_levels = _price_levels(side);
|
||||
auto& bk = _book(side);
|
||||
_search_tok.set_price(price);
|
||||
auto it = price_levels.find (_search_tok);
|
||||
return it != price_levels.end() ? &*it : nullptr;
|
||||
auto it = bk.find (_search_tok);
|
||||
return it != bk.end() ? &*it : nullptr;
|
||||
}
|
||||
|
||||
std::tuple<FifoPriceLevelMatcher*,FifoPriceLevelMatcher::Order*>
|
||||
FifoSecurityMatcher::_find_order (MDP3OrderKey key){
|
||||
for (auto& p_level : _bid_prices){
|
||||
for (auto& p_level : _bid_book){
|
||||
auto o_ptr = p_level.find_order(key);
|
||||
if (o_ptr != nullptr)
|
||||
return std::make_tuple(&p_level,o_ptr);
|
||||
}
|
||||
for (auto& p_level : _ask_prices){
|
||||
for (auto& p_level : _ask_book){
|
||||
auto o_ptr = p_level.find_order(key);
|
||||
if (o_ptr != nullptr)
|
||||
return std::make_tuple(&p_level,o_ptr);
|
||||
@@ -60,24 +60,24 @@ std::tuple<FifoPriceLevelMatcher*,FifoPriceLevelMatcher::Order*>
|
||||
|
||||
void FifoSecurityMatcher::_remove_empty_price_levels(){
|
||||
_empty_price_levels.clear();
|
||||
for (const auto& p: _bid_prices)
|
||||
for (const auto& p: _bid_book)
|
||||
if(!p.populated())
|
||||
_empty_price_levels.emplace_back(api::Side::SIDE_BUY, p.price());
|
||||
for (const auto& p: _ask_prices)
|
||||
for (const auto& p: _ask_book)
|
||||
if(!p.populated())
|
||||
_empty_price_levels.emplace_back(api::Side::SIDE_SELL, p.price());
|
||||
for (const auto& t : _empty_price_levels){
|
||||
auto& price_levels = _price_levels(std::get<0>(t));
|
||||
auto& bk = _book(std::get<0>(t));
|
||||
_search_tok.set_price(std::get<1>(t));
|
||||
price_levels.erase(_search_tok);
|
||||
bk.erase(_search_tok);
|
||||
}
|
||||
}
|
||||
// constructors ///////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
FifoSecurityMatcher::FifoSecurityMatcher(const InstrumentSnapshot& snp)
|
||||
:
|
||||
_bid_prices(),
|
||||
_ask_prices(),
|
||||
_bid_book(),
|
||||
_ask_book(),
|
||||
_empty_price_levels(),
|
||||
_search_tok(md::IntPrice(),
|
||||
api::Side::SIDE_BUY)
|
||||
@@ -90,7 +90,7 @@ _search_tok(md::IntPrice(),
|
||||
Book FifoSecurityMatcher::book(api::Side side) const{
|
||||
auto i = 0;
|
||||
Book rv;
|
||||
for (const auto& p_level : _price_levels(side)){
|
||||
for (const auto& p_level : _book(side)){
|
||||
if(i < MDP3_MAX_BOOK_DEPTH)
|
||||
rv[i++] = p_level.book_level();
|
||||
else
|
||||
@@ -101,7 +101,7 @@ Book FifoSecurityMatcher::book(api::Side side) const{
|
||||
// order interactions /////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void FifoSecurityMatcher::on_new_order(const MDP3Order& ord){
|
||||
auto& opp_book = _price_levels(_opp_side(ord.side));
|
||||
auto& opp_book = _book(_opp_side(ord.side));
|
||||
uint32_t rem = ord.quantity.value();
|
||||
for (FifoPriceLevelMatcher& pl : opp_book){
|
||||
if(_is_cross(ord, pl))
|
||||
@@ -121,7 +121,7 @@ void FifoSecurityMatcher::on_new_order(const MDP3Order& ord){
|
||||
// in either case, it becomes a resting order
|
||||
FifoPriceLevelMatcher* price_level = _find_price_level(ord.side,ord.price);
|
||||
if(price_level == nullptr){
|
||||
auto& same_side_book = _price_levels(ord.side);
|
||||
auto& same_side_book = _book(ord.side);
|
||||
auto p = same_side_book.emplace(ord.price,ord.side);
|
||||
bts_assert(std::get<1>(p));
|
||||
price_level = &*std::get<0>(p);
|
||||
|
||||
@@ -12,8 +12,8 @@ class FifoSecurityMatcher {
|
||||
private:
|
||||
// ask prices are sorted lowest to highets and and bid prices
|
||||
// are sorted lowest to highest
|
||||
boost::container::flat_set<FifoPriceLevelMatcher> _bid_prices,
|
||||
_ask_prices;
|
||||
boost::container::flat_set<FifoPriceLevelMatcher> _bid_book,
|
||||
_ask_book;
|
||||
// auxiliary vector to help with not allocating memory when
|
||||
// removing price levels
|
||||
std::vector<std::tuple<api::Side,md::IntPrice>> _empty_price_levels;
|
||||
@@ -26,13 +26,12 @@ private:
|
||||
FifoPriceLevelMatcher* _top(api::Side);
|
||||
// complexity: O(lg(n))
|
||||
FifoPriceLevelMatcher* _find_price_level(api::Side, md::IntPrice price);
|
||||
boost::container::flat_set<FifoPriceLevelMatcher>& _price_levels(
|
||||
api::Side side){
|
||||
return side == api::Side::SIDE_BUY ? _bid_prices : _ask_prices;
|
||||
boost::container::flat_set<FifoPriceLevelMatcher>& _book(api::Side side){
|
||||
return side == api::Side::SIDE_BUY ? _bid_book : _ask_book;
|
||||
}
|
||||
const boost::container::flat_set<FifoPriceLevelMatcher>& _price_levels(
|
||||
api::Side side) const{
|
||||
return side == api::Side::SIDE_BUY ? _bid_prices : _ask_prices;
|
||||
const boost::container::flat_set<FifoPriceLevelMatcher>& _book(
|
||||
api::Side side) const{
|
||||
return side == api::Side::SIDE_BUY ? _bid_book : _ask_book;
|
||||
}
|
||||
// returns the price level and the order within that level.
|
||||
// complexity: O(n^2) (searching through each price level
|
||||
|
||||
Reference in new issue
Block a user