Merged
This commit is contained in:
commit
b980e39ebb
3 files changed
+96
-6
No files matched your search
@@ -31,6 +31,7 @@ using namespace google::protobuf::util;
|
||||
// as well as pointers to all polygons that contain this security as one of
|
||||
// the legs. Stored in the PImpl state in an unordered_map
|
||||
struct SecData{
|
||||
const bool detailed_logging = false;
|
||||
const SecurityKey key;
|
||||
const api::Security& security;
|
||||
// shared across all polygons
|
||||
@@ -44,16 +45,25 @@ struct SecData{
|
||||
public:
|
||||
// all polygons that have a leg with this security are in this vector
|
||||
std::vector<SniperPolygon*> polygons;
|
||||
SecData (SecurityKey key,
|
||||
SecData (bool detailed_logging,
|
||||
SecurityKey key,
|
||||
const api::Security& security,
|
||||
ChildTemplate* buy_template,
|
||||
ChildTemplate* sell_template)
|
||||
:
|
||||
detailed_logging(detailed_logging),
|
||||
key(key),
|
||||
security(security),
|
||||
buy_template(*buy_template),
|
||||
sell_template(*sell_template) { }
|
||||
sell_template(*sell_template),
|
||||
look_ahead_book(Book(key)) { }
|
||||
void set_book(const Book& bk){
|
||||
if(detailed_logging && use_look_ahead_book)
|
||||
LOG(OrderMan, Info, "Lookahead->Normal {} {} -> {} {}",
|
||||
SpreaderUtils::book_to_str(look_ahead_book, api::Side::SIDE_BUY),
|
||||
SpreaderUtils::book_to_str(look_ahead_book, api::Side::SIDE_SELL),
|
||||
SpreaderUtils::book_to_str(bk, api::Side::SIDE_BUY),
|
||||
SpreaderUtils::book_to_str(bk, api::Side::SIDE_SELL));
|
||||
use_look_ahead_book = false;
|
||||
last_book = current_book;
|
||||
current_book = bk;
|
||||
@@ -69,6 +79,12 @@ struct SecData{
|
||||
agg_side,
|
||||
last_price,last_qty,
|
||||
look_ahead_book);
|
||||
if(detailed_logging && use_look_ahead_book)
|
||||
LOG(OrderMan, Info, "Normal->Lookahead {} {} -> {} {}",
|
||||
SpreaderUtils::book_to_str(current_book, api::Side::SIDE_BUY),
|
||||
SpreaderUtils::book_to_str(current_book, api::Side::SIDE_SELL),
|
||||
SpreaderUtils::book_to_str(look_ahead_book, api::Side::SIDE_BUY),
|
||||
SpreaderUtils::book_to_str(look_ahead_book, api::Side::SIDE_SELL));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -282,7 +298,17 @@ bool _convert_params (const CustomOrderDefinition& cod,
|
||||
out_p.min_cumm_qty = min_cumm_qty.value();
|
||||
out_p.throttle_ms = throttle.value();
|
||||
out_p.use_trade_summary = use_trade_summary.has_value() &&
|
||||
use_trade_summary.value();
|
||||
use_trade_summary.value();
|
||||
LOG(OrderMan, Info, "SniperAlgo loaded parameters polygon_list_file:{} "
|
||||
"shoot_real_orders:{} min_edge:{} max_shot_qty:{} "
|
||||
"leg_payup_ticks:{} min_cumm_edge:{} "
|
||||
"min_cumm_qty:{} use_trade_summary:{} "
|
||||
"throttle_ms:{}",
|
||||
out_p.polygon_list_file, out_p.shoot_real_orders,
|
||||
out_p.min_edge, out_p.max_shot_qty,
|
||||
out_p.leg_payup_ticks, out_p.min_cumm_edge,
|
||||
out_p.min_cumm_qty, out_p.use_trade_summary,
|
||||
out_p.throttle_ms);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -372,7 +398,7 @@ bool check_for_cumm_price_qty(const SniperPolygon& p,
|
||||
Quantity cumm_qty){
|
||||
if(cumm_qty.value()==0)
|
||||
return true;
|
||||
double price_at_cumm_qty = 0;
|
||||
double price_at_cumm_qty;
|
||||
for (auto& l : p.legs){
|
||||
Price l_comp_price; Quantity l_comp_qty;
|
||||
api::Side cross_side = get_leg_cross_market_side(trade_side,l);
|
||||
@@ -514,11 +540,21 @@ void SniperAlgo::on_book(SecurityKey key, const Book& bk) {
|
||||
void SniperAlgo::on_trade_summary_signal(SecurityKey key, api::Side agg_side,
|
||||
Price last_price,
|
||||
Quantity last_quantity){
|
||||
LOG(OrderMan, Info,
|
||||
"SniperAlgo::on_trade_summary_signal okey:{} skey:{} side:{} "
|
||||
"pr:{} qty:{}",
|
||||
me->algo_services->order_key(), key, agg_side,
|
||||
last_price, last_quantity);
|
||||
if(me->algo_params.use_trade_summary){
|
||||
auto it = me->sec_map.find(key);
|
||||
bts_assert(it != me->sec_map.end());
|
||||
auto& sec_data = it->second;
|
||||
sec_data.on_trade_signal(agg_side, last_price, last_quantity);
|
||||
if(me->algo_params.shoot_real_orders)
|
||||
_fire_orders(sec_data);
|
||||
else
|
||||
for (SniperPolygon* p_ptr : sec_data.polygons)
|
||||
log_polygon_eval(me->order_key, *p_ptr,me->algo_params.min_edge);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -596,7 +632,9 @@ bool SniperAlgo::_onetime_setup(IBeforeLaunchAlgoServices& serv,
|
||||
if(me->sec_map.find(sec_key) == me->sec_map.end()){
|
||||
me->sec_map.emplace(
|
||||
sec_key,
|
||||
SecData(sec_key,
|
||||
SecData(
|
||||
!me->algo_params.shoot_real_orders,
|
||||
sec_key,
|
||||
*sec_ptr,
|
||||
_get_ord_template(serv,cod,sec_key,api::Side::SIDE_BUY),
|
||||
_get_ord_template(serv,cod,sec_key,api::Side::SIDE_SELL)));
|
||||
@@ -695,6 +733,8 @@ void SniperAlgo::_fire_orders(SecData& sec_data){
|
||||
auto[order_template,side] = get_leg_order_template(poly_side,l);
|
||||
auto payup_pr = get_payup_price(pr, me->algo_params.leg_payup_ticks,
|
||||
l.sec_data.security, side);
|
||||
payup_pr = Price(bts::securities::raw_round_to_quote_price (
|
||||
payup_pr.value(), l.sec_data.security.contract_spec().low_tick(),side));
|
||||
LOG(OrderMan, Diag, "pr:{} payup_pr:{} qty:{}", pr, payup_pr, qty);
|
||||
l.working_order =
|
||||
me->algo_services->launch_child(order_template,payup_pr,qty);
|
||||
|
||||
@@ -4105,6 +4105,56 @@ TEST_CASE ("net_change_transformation", "[spreader]")
|
||||
REQUIRE(q1_qty_ticks.value()==q1_qty_raw.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE ("sniper", "[spreader]"){
|
||||
SECTION("sweep"){
|
||||
Book bk=get_book(SecurityKey(10),
|
||||
5,
|
||||
new double[5] {50,40,30,20,10},
|
||||
new uint16_t[5] {5,15,25,35,45},
|
||||
new double[5] {60,70,80,90,100},
|
||||
new uint16_t[5] {5,10,15,20,25},
|
||||
true);
|
||||
Book look_ahead_book = bk;
|
||||
// buy sweep
|
||||
bool res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_BUY,Price(80),Quantity(15),look_ahead_book);
|
||||
REQUIRE(res);
|
||||
res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_BUY,Price(80),Quantity(16),look_ahead_book);
|
||||
REQUIRE(!res);
|
||||
res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_BUY,Price(80.01),Quantity(16),look_ahead_book);
|
||||
REQUIRE(!res);
|
||||
res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_BUY,Price(80),Quantity(15),look_ahead_book);
|
||||
REQUIRE(res);
|
||||
bts::securities::test_price_equality(look_ahead_book.bid()[0].price(),80);
|
||||
bts::securities::test_price_equality(look_ahead_book.bid()[0].size(),1);
|
||||
validate_book(look_ahead_book,SecurityKey(10),api::Side::SIDE_BUY,0.001,
|
||||
new double[5] {80,50,40,30,20},
|
||||
new uint16_t[5] {1,5,15,25,35},
|
||||
true);
|
||||
validate_book(look_ahead_book,SecurityKey(10),api::Side::SIDE_SELL,0.001,
|
||||
new double[5] {90,100,os::nan(),os::nan(),os::nan()},
|
||||
new uint16_t[5] {20,25,0,0,0},
|
||||
true);
|
||||
// sell sweep
|
||||
res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_SELL,Price(40),Quantity(15),look_ahead_book);
|
||||
REQUIRE(res);
|
||||
res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_SELL,Price(40),Quantity(16),look_ahead_book);
|
||||
REQUIRE(!res);
|
||||
res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_SELL,Price(40.01),Quantity(15),look_ahead_book);
|
||||
REQUIRE(!res);
|
||||
res = SpreaderUtils::compute_book_from_sweep(bk,api::Side::SIDE_SELL,Price(40),Quantity(15),look_ahead_book);
|
||||
REQUIRE(res);
|
||||
|
||||
validate_book(look_ahead_book,SecurityKey(10),api::Side::SIDE_BUY,0.001,
|
||||
new double[5] {30,20,10,os::nan(),os::nan()},
|
||||
new uint16_t[5] {25,35,45,0,0},
|
||||
true);
|
||||
validate_book(look_ahead_book,SecurityKey(10),api::Side::SIDE_SELL,0.001,
|
||||
new double[5] {40,60,70,80,90},
|
||||
new uint16_t[5] {1,5,10,15,20},
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ void run_sim(SimDB &db, SimDB::SessionID sid, size_t remaining,
|
||||
protos::SimRunOptions const &raw_options) {
|
||||
|
||||
std::unique_ptr<IAlgoModel> algo;
|
||||
if (raw_options.algo() == "Snipe")
|
||||
if (raw_options.algo() == "Sniper")
|
||||
algo.reset(new SniperModel());
|
||||
else if (raw_options.algo() == "PolyObserver")
|
||||
algo.reset(new PolyObserver());
|
||||
|
||||
Reference in new issue
Block a user