Some error handling (originating the algo from the wrong top spread)

This commit is contained in:
Taha Afzal committed 2019-08-28 12:27:36 -04:00
1 parent dba3747d98
commit e179f7e5a4
2 files changed
+28 -2

No files matched your search

@@ -77,7 +77,7 @@ IAlgoServices& PyramidAlgo::_algo() const { return *me->algo_services; }
OrderOpResult PyramidAlgo::do_before_launch(IBeforeLaunchAlgoServices& serv) {
auto& def = serv.definition();
if (def.has_custom_def() && def.custom_def().has_dynamic()){
auto conv_res = _convert_params(def.custom_def());
auto conv_res = _get_creation_params(def.custom_def(), serv);
if (std::get<1>(conv_res)){
// params are good
me->params = std::get<0>(conv_res);
@@ -121,7 +121,7 @@ void PyramidAlgo::do_update(const api::orderman::Update& update) {
_algo().terminate_error("Invalid update");
return;
}
auto conv_res = _convert_params(update.custom());
auto conv_res = _get_update_params(update, me->params);
if (!std::get<1>(conv_res)){
_algo().terminate_error("Invalid update");
return;
@@ -222,6 +222,26 @@ PyramidAlgo::_convert_params (const CustomOrderDefinition& cod){
return std::make_tuple(rv,true,std::string(""));
}
std::tuple<PyramidAlgo::PyramidAlgoParams,bool,std::string>
PyramidAlgo::_get_creation_params(const CustomOrderDefinition& cod,
IBeforeLaunchAlgoServices& serv){
auto rv = _convert_params(cod);
if (std::get<1>(rv)){
const auto& p = std::get<0>(rv);
if(p.sec_keys[0].value() != serv.security().id()){
std::get<2>(rv) = "Algo can only be launched from the Top Spread";
std::get<1>(rv) = false;
}
}
return rv;
}
std::tuple<PyramidAlgo::PyramidAlgoParams,bool,std::string>
PyramidAlgo::_get_update_params(const Update&,
const PyramidAlgoParams& curr_params){
return std::make_tuple(curr_params,true,std::string(""));
}
ChildTemplate* PyramidAlgo::_create_order_template (
IBeforeLaunchAlgoServices& serv,
SecurityKey key,
@@ -36,6 +36,12 @@ private:
IAlgoServices& _algo() const ;
static std::tuple<PyramidAlgoParams,bool,std::string> _convert_params (
const bts::api::orderman::CustomOrderDefinition&);
static std::tuple<PyramidAlgoParams,bool,std::string> _get_creation_params(
const bts::api::orderman::CustomOrderDefinition&,
IBeforeLaunchAlgoServices&);
static std::tuple<PyramidAlgoParams,bool,std::string> _get_update_params(
const api::orderman::Update&,
const PyramidAlgoParams& curr_params);
ChildTemplate* _create_order_template (IBeforeLaunchAlgoServices&,
SecurityKey,
api::Side) const;