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

This commit is contained in:
Pedro Pinto committed 2020-09-22 11:17:08 -04:00
commit 6bf4966fb3
4 files changed
+119 -4

No files matched your search

@@ -0,0 +1,40 @@
#include "OrderTranslator.h"
#include "SimSpreader.h"
#include "../AlgoEvent.h"
#include "../IAlgoModel.h"
using namespace bts::orderman;
namespace bts::spartan::mdp3 {
struct OrderTranslator::PImpl {
SimSpreader& spreader;
ISimServices* sim_services = nullptr;
PImpl(SimSpreader& spr)
:
spreader(spr){
}
};
OrderTranslator::OrderTranslator(SimSpreader& spreader)
:
me(new PImpl(spreader)){
}
void OrderTranslator::init(ISimServices& sim_services){
me->sim_services = &sim_services;
}
void OrderTranslator::place_new_order(OrderKey, Price, Quantity){
}
void OrderTranslator::modify_order(OrderKey, Price, Quantity){
}
void OrderTranslator::cxl_order(OrderKey){
}
void OrderTranslator::route_update_to_spreader(){
}
}
@@ -0,0 +1,29 @@
#pragma once
#include "../../../common/mdp3_common.h"
#include "lib/orderman/orderman_utils/orderman_common.h"
class OrderUpdate;
namespace bts::spartan::mdp3 {
class ISimServices;
class SimSpreader;
class OrderTranslator {
private:
struct PImpl;
std::unique_ptr<PImpl> me;
public:
OrderTranslator(SimSpreader&);
void init(ISimServices&);
// routes old style order to ISimServices
// (SpreaderChildOrderState's calls need to end up here)
void place_new_order(bts::orderman::OrderKey, Price, Quantity);
void modify_order(bts::orderman::OrderKey, Price, Quantity);
void cxl_order(bts::orderman::OrderKey);
// Sends ISimServices's updates to spreader
void route_update_to_spreader();
};
}
@@ -4,6 +4,7 @@
#include "lib/sparkproto/SparkProtos.pb.h"
#include "lib/orderman/orders/spreader_orders/SpreaderOrder.h"
#include "lib/orderman/orders/spreader_orders/spreader/external_interfacing/SpreaderPreActivationOrderServices.h"
#include "lib/orderman/orderman_utils/Book.h"
using namespace bts::orderman;
using namespace bts::api::orderman;
@@ -11,25 +12,55 @@ using namespace bts::api::orderman;
namespace bts::spartan::mdp3 {
void translate_book(const MBPUpdate& u_in,
bts::orderman::Book& b_out){
size_t i=-1;
for (auto const& bl : u_in.mbp_buy)
if(++i<5)
b_out.side(api::Side::SIDE_BUY)[i] =
md::PriceSize (bl.price,bl.quantity.value());
for (auto const& bl : u_in.mbp_sell)
if(++i<5)
b_out.side(api::Side::SIDE_SELL)[i] =
md::PriceSize (bl.price,bl.quantity.value());
}
bool compare_keys (SecurityKey spark_k,
MDP3SecurityID spartan_k){
return static_cast<int>(spark_k.value()) == spartan_k.value();
}
bts::orderman::Book* find_book(MDP3SecurityID id,
std::vector<bts::orderman::Book>& books){
for (auto& b : books)
if(compare_keys(b.security_key(),id))
return &b;
return nullptr;
}
struct SimSpreader::PImpl {
const OrderDefinition order_def;
const SpreaderPreActivationOrderServices pao_services;
const SpreaderOrderServices so_services = SpreaderOrderServices(nullptr);
ISimServices* sim_services = nullptr;
SpreaderOrder spreader;
SpreaderOrder spreader;
std::vector<bts::orderman::Book> books;
PImpl(const OrderDefinition& order_def,
const bts::api::Security& sec)
:
order_def(order_def),
pao_services(sec),
spreader(){
spreader(),
books(){
for (const auto& l : sec.synthetic().legs())
books.emplace_back(SecurityKey(l.security().id()));
}
};
SimSpreader::SimSpreader(const OrderDefinition& order_def,
const bts::api::Security& sec)
:
me(new PImpl(order_def,sec)){
me(new PImpl(order_def,sec)){
}
void SimSpreader::init(ISimServices& sim_services){
@@ -38,7 +69,21 @@ void SimSpreader::init(ISimServices& sim_services){
me->spreader.test_only_on_init_new (me->order_def,
me->pao_services);
}
void SimSpreader::on_notification(AlgoNotification const&){
void SimSpreader::on_notification(AlgoNotification const& ev) {
if(std::holds_alternative<MBPUpdate>(ev.event)){
// book update
const MBPUpdate& bk = std::get<MBPUpdate>(ev.event);
// copy book
bts::orderman::Book* leg_bk = find_book(bk.security_id, me->books);
if(leg_bk != nullptr){
auto& leg_bk_r = *leg_bk;
translate_book(bk, leg_bk_r);
me->spreader.test_only_on_book_update(leg_bk_r);
}
}
else{
}
}
}
@@ -1,6 +1,7 @@
#pragma once
#include "../../../common/mdp3_common.h"
#include "OrderTranslator.h"
#include "../AlgoEvent.h"
#include "../IAlgoModel.h"