TaskingEyeAlgo hooked up to theos

This commit is contained in:
Taha Afzal committed 2022-11-29 00:11:04 -05:00
1 parent 84e7bdb586
commit da2cc977a0
5 files changed
+60 -5

No files matched your search

+1 -1
View File
@@ -474,7 +474,7 @@ void OrderServiceServer::set_precomputed_theos(
const api::Response<::bts::api::ResultMessage> &reply) {
LOG(Gen, Info, "OrderServiceServer::set_precomputed_theos count: {}",
precomp_theos.theos().size());
// me->service_bridge->set_precomputed_theos(precomp_theos);
me->service_bridge->set_precomputed_theos(precomp_theos);
bts::api::ResultMessage res = {};
reply(res);
}
+4 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "lib/api/services/OrderService.pb.h"
#include "lib/logging/logging.h"
#include "lib/mercury/events/Event.h"
#include "lib/orderman/calculations/ITheoCalculator.h"
@@ -13,7 +14,9 @@ class TheoEvent : public mercury::Event<TheoEvent> {
bts::orderman::analytics::ITheoCalculator const *theo_calc;
using SynopsisPolicy = mercury::CacheAll<TheoEvent>;
TheoEvent(bts::orderman::analytics::ITheoCalculator const *theo_calc)
: theo_calc(theo_calc) {}
: theo_calc(theo_calc) {
LOG(OrderMan, Info, "TheoEvent::TheoEvent");
}
};
} // namespace bts::orderman
@@ -301,6 +301,7 @@ extern "C" void init_task_eye_plugin(bts::SparkServices &srv) {
tasking_eye_algo.set_dynamic_order_type("Tasking Eye");
*tasking_eye_algo.add_param_desc() = param_double("Edge");
*tasking_eye_algo.add_param_desc() = param_double("Shot Size");
*tasking_eye_algo.add_param_desc() = param_bool("Buy?");
*tasking_eye_algo.add_param_desc() = param_double("Target Quantity");
// array of secs
// using namespace bts::api::orderman;
@@ -1,22 +1,47 @@
#include "TaskingEyeAlgo.h"
#include "lib/api/services/OrderService.pb.h"
#include "lib/domain_model/Security.pb.h"
#include "lib/domain_model/SecurityKey.h"
#include "lib/logging/logging.h"
#include "lib/orderman/ChildOrder.h"
#include "lib/orderman/OrderBuilder.h"
#include "lib/orderman/order_factory/IOrderFactory.h"
#include "lib/orderman/orderman_utils/orderman_common.h"
#include "lib/orderman/orderman_utils/orderman_utils.h"
#include "lib/orderman/orders/OrderOpResult.h"
#include "lib/orderman/orders/algo/ChildTemplate.h"
#include "lib/orderman/orders/algo/IAlgoServices.h"
#include "lib/orderman/orders/algo/IBeforeLaunchAlgoServices.h"
#include "lib/utils/PBUtils.h"
#include <unordered_map>
using namespace bts::api::orderman;
namespace bts::orderman {
struct TaskingEyeAlgo ::PImpl {
IAlgoServices *service_ptr = nullptr;
analytics::ITheoCalculator const *theo_calc = nullptr;
double edge = 100000;
double shot_size = 0;
double target_qty = 0;
api::Side side = api::Side::SIDE_UNDEFINED;
std::vector<SecurityKey> secs = {};
std::unordered_map<SecurityKey, ChildTemplate *> order_map = {};
};
ChildTemplate *get_tea_child_template(
IBeforeLaunchAlgoServices &serv, SecurityKey key, api::Side side) {
OrderDefinition order_def = serv.definition();
order_def.set_security_key(key.value());
order_def.set_side(side);
order_def.set_time_in_force(TimeInForce::TIME_IN_FORCE_IOC);
order_def.mutable_custom_def()->mutable_limit()->MergeFrom(
api::orderman::LimitOrderDefinition());
return &(serv.make_child_template(order_def));
}
TaskingEyeAlgo::TaskingEyeAlgo() : me(new PImpl()) {
LOG(OrderMan, Info, "TaskingEyeAlgo created");
}
@@ -25,6 +50,9 @@ TaskingEyeAlgo::~TaskingEyeAlgo() {}
OrderOpResult TaskingEyeAlgo::do_before_launch(
IBeforeLaunchAlgoServices &serv) {
auto is_data_valid = [&]() {
return me->shot_size > 0 && me->target_qty > 0 && !me->secs.empty();
};
LOG(OrderMan, Info,
"TaskingEyeAlgo::do_before_launch order_key: {} security: {} "
"definition: {}",
@@ -36,9 +64,23 @@ OrderOpResult TaskingEyeAlgo::do_before_launch(
me->edge = get_if<double>(d_params, "Edge").value();
me->shot_size = get_if<double>(d_params, "Shot Size").value();
me->target_qty = get_if<double>(d_params, "Target Quantity").value();
// me->order_template = get_child_template(
// serv, SecurityKey(serv.security().id()), serv.definition().side());
return {};
me->side = get_if<bool>(d_params, "Buy?").value() ? api::SIDE_BUY
: api::SIDE_SELL;
// TODO, get it from the algo params
// BTC 2 DEC 22 19000C, 20000C
me->secs.push_back(SecurityKey{66});
me->secs.push_back(SecurityKey{68});
if (is_data_valid()) {
for (auto sec_key : me->secs) {
auto ct = get_tea_child_template(serv, sec_key, me->side);
me->order_map.insert({sec_key, ct});
LOG(OrderMan, Info,
"TaskingEyeAlgo::do_before_launch order_key: {} successfully "
"created ChildTemplate for sec_key: {}",
serv.order_key(), sec_key);
}
return {};
}
}
return {
bts::api::orderman::OrderError::ORDER_ERROR_INVALID_PARAMETER,
@@ -48,6 +90,7 @@ void TaskingEyeAlgo::do_launch(IAlgoServices &serv) {
LOG(OrderMan, Info, "TaskingEyeAlgo::do_launch order_key: {}",
serv.order_key());
me->service_ptr = &serv;
me->service_ptr->subscribe_theos();
}
void TaskingEyeAlgo::do_launch_attached(IAlgoServices &, OrderKey, ChildState) {
@@ -56,5 +99,11 @@ void TaskingEyeAlgo::do_update(api::orderman::Update const &) {}
void TaskingEyeAlgo::on_child_change(OrderKey, ChildState const &) {}
void TaskingEyeAlgo::on_status(SecurityKey, co2::TradingStatus) {}
void TaskingEyeAlgo::on_timer() {}
void TaskingEyeAlgo::on_theos(
analytics::ITheoCalculator const *theo_calculator) {
me->theo_calc = theo_calculator;
LOG(OrderMan, Info, "TaskingEyeAlgo::on_theos order_key: {}",
me->service_ptr->order_key());
}
} // namespace bts::orderman
@@ -1,5 +1,6 @@
#pragma once
#include "lib/orderman/calculations/ITheoCalculator.h"
#include "lib/orderman/orders/algo/IAlgoOrder.h"
#include <openssl/ossl_typ.h>
@@ -18,6 +19,7 @@ class TaskingEyeAlgo : public IAlgoOrder {
void on_child_change(OrderKey, ChildState const &) override;
void on_status(SecurityKey, co2::TradingStatus) override;
void on_timer() override;
void on_theos(analytics::ITheoCalculator const *theo_calculator) override;
private:
struct PImpl;