WIP: manual fills in pos server.
This commit is contained in:
1 parent
88bf448e68
commit
ac45e9bdb2
2 files changed
+28
-19
No files matched your search
@@ -72,8 +72,10 @@ me(new PImpl(context,
|
||||
LOG(persist, Info, "Finished loading all {} manual fills", all.size());
|
||||
ManualFill rec;
|
||||
for (auto const &kvp : all)
|
||||
if (utils::pb::from_string<ManualFill>(kvp.second, &rec))
|
||||
if (utils::pb::from_string<ManualFill>(kvp.second, &rec)) {
|
||||
me->manual_fills_publisher.add_or_update(rec);
|
||||
me->publisher.add_or_update(_on_fill(to_fill(rec),true));
|
||||
}
|
||||
else {
|
||||
LOG(OrderMan, Error,
|
||||
"Could not recover manual fill {} from storage. "
|
||||
@@ -81,15 +83,30 @@ me(new PImpl(context,
|
||||
kvp.first);
|
||||
}
|
||||
me->manual_fills_publisher.flush();
|
||||
me->publisher.flush();
|
||||
}
|
||||
|
||||
bts::api::orderman::Fill PositionServiceServer::to_fill(bts::api::position::ManualFill const&src)
|
||||
{
|
||||
using namespace api::orderman;
|
||||
bts::api::orderman::Fill result;
|
||||
result.set_account(src.account());
|
||||
result.set_security_key(src.security_key());
|
||||
result.set_last_price(src.price());
|
||||
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()));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
const PositionUnit& PositionServiceServer::_on_fill (const Fill& f,
|
||||
bool is_add){
|
||||
std::string fill_account=_fill_account(f);
|
||||
PositionUnit& pu=_get_or_add(fill_account,f.security_key());
|
||||
double avg_price, tot_qty;
|
||||
if(f.fill_kind()==bts::api::orderman::Fill::FILL_KIND_SOD){
|
||||
if(f.side()==api::Side::SIDE_BUY){
|
||||
if(f.side()==api::Side::SIDE_BUY){
|
||||
_avg_price_qty(pu.sod_long_avg_price(),pu.sod_long_pos(),
|
||||
f.last_price(),f.last_shares(),
|
||||
is_add,f.fill_key(),
|
||||
@@ -129,24 +146,14 @@ const PositionUnit& PositionServiceServer::_on_fill (const Fill& f,
|
||||
|
||||
PositionUnit& PositionServiceServer::_get_or_add (const std::string& acct,
|
||||
uint32_t seckey){
|
||||
auto acct_it=me->state.find(acct);
|
||||
if(acct_it==me->state.end())
|
||||
me->state[acct]=std::map<uint32_t,PositionUnit>();
|
||||
acct_it=me->state.find(acct);
|
||||
bts_assert(acct_it!=me->state.end());
|
||||
|
||||
std::map<uint32_t,PositionUnit>& sec_map=acct_it->second;
|
||||
auto sec_it=sec_map.find(seckey);
|
||||
if(sec_it==sec_map.end()){
|
||||
PositionUnit n;
|
||||
n.set_record_id(++me->id);
|
||||
n.set_account(acct);
|
||||
n.set_security_id(seckey);
|
||||
sec_map[seckey]=n;
|
||||
auto &pu = me->state[acct][seckey];
|
||||
if (pu.record_id() == 0) {
|
||||
// new PU
|
||||
pu.set_record_id(++me->id);
|
||||
pu.set_account(acct);
|
||||
pu.set_security_id(seckey);
|
||||
}
|
||||
sec_it=sec_map.find(seckey);
|
||||
bts_assert(sec_it!=sec_map.end());
|
||||
return sec_it->second;
|
||||
return pu;
|
||||
}
|
||||
|
||||
void PositionServiceServer::_avg_price_qty(double base_p,
|
||||
|
||||
Reference in new issue
Block a user