Added logic for book calculation based on sweep
This commit is contained in:
1 parent
fd8bd63f55
commit
436f7eefe9
3 files changed
+71
No files matched your search
@@ -62,6 +62,14 @@ struct SecData{
|
||||
return look_ahead_book.value();
|
||||
return current_book;
|
||||
}
|
||||
void on_trade_signal(api::Side agg_side, Price deepest_price,
|
||||
Quantity qty_at_deepest_price){
|
||||
auto res = SpreaderUtils::compute_book_from_sweep(current_book,agg_side,
|
||||
deepest_price,qty_at_deepest_price,
|
||||
look_ahead_book.value());
|
||||
if(!res)
|
||||
look_ahead_book = std::nullopt;
|
||||
}
|
||||
};
|
||||
|
||||
// Conveniance struct to package price/qty on both sides
|
||||
|
||||
@@ -7,6 +7,43 @@
|
||||
namespace bts{
|
||||
namespace orderman{
|
||||
|
||||
|
||||
// computes the book (last arg) resulting from from a sweep
|
||||
bool SpreaderUtils::compute_book_from_sweep (
|
||||
const Book& book,
|
||||
api::Side agg_side,
|
||||
Price deepest_trade_price,
|
||||
Quantity qty_at_deepest_price,
|
||||
Book& out_book){
|
||||
// LOG(OrderMan, Info, "p:{} q:{} took swept level:{}",
|
||||
// deepest_trade_price, qty_at_deepest_price, level);
|
||||
const auto n_levels = book.n_levels();
|
||||
Quantity qty_guess = Quantity(1);
|
||||
empty_out_book(out_book.bid(),0,out_book.n_levels());
|
||||
empty_out_book(out_book.ask(),0,out_book.n_levels());
|
||||
auto passive_side = invert_side(agg_side);
|
||||
auto[level,qty] = locate_price(book,passive_side,deepest_trade_price);
|
||||
bool bid_agg = agg_side == api::Side::SIDE_BUY;
|
||||
if(qty == qty_at_deepest_price){
|
||||
BookSide& target_agg_side = bid_agg ? out_book.bid() : out_book.ask();
|
||||
const BookSide& curr_agg_side = bid_agg ? book.bid() : book.ask();
|
||||
// agg side : gets a new level
|
||||
target_agg_side[0] = md::PriceSize_from_double(
|
||||
deepest_trade_price.value(),qty_guess.value());
|
||||
// the curr_book is copied after the new 0th level (above)
|
||||
for (size_t i=1; i<n_levels; i++)
|
||||
target_agg_side[i] = curr_agg_side[i-1];
|
||||
// passive side
|
||||
BookSide& target_passive_side = bid_agg ? out_book.ask() : out_book.bid();
|
||||
const BookSide& current_passive_side = bid_agg ? book.ask() : book.bid();
|
||||
size_t z_idx = 0;
|
||||
for (size_t i=level+1; i<n_levels; i++)
|
||||
target_passive_side[z_idx++] = current_passive_side[i];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
api::Side SpreaderUtils::get_leg_side(api::Side spreader_order_side,
|
||||
bts::api::ContractLeg const& quote_leg){
|
||||
if (spreader_order_side == api::SIDE_BUY)
|
||||
|
||||
@@ -282,6 +282,32 @@ public:
|
||||
Price rv(os::nan());
|
||||
return rv;
|
||||
}
|
||||
|
||||
// if return quantity in the tuiple is 0, then the price was not found
|
||||
static std::tuple<size_t,Quantity> locate_price(const Book& book,
|
||||
api::Side side,
|
||||
Price price){
|
||||
const size_t n_levels = book.n_levels();
|
||||
const BookSide& book_side = book.side(side);
|
||||
for (size_t lv = 0; lv < n_levels; lv++){
|
||||
const auto& l_pq = book_side[lv];
|
||||
if(bts::securities::test_price_equality(l_pq.price(),price.value()))
|
||||
return std::make_tuple(lv,Quantity(l_pq.size()));
|
||||
}
|
||||
return std::tuple<size_t,Quantity>(0,Quantity(0));
|
||||
}
|
||||
|
||||
// computes the book (last arg) resulting from from a sweep
|
||||
static bool compute_book_from_sweep (// starting book
|
||||
const Book& book,
|
||||
// side of the agg order
|
||||
api::Side agg_side,
|
||||
// "best" trade price (max for buy sweep)
|
||||
Price deepest_trade_price,
|
||||
// tot executed qty at deepest price
|
||||
Quantity qty_at_deepest_price,
|
||||
// resultant book
|
||||
Book& out_book);
|
||||
////////////////////////////////////////////////////
|
||||
// quoting params //////////////////////////////////
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
Reference in new issue
Block a user