Merge branch 'spartan_tas' of bitbucket.org:bluetradesys/spark into spartan_tas

This commit is contained in:
Pedro Pinto committed 2021-02-03 14:54:24 -05:00
commit 0eeffd1984
1 file changed
+27 -14
@@ -71,7 +71,7 @@ ChildTemplate *get_ord_template(
// Returns true if it a good shot (ie for sells, poly_cross_price >= min_edge
// and poly_cross_price <= -1*min_edge. So if we are looking for $0.05, selling
// it for >= 0.05 or buying it for <= -0.05 would be an opportunity)
bool is_shot_opp(
bool meets_edge(
api::Side poly_side, double poly_cross_price, double min_edge) {
if (os::is_nan(poly_cross_price))
return false;
@@ -140,8 +140,9 @@ uint32_t scale_leg_qty (uint32_t polygon_qty, SniperLeg& leg){
// sets the corresponding leg values that add up to achieve
// the polygon buy/sell price.
// it is important to distinguish this
// with the 'polygon market' since the polygon is bought at
// the offer and sold at the bid
// with the 'polygon market', we are not computing the polygon
// market but rather where we will shoot, since for the sniper
// we buy at the offer and sell at the bid
void update_cross_values(SniperPolygon& poly){
auto comp = [](SniperPolygon& poly, api::Side p_side){
bool p_is_direct = true;
@@ -182,8 +183,8 @@ void update_cross_values(SniperPolygon& poly){
comp(poly, api::Side::SIDE_SELL);
}
// checks if cumm_qty exists for cumm_price on the
// opp side of the trade_side
// checks if cumm_qty exists for cumm_price such that
// a sniper (cross) order can be shot
bool check_for_cumm_price_qty(
const SniperPolygon &p,
api::Side trade_side,
@@ -192,6 +193,8 @@ bool check_for_cumm_price_qty(
if (cumm_qty.value() == 0)
return true;
double price_at_cumm_qty = 0;
// the price is computed for the cumm_qty (in price_at_cumm_qty)
// and then checked if it is better than cumm_edge)
for (auto &l : p.legs) {
Price l_comp_price;
Quantity l_comp_qty;
@@ -200,11 +203,12 @@ bool check_for_cumm_price_qty(
SpreaderUtils::traverse_depth_for_quantity(
l.sec_data.get_current_book(), cross_side, demanded_leg_qty,
l_comp_price, l_comp_qty);
// if enough qty is not available we exit early
if (l_comp_qty.value() < demanded_leg_qty.value())
return false;
price_at_cumm_qty += leg_mult(l) * l_comp_price.value();
}
return is_shot_opp(trade_side, price_at_cumm_qty, cumm_edge.value());
return meets_edge(trade_side, price_at_cumm_qty, cumm_edge.value());
}
// logging/strings ////////////////////////////////////////////////////////////
@@ -237,8 +241,8 @@ void log_polygon_eval(
// i_qty, side)
const auto& curr = p.curr_cross_value.get(side);
const auto& prev = p.prev_cross_value.get(side);
auto is_curr_opp = is_shot_opp(side, curr.p.value(), min_edge),
is_prev_opp = is_shot_opp(side, prev.p.value(), min_edge);
auto is_curr_opp = meets_edge(side, curr.p.value(), min_edge),
is_prev_opp = meets_edge(side, prev.p.value(), min_edge);
auto cumm_pass = check_for_cumm_price_qty(
p, side, Price(algo_params.min_cumm_edge),
Quantity(algo_params.min_cumm_qty));
@@ -481,7 +485,7 @@ bool SniperAlgo::_global_constraints_passed() const{
bool SniperAlgo::_is_fire_opp(const SniperPolygon& p,
api::Side side) const{
const auto& side_pq = p.curr_cross_value.get(side);
if(!is_shot_opp(side, side_pq.p.value(), me->algo_params.min_edge))
if(!meets_edge(side, side_pq.p.value(), me->algo_params.min_edge))
return false;
// for 1 lot, it has to be >=1000 usec old
if(side_pq.q.value() == 1){
@@ -509,10 +513,11 @@ bool SniperAlgo::_is_fire_opp(const SniperPolygon& p,
return true;
}
// returns true if
// 1. next_p passes constraints
// 2. passes min edge constraint
// 3. is a better opp than curr_best
// returns true if next_p passes _is_fire_opp and is better
// opp than curr_best, ie :
// a. more edge
// b. same edge but more qty
// c. less number of legs
bool SniperAlgo::_is_better_opp (const SniperPolygon* curr_best,
const SniperPolygon* next_p,
api::Side side) const{
@@ -541,7 +546,7 @@ bool SniperAlgo::_is_better_opp (const SniperPolygon* curr_best,
}
// finds the best polygon to fire for a security (ie all polygons
// with that security as a leg). If none of the polygons is worth
// that share this security as a leg). If none of the polygons is worth
// shooting the second member of the tuple is null
std::tuple<api::Side,SniperPolygon*> SniperAlgo::_find_best_polygon_to_fire(
SecData& sec){
@@ -584,6 +589,11 @@ std::tuple<api::Side, SniperPolygon*> SniperAlgo::_find_best_polygon_to_fire(){
}
}
// for all polygons with sec_data.security as the common leg
// 1. computes the cross prices
// 2. verifies that the global constrains have been passed
// 3. shoots the best polygon if possible
// (logs in case shoot_real_orders is false)
void SniperAlgo::_compute_and_analyze(SecData &sec_data, FireImpetus f_imp) {
// The polygons are computed and then its decided which
// one(s) to shoot (for now, not really, we just shoot
@@ -605,6 +615,9 @@ void SniperAlgo::_compute_and_analyze(SecData &sec_data, FireImpetus f_imp) {
me->algo_services->get_correlation_id(), f_imp);
}
// responsible for firing one polygon, at the
// computed cross values (constraints have already been
// checked)
void SniperAlgo::_fire_polygon_order(SniperPolygon& p,
api::Side p_side,
FireImpetus f_imp){