Fixed some issues with position service and manual fill integration.
This commit is contained in:
1 parent
3758ac6101
commit
b07700cdc7
1 file changed
+27
-1
@@ -26,6 +26,7 @@ struct PositionServiceServer::PImpl {
|
||||
PositionServiceBase::Position_dataStatefulPublisher publisher;
|
||||
bts::api::orderman::OrderService order_service;
|
||||
std::map<std::string, std::map<uint32_t, PositionUnit>> state;
|
||||
std::map<uint32_t, ManualFill> manual_fills;
|
||||
int id;
|
||||
|
||||
// manual fills management
|
||||
@@ -73,6 +74,7 @@ me(new PImpl(context,
|
||||
ManualFill rec;
|
||||
for (auto const &kvp : all)
|
||||
if (utils::pb::from_string<ManualFill>(kvp.second, &rec)) {
|
||||
me->manual_fills.insert({rec.record_id(), rec});
|
||||
me->manual_fills_publisher.add_or_update(rec);
|
||||
me->publisher.add_or_update(_on_fill(to_fill(rec),true));
|
||||
}
|
||||
@@ -90,9 +92,10 @@ bts::api::orderman::Fill PositionServiceServer::to_fill(bts::api::position::Manu
|
||||
{
|
||||
using namespace api::orderman;
|
||||
bts::api::orderman::Fill result;
|
||||
result.set_account(src.account());
|
||||
result.set_account(src.account_name());
|
||||
result.set_security_key(src.security_key());
|
||||
result.set_last_price(src.price());
|
||||
result.set_side(src.side());
|
||||
result.set_last_shares(src.quantity());
|
||||
result.set_fill_kind(Fill::FILL_KIND_SOD);
|
||||
result.set_fill_key(std::string("manual:")+std::to_string(src.record_id()));
|
||||
@@ -203,14 +206,18 @@ void PositionServiceServer::create_manual_fill(
|
||||
for (auto mf : batch.manual_fill()) {
|
||||
auto id = utils::gen_id ("manual_fills");
|
||||
mf.set_record_id(id);
|
||||
|
||||
me->manual_fills.insert({mf.record_id(), mf});
|
||||
me->manual_fills_store->insert(manual_fills_ns,
|
||||
std::to_string(id),
|
||||
utils::pb::to_string(mf));
|
||||
resp.add_response()->set_ok(true);
|
||||
me->manual_fills_publisher.add_or_update(mf);
|
||||
me->publisher.add_or_update(_on_fill(to_fill(mf),true));
|
||||
}
|
||||
r(resp);
|
||||
me->manual_fills_publisher.flush();
|
||||
me->publisher.flush();
|
||||
}
|
||||
|
||||
void PositionServiceServer::update_manual_fill(
|
||||
@@ -233,10 +240,21 @@ void PositionServiceServer::update_manual_fill(
|
||||
id,
|
||||
utils::pb::to_string(mf));
|
||||
this_resp->set_ok(true);
|
||||
|
||||
// Retrieve old record so we can remove it from position
|
||||
auto it = me->manual_fills.find(mf.record_id());
|
||||
bts_assert(it!= me->manual_fills.end());
|
||||
auto &old = it->second;
|
||||
// remove old
|
||||
me->publisher.add_or_update(_on_fill(to_fill(old),false));
|
||||
// add new
|
||||
me->manual_fills.insert({mf.record_id(), mf});
|
||||
me->publisher.add_or_update(_on_fill(to_fill(mf),true));
|
||||
me->manual_fills_publisher.add_or_update(mf);
|
||||
}
|
||||
}
|
||||
r(resp);
|
||||
me->publisher.flush();
|
||||
me->manual_fills_publisher.flush();
|
||||
}
|
||||
|
||||
@@ -256,6 +274,13 @@ void PositionServiceServer::remove_manual_fill(
|
||||
this_resp->set_msg("Could not find record");
|
||||
}
|
||||
else {
|
||||
// Retrieve old record so we can remove it from position
|
||||
auto it = me->manual_fills.find(mf.record_id());
|
||||
bts_assert(it != me->manual_fills.end());
|
||||
auto &old = it->second;
|
||||
me->publisher.add_or_update(_on_fill(to_fill(old),false));
|
||||
me->manual_fills.erase(it);
|
||||
|
||||
std::set<std::string> to_r ;
|
||||
to_r.insert(id);
|
||||
me->manual_fills_store->remove(manual_fills_ns,to_r);
|
||||
@@ -264,6 +289,7 @@ void PositionServiceServer::remove_manual_fill(
|
||||
}
|
||||
}
|
||||
r(resp);
|
||||
me->publisher.flush();
|
||||
me->manual_fills_publisher.flush();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user