Comments mainly
This commit is contained in:
1 parent
edba0e1cd7
commit
76f582613b
4 files changed
+35
-40
No files matched your search
@@ -135,7 +135,7 @@ PositionUnit& PositionMap::_get_or_add(uint32_t account_id, uint32_t seckey){
|
||||
pu.set_security_id(seckey);
|
||||
pu.set_account_id(account_id);
|
||||
// zeroing out all pos's
|
||||
_zero_out(pu);
|
||||
_zero_out_pos_unit(pu);
|
||||
}
|
||||
_fill_account(pu);
|
||||
return pu;
|
||||
@@ -149,45 +149,48 @@ PositionMap::FillType PositionMap::_fill_type(const Fill& f) const{
|
||||
}
|
||||
|
||||
void PositionMap::_reset_sod(){
|
||||
// 1.
|
||||
// zero'ing out all pos
|
||||
// important : once an acct_id,sec_key entry is made
|
||||
// it is never deleted, only 0's out
|
||||
for (auto &acct_p : _pos_map)
|
||||
for (auto &sec_p : acct_p.second)
|
||||
_zero_out(sec_p.second);
|
||||
for (auto& acct_p : _base_pos_map) {
|
||||
uint32_t account_id = acct_p.first;
|
||||
_zero_out_pos_unit(sec_p.second);
|
||||
// 2.
|
||||
// entering the base pos as SOD
|
||||
// important : base pos is always entered as current SOD
|
||||
for (auto& acct_p : _base_pos_map)
|
||||
for (auto& sec_p : acct_p.second) {
|
||||
uint32_t sec_key = sec_p.first;
|
||||
const auto& e = sec_p.second;
|
||||
PositionUnit& pu = _get_or_add(account_id, sec_key);
|
||||
pu.mutable_sod()->CopyFrom(e);
|
||||
PositionUnit& pu = _get_or_add(acct_p.first, sec_p.first);
|
||||
pu.mutable_sod()->CopyFrom(sec_p.second);
|
||||
}
|
||||
}
|
||||
// 3.
|
||||
// rentering all the fills
|
||||
for (auto& fill_p : _fill_map)
|
||||
on_fill(fill_p.second,true);
|
||||
// 4.
|
||||
// rentering all the manual fills
|
||||
for (auto& mfill_p : _manual_fill_map)
|
||||
on_manual_fill(mfill_p.second,true);
|
||||
}
|
||||
|
||||
bool PositionMap::_fill_account (PositionUnit& u){
|
||||
void PositionMap::_fill_account (PositionUnit& u){
|
||||
if (u.account().empty()){
|
||||
const auto& it = _account_id_map.find(u.account_id());
|
||||
if (it != _account_id_map.end()){
|
||||
if (it != _account_id_map.end())
|
||||
u.set_account(it->second);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PositionMap::_zero_out (bts::api::position::PositionUnit& pu){
|
||||
_zero_out_entry(*pu.mutable_day());
|
||||
_zero_out_entry(*pu.mutable_sod());
|
||||
_zero_out_entry(*pu.mutable_local());
|
||||
_zero_out_entry(*pu.mutable_admin_day());
|
||||
_zero_out_entry(*pu.mutable_admin_sod());
|
||||
void PositionMap::_zero_out_pos_unit (bts::api::position::PositionUnit& pu){
|
||||
_zero_out_pos_entry(*pu.mutable_day());
|
||||
_zero_out_pos_entry(*pu.mutable_sod());
|
||||
_zero_out_pos_entry(*pu.mutable_local());
|
||||
_zero_out_pos_entry(*pu.mutable_admin_day());
|
||||
_zero_out_pos_entry(*pu.mutable_admin_sod());
|
||||
}
|
||||
|
||||
void PositionMap::_zero_out_entry (bts::api::position::PositionEntry& p){
|
||||
void PositionMap::_zero_out_pos_entry (bts::api::position::PositionEntry& p){
|
||||
p.set_long_pos(0);
|
||||
p.set_long_avg_price(0);
|
||||
p.set_short_pos(0);
|
||||
|
||||
@@ -39,9 +39,9 @@ private:
|
||||
void _reset_sod();
|
||||
// returns true if the account went from unpop'ed
|
||||
// to populated
|
||||
bool _fill_account (bts::api::position::PositionUnit&);
|
||||
void _zero_out (bts::api::position::PositionUnit&);
|
||||
void _zero_out_entry (bts::api::position::PositionEntry&);
|
||||
void _fill_account (bts::api::position::PositionUnit&);
|
||||
void _zero_out_pos_unit (bts::api::position::PositionUnit&);
|
||||
void _zero_out_pos_entry (bts::api::position::PositionEntry&);
|
||||
public:
|
||||
PositionMap();
|
||||
const bts::api::position::PositionUnit& on_fill (
|
||||
|
||||
@@ -277,9 +277,10 @@ void PositionServiceServer::remove_manual_fill(
|
||||
}
|
||||
|
||||
void PositionServiceServer::set_base_position(
|
||||
const ::bts::api::position::BasePositionBatch& req,
|
||||
const api::Response<::bts::api::position::SetBasePositionResponse> &) {
|
||||
me->state.set_base_position(req);
|
||||
const BasePositionBatch& req,
|
||||
const api::Response<SetBasePositionResponse>&) {
|
||||
me->state.set_base_position(req);
|
||||
_clear_and_publish_pos();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -35,28 +35,19 @@ class PositionServiceServer : public bts::api::position::PositionServiceBase {
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
enum FillType{
|
||||
BASE,
|
||||
SOD,
|
||||
DAY
|
||||
};
|
||||
struct BasePositionEntry{
|
||||
timeval current_as_of;
|
||||
api::position::PositionEntry pos;
|
||||
};
|
||||
// this is the function that aggrgates the
|
||||
// position. is_add is to indicate if a row
|
||||
// is added or removed
|
||||
const bts::api::position::PositionUnit &
|
||||
_on_fill(const bts::api::orderman::Fill &fill, bool is_add);
|
||||
// analogous to the above, for manual fills (this inclused
|
||||
// both client(local) and server(admin) fills)
|
||||
const bts::api::position::PositionUnit &
|
||||
_on_manual_fill(const api::position::ManualFill &fill, bool is_add);
|
||||
_on_manual_fill(const api::position::ManualFill &fill, bool is_add);
|
||||
void _periodic_poll();
|
||||
// recomputes the whole pnl (no increments) and publishes it
|
||||
void _compute_pnl_and_publish();
|
||||
void _set_admin_data(const api::admin::AdminData &admin_data);
|
||||
//FillType _fill_type(const bts::api::orderman::Fill &fill) const;
|
||||
// this is when we have to reset the
|
||||
void _recompute_all();
|
||||
void _clear_and_publish_pos();
|
||||
public:
|
||||
PositionServiceServer(bts::api::ServiceContext &context, md::MDClient &);
|
||||
|
||||
Reference in new issue
Block a user