diff --git a/src/server/sparkd/orderman/actors/SODPositionMap.cpp b/src/server/sparkd/orderman/actors/SODPositionMap.cpp index a60ac492b..588e928fb 100644 --- a/src/server/sparkd/orderman/actors/SODPositionMap.cpp +++ b/src/server/sparkd/orderman/actors/SODPositionMap.cpp @@ -1,10 +1,50 @@ #include "SODPositionMap.h" #include "lib/logging/logging.h" #include "lib/utils/bts_assert.h" +#include namespace bts{ namespace orderman{ +SODPosition::SODPosition() +:_sod_time(_get_sod_time()){ +} + +timeval SODPosition::_to_timeval(uint16_t hh, uint16_t mm, uint16_t ss){ + bts_assert(hh<24); + bts_assert(mm<60); + bts_assert(ss<60); + time_t secs; + time (&secs); // seconds since epoch + struct tm* ptm = gmtime (&secs); + ptm->tm_hour=hh; + ptm->tm_min=mm; + ptm->tm_sec=ss; + secs=mktime(ptm); + timeval rv; + rv.tv_sec=secs; + rv.tv_usec=0; + return rv; +} + +timeval SODPosition::_subtract_day(const timeval& tv){ + uint32_t secs_in_day=86400; + bts_assert(tv.tv_sec>secs_in_day); + timeval rv=tv; + rv.tv_sec=rv.tv_sec-secs_in_day; + return rv; +} + +timeval SODPosition::_get_sod_time(){ + uint16_t hh=21,mm=30; //TODO get it fro config (1640 central) + timeval sod=_to_timeval(hh,mm,0); + timeval now; + gettimeofday(&now, NULL); + if(sod.tv_sec >= now.tv_sec) + sod=_subtract_day(sod); + return sod; +} + void SODPosition::_merge_pos(Fill& pos, const Fill& fill){ bts_assert(pos.security_key()==fill.security_key()); bts_assert(pos.account()==fill.account()); diff --git a/src/server/sparkd/orderman/actors/SODPositionMap.h b/src/server/sparkd/orderman/actors/SODPositionMap.h index 9fd699f83..bd634e6ee 100644 --- a/src/server/sparkd/orderman/actors/SODPositionMap.h +++ b/src/server/sparkd/orderman/actors/SODPositionMap.h @@ -14,10 +14,16 @@ class SODPosition{ private: std::map _sod_map; std::map _sec_ptr_map; + const timeval _sod_time; private: + // converts the timeval to todat:hh:mm:ss + static timeval _to_timeval(uint16_t hh, uint16_t mm, uint16_t ss); + static timeval _subtract_day(const timeval& tv); + timeval _get_sod_time(); void _merge_pos(Fill& pos, const Fill& fill); - void _zero_pos(Fill& pos, const Fill& fill, api::Side side); + void _zero_pos(Fill& pos, const Fill& fill, api::Side side); public: + SODPosition(); void add_fill_to_sod_pos(const Fill& fill); std::vector sod_pos(); };