Adding sec/spread (optional) parameter and better logs
This commit is contained in:
1 parent
f435203794
commit
3c744e9678
3 files changed
+54
-13
No files matched your search
@@ -260,6 +260,8 @@ extern "C" void init_sniper_plugin(bts::SparkServices &srv) {
|
||||
*sniper.add_param_desc() = param_bool("Include Future Polygons");
|
||||
*sniper.add_param_desc() = param_uint32("Min Days To Exp");
|
||||
*sniper.add_param_desc() = param_uint32("Max Days To Exp");
|
||||
*sniper.add_param_desc() = param_string("Futures");
|
||||
*sniper.add_param_desc() = param_string("Spreads");
|
||||
// shots
|
||||
*sniper.add_param_desc() = param_bool("Shoot Real Orders");
|
||||
*sniper.add_param_desc() = param_bool("Shut Down After Fire");
|
||||
|
||||
@@ -423,11 +423,13 @@ bool SniperAlgo::_onetime_setup(IBeforeLaunchAlgoServices &serv,
|
||||
}
|
||||
if (resolved && passed_filter)
|
||||
resolved_polygons.push_back(p);
|
||||
else
|
||||
LOG(OrderMan, Info,
|
||||
"SniperAlgo::_onetime_setup ok:{} ignoring polygon:{} "
|
||||
"resolved:{} passes_filter:{}",
|
||||
me->order_key, p.p_name, resolved, passed_filter);
|
||||
else{
|
||||
if(!resolved)
|
||||
LOG(OrderMan, Info,
|
||||
"SniperAlgo::_onetime_setup ok:{} ignoring polygon:{} "
|
||||
"resolved:{} passes_filter:{}",
|
||||
me->order_key, p.p_name, resolved, passed_filter);
|
||||
}
|
||||
}
|
||||
for (const auto &p : resolved_polygons) {
|
||||
const auto &sniper_polygon = add_polygon(p);
|
||||
@@ -611,8 +613,9 @@ void SniperAlgo::_fire_polygon_order(SniperPolygon& p,
|
||||
const auto& pq = p.curr_cross_value.get(p_side);
|
||||
uint32_t p_q = std::min(pq.q.value(), me->algo_params.max_shot_qty);
|
||||
// all constraints have been checked
|
||||
LOG(OrderMan, Info, "Firing Polygon pid:{} f_imp:{} corid:{}",
|
||||
p.pid, static_cast<int>(f_imp),
|
||||
LOG(OrderMan, Info,
|
||||
"Firing Polygon pid:{} side:{} p:{} avl_q:{} corid:{}",
|
||||
p.pid, p_side, pq.p, pq.q,
|
||||
me->algo_services->get_correlation_id().sn);
|
||||
for (auto &l : p.legs) {
|
||||
const auto& l_pq = l.cross_value.get(p_side);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <fstream>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -39,9 +40,13 @@ struct SniperAlgoParams {
|
||||
// contracts
|
||||
// all legs of a polygon have to be present in this list
|
||||
std::set<std::string> product_list;
|
||||
// optional filter for futures, empty list is dont care
|
||||
std::set<std::string> futures;
|
||||
// anologous to spread list
|
||||
std::set<std::string> spreads;
|
||||
bool include_future_polygons;
|
||||
uint32_t min_days_to_exp;
|
||||
uint32_t max_days_to_exp;
|
||||
uint32_t max_days_to_exp;
|
||||
// shots
|
||||
bool shoot_real_orders;
|
||||
bool shut_down_after_fire;
|
||||
@@ -314,7 +319,15 @@ void read_polygons(const std::string &file_n, std::vector<FilePolygon> &out_v,
|
||||
|
||||
bool convert_params(const api::orderman::CustomOrderDefinition &cod,
|
||||
SniperAlgoParams &out_p) {
|
||||
|
||||
auto tokenize = [](std::string txt, std::set<std::string>& out_v){
|
||||
boost::algorithm::trim(txt);
|
||||
if(txt.size()>0){
|
||||
std::vector<std::string> toks;
|
||||
boost::split(toks, txt, boost::is_any_of(","));
|
||||
for (auto &p : toks)
|
||||
out_v.insert(p);
|
||||
}
|
||||
};
|
||||
const api::orderman::DynamicOrderDefinition &def = cod.dynamic();
|
||||
const auto ¶ms = def.order_params();
|
||||
|
||||
@@ -322,6 +335,8 @@ bool convert_params(const api::orderman::CustomOrderDefinition &cod,
|
||||
// contracts
|
||||
auto products = get_if<std::string>(params, "Products");
|
||||
auto include_future_polygons = get_if<bool>(params, "Include Future Polygons");
|
||||
auto futures = get_if<std::string>(params, "Futures");
|
||||
auto spreads = get_if<std::string>(params, "Spreads");
|
||||
auto min_days_to_exp = get_if<uint32_t>(params, "Min Days To Exp");
|
||||
auto max_days_to_exp = get_if<uint32_t>(params, "Max Days To Exp");
|
||||
// shots
|
||||
@@ -357,7 +372,13 @@ bool convert_params(const api::orderman::CustomOrderDefinition &cod,
|
||||
boost::split(toks, products_str, boost::is_any_of(","));
|
||||
for (auto &p : toks)
|
||||
out_p.product_list.insert(p);
|
||||
out_p.include_future_polygons = include_future_polygons.value();
|
||||
out_p.include_future_polygons = include_future_polygons.value();
|
||||
|
||||
if(futures.has_value())
|
||||
tokenize(futures.value(), out_p.futures);
|
||||
if(spreads.has_value())
|
||||
tokenize(spreads.value(), out_p.spreads);
|
||||
|
||||
out_p.min_days_to_exp = min_days_to_exp.value();
|
||||
out_p.max_days_to_exp = max_days_to_exp.value();
|
||||
|
||||
@@ -463,6 +484,10 @@ long long usecs_since(const bts::datetime::PTime& ts){
|
||||
return bts::datetime::usecs_since(ts);
|
||||
}
|
||||
|
||||
std::string sec_desc(const api::Security& sec){
|
||||
return sec.glbx().security_desc();
|
||||
}
|
||||
|
||||
void print_exp(const bts::api::Security& leg_sec){
|
||||
auto print_fut_exp = [](const bts::api::Security& f_sec){
|
||||
bts_assert(f_sec.has_future());
|
||||
@@ -516,10 +541,21 @@ bool passes_filter(const bts::api::Security& leg_sec,
|
||||
const SniperAlgoParams& params){
|
||||
const auto &prods = params.product_list;
|
||||
if(prods.find(leg_sec.symbol()) == prods.end())
|
||||
return false;
|
||||
if(!params.include_future_polygons)
|
||||
if(leg_sec.has_future())
|
||||
return false;
|
||||
// future constraints
|
||||
if(leg_sec.has_future()){
|
||||
if(!params.include_future_polygons)
|
||||
return false;
|
||||
if(params.futures.size() > 0 &&
|
||||
params.futures.find(sec_desc(leg_sec)) == params.futures.end())
|
||||
return false;
|
||||
}
|
||||
if(leg_sec.has_spread()){
|
||||
if(params.spreads.size() > 0 &&
|
||||
params.spreads.find(sec_desc(leg_sec)) == params.spreads.end())
|
||||
return false;
|
||||
}
|
||||
// exp range constraints
|
||||
auto[min,max] = get_exp_range(leg_sec);
|
||||
if(min <= static_cast<int>(params.min_days_to_exp) ||
|
||||
max >= static_cast<int>(params.max_days_to_exp))
|
||||
|
||||
Reference in new issue
Block a user