SPARK-1516 sod pos aggregation hooked to time calcs

This commit is contained in:
Taha Afzal committed 2018-07-28 22:20:43 -04:00
1 parent 9ca4f85ea1
commit 7ff42506af
2 files changed
+47 -1

No files matched your search

@@ -1,10 +1,50 @@
#include "SODPositionMap.h"
#include "lib/logging/logging.h"
#include "lib/utils/bts_assert.h"
#include <sys/time.h>
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());
@@ -14,10 +14,16 @@ class SODPosition{
private:
std::map<std::string,SecPosMap> _sod_map;
std::map<uint32_t, const api::Security*> _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<const Fill*> sod_pos();
};