adding test for throttle exposed a rounding bug

This commit is contained in:
Taha Afzal committed 2018-03-14 14:08:12 -04:00
1 parent 13f6268082
commit f715d196b0
1 file changed
+20 -14
@@ -313,28 +313,27 @@ public:
static bool reprice_quote_mute_zone(double current_price, double new_price, api::Side quote_side, double tick_size,
const bts::spark::QuoteMuteZone& quote_mute_zone)
{
double price_change = new_price - current_price;
// inside_market_limit and outside_market_limit can be cached
double inside_market_limit = quote_mute_zone.inside_ticks() * tick_size,
outside_market_limit = quote_mute_zone.outside_ticks() * tick_size;
/// TODO, when price is not in multiples of ticks
/// TODO, check for negative values
if (price_change != 0)
int price_change_ticks = price_diff_to_ticks (current_price, new_price, tick_size);
if (price_change_ticks != 0)
{
bool price_increasing = price_change_ticks > 0;
uint32_t abs_price_change_ticks = static_cast<uint32_t>(std::abs(price_change_ticks));
LOG(OrderMan, Info, "SpreaderUtils::reprice_quote_mute_zone current_price: {} new_price: {} price_change_ticks: {} abs_price_change_ticks: {} inside_limit_ticks: {} outside_limit_ticks: {}",
current_price, new_price, price_change_ticks, abs_price_change_ticks, quote_mute_zone.inside_ticks(), quote_mute_zone.outside_ticks());
if (quote_side == api::SIDE_BUY)
{
if (price_change > 0)
return price_change > inside_market_limit;
if (price_increasing) // moving toward inside market
return abs_price_change_ticks > quote_mute_zone.inside_ticks();
else
return fabs(price_change) > outside_market_limit;
return abs_price_change_ticks > quote_mute_zone.outside_ticks();
}
else
{
if (price_change < 0)
return fabs(price_change) > inside_market_limit;
if (!price_increasing) // moving toward inside market
return abs_price_change_ticks > quote_mute_zone.inside_ticks();
else
return price_change > outside_market_limit;
}
return abs_price_change_ticks > quote_mute_zone.outside_ticks();
}
}
else
return false;
@@ -655,5 +654,12 @@ public:
oss << "sec_key:" << book_event.key() << " " << book_to_str(book_event.book, api::Side::SIDE_BUY) << " " << book_to_str(book_event.book, api::Side::SIDE_SELL);
return oss.str();
}
/**********************************************************************/
/***********************price rounding helpers*************************/
/**********************************************************************/
static int price_diff_to_ticks (double curr_price, double new_price, double tick_size)
{
return static_cast<int> (std::round((new_price - curr_price)/tick_size));
}
};
}}