Merge branch 'prod' of bitbucket.org:bluetradesys/spark

This commit is contained in:
Taha Afzal committed 2018-09-18 14:11:35 -04:00
commit 8730a7def3
3 files changed
+46 -6

No files matched your search

+3 -2
View File
@@ -24,8 +24,7 @@ struct OrderStore::PImpl {
PImpl()
: state(State::WAIT_SEC), known_orders(),
store(new persistence::SqliteStore("orders")), order_stream(),
soft_cleanup_enabled (config::get<config::toggles::OrdersSoftCleanup>().enabled()),
cutoff_time(SODPosition::get_orders_start_time())
soft_cleanup_enabled (config::get<config::toggles::OrdersSoftCleanup>().enabled())
{}
State state;
@@ -76,6 +75,8 @@ void OrderStore::init() {
auto all = me->store->retrieve_all()[orders_ns];
LOG(persist, Info, "Finished loading all {} orders", all.size());
me->cutoff_time=SODPosition::get_order_cutoff_time(all);
for (auto const &kvp : all)
if (utils::pb::from_string<api::orderman::OrderRecord>(
kvp.second, &rec)) {
+41 -3
View File
@@ -4,6 +4,7 @@
#include "lib/config/protos/toggles.pb.h"
#include "lib/config/protos/orders_fills_cleanup.pb.h"
#include "lib/config/config.h"
#include "lib/utils/PBUtils.h"
#include <sys/time.h>
#include <sstream>
@@ -18,12 +19,14 @@ _sod_time(_get_fills_sod_time()){
_enabled, _sod_time.tv_sec);
}
// returns the timeval for today's hh,mm,ss
// timeval is the microsecons from epoch)
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
time (&secs); // seconds since epoch (utc)
struct tm* ptm = gmtime (&secs);
ptm->tm_hour=hh;
ptm->tm_min=mm;
@@ -37,9 +40,8 @@ timeval SODPosition::_to_timeval(uint16_t hh, uint16_t mm, uint16_t ss){
timeval SODPosition::_subtract_days(const timeval& tv, uint32_t n_days){
uint32_t secs_in_day=86400*n_days;
bts_assert(tv.tv_sec>secs_in_day);
timeval rv=tv;
rv.tv_sec=rv.tv_sec-secs_in_day;
rv.tv_sec=(rv.tv_sec > secs_in_day) ? rv.tv_sec-secs_in_day : 0;
return rv;
}
@@ -69,6 +71,42 @@ timeval SODPosition::get_orders_start_time(){
return sod;
}
timeval SODPosition::get_order_cutoff_time(
const std::map<std::string,std::string>& order_map){
//returns true is t1 >= t2
auto compare_ts = [&](google::protobuf::Timestamp t1, google::protobuf::Timestamp t2) -> bool
{
if (t1.seconds() > t2.seconds())
return true;
else if (t1.seconds() < t2.seconds())
return false;
else
return t1.nanos() >= t2.nanos();
};
google::protobuf::Timestamp max_ts;
max_ts.set_seconds(0);
max_ts.set_nanos(0);
for (auto const &kvp : order_map){
OrderRecord trec;
if (utils::pb::from_string<api::orderman::OrderRecord>(kvp.second, &trec)){
const auto& ts = trec.state().created();
if(compare_ts(ts,max_ts))
(&max_ts)->CopyFrom(ts);
}
else
LOG(OrderMan, Error,
"Could not recover order {} from storage. "
"This should be investigated",
kvp.first);
}
timeval rv;
rv.tv_sec=max_ts.seconds();
rv.tv_usec=static_cast<double>(max_ts.nanos())/1000;
const auto& orders_cleanup = config::get<config::OrdersSoftCleanupCutoff>();
return _subtract_days(rv,orders_cleanup.extra_days());
}
std::string SODPosition::_sod_fill_id(const Fill& fill,api::Side side){
//sod:acct:long/short:sec
std::ostringstream oss;
+2 -1
View File
@@ -31,9 +31,10 @@ public:
SODPosition();
// all inactive orders before this time are not published
static timeval get_orders_start_time();
static timeval get_order_cutoff_time(const std::map<std::string,std::string>& ordermap);
bool add_fill_to_sod_pos(const Fill& fill);
void add_sod_pos_as_fill_events(std::vector<StoredFillEvent>& fill_events,
std::map<SecurityKey, const api::Security*> sec_map);
std::map<SecurityKey, const api::Security*> sec_map);
};
}}