SPARK-1017

This commit is contained in:
Taha Afzal committed 2018-05-18 10:47:24 -04:00
1 parent ae3b94d6f4
commit 47b1e8f64d
3 files changed
+44 -5

No files matched your search

@@ -453,11 +453,22 @@ public:
}
// all market based post hedging (there is only now) are
// in this function
static bool post_hedge_market_based_price_action (double curr_order_price, const LegPropertyData& leg_property_data, const bts::orderman::Book& book, double& out_new_price)
static bool post_hedge_market_based_price_action (double curr_order_price, uint32_t, uint32_t remaining_to_fill_qty,
const LegPropertyData& leg_property_data, const bts::orderman::Book& book,
double& out_new_price)
{
const bts::spark::PostHedgeParams& post_hedge_params = leg_property_data.leg_params().post_hedge_params();
if (post_hedge_params.has_price_based_cross())
return post_hedge_price_based_forced_cross (curr_order_price, leg_property_data.trading_side(), book, leg_property_data.tick_size(), post_hedge_params.price_based_cross(), out_new_price);
if (post_hedge_params.has_price_based_cross()){
if(post_hedge_price_based_forced_cross (curr_order_price, leg_property_data.trading_side(), book, leg_property_data.tick_size(), post_hedge_params.price_based_cross(), out_new_price))
return true;
}
if (post_hedge_params.has_opposite_market_volume_based_forced_cross()){
if (post_hedge_volume_based_forced_cross(curr_order_price, remaining_to_fill_qty, leg_property_data.trading_side(),
book, leg_property_data.tick_size(),
post_hedge_params.opposite_market_volume_based_forced_cross(),
out_new_price))
return true;
}
return false;
}
static bool post_hedge_price_based_forced_cross (double curr_order_price, api::Side hedge_side, const bts::orderman::Book& book, double tick_size,
@@ -468,6 +479,7 @@ public:
if (hedge_side == api::SIDE_BUY)
{
const md::PriceSize& opp_inside_price_size = book.side(api::Side::SIDE_SELL)[0];
if (opp_inside_price_size.size() > 0)
{
uint32_t dist = bts::securities::price_diff_to_ticks (curr_order_price, opp_inside_price_size.price(), tick_size);
@@ -493,6 +505,30 @@ public:
}
return false;
}
static bool post_hedge_volume_based_forced_cross (double out_price, uint32_t remaining_to_fill_qty, api::Side hedge_side,
const bts::orderman::Book& book,
double tick_size,
const bts::spark::PostHedgeOppositeMarketVolumeBasedForcedCross& volume_based_forced_cross,
double& out_new_price){
Quantity threshold = _quantity_threshold (volume_based_forced_cross.quantity_threshold(), Quantity(remaining_to_fill_qty));
if (hedge_side == api::SIDE_BUY){
const md::PriceSize& opp_inside_price_size = book.side(api::Side::SIDE_SELL)[0];
// the price check is so that we dont repeatedly keep doing this
// im the short period where our hedge order change has not effected the book
if (opp_inside_price_size.size() > threshold.value() && out_price < opp_inside_price_size.price()){
out_new_price = opp_inside_price_size.price() + tick_size * volume_based_forced_cross.cross_ticks();
return true;
}
}
else{
const md::PriceSize& opp_inside_price_size = book.side(api::Side::SIDE_BUY)[0];
if (opp_inside_price_size.size() > threshold.value() && out_price > opp_inside_price_size.price()){
out_new_price = opp_inside_price_size.price() - tick_size * volume_based_forced_cross.cross_ticks();
return true;
}
}
return false;
}
/**********************************************************************/
/**************************Price/Size Calculation**********************/
/**********************************************************************/
@@ -28,7 +28,10 @@ void HedgerWorkingStateWorker::on_order_update(const SpreaderChildOrderState& or
void HedgerWorkingStateWorker::on_book(bts::orderman::TickToTradeCorID, const bts::orderman::Book&)
{
double new_price;
if (SpreaderUtils::post_hedge_market_based_price_action (_hedger->_price_quantity_state.out_price().value(), _hedger->_leg_property_data,
if (SpreaderUtils::post_hedge_market_based_price_action (_hedger->_price_quantity_state.out_price().value(),
_hedger->_price_quantity_state.out_quantity().value(),
_hedger->_price_quantity_state.remaining_to_fill().value(),
_hedger->_leg_property_data,
_hedger->_spreader.get_book (_hedger->_leg_property_data.leg_index()), new_price))
_hedger->_modify_order (Price(new_price));
}