SPARK-1516
This commit is contained in:
1 parent
239acc7821
commit
789a84527d
7 files changed
+54
-17
No files matched your search
@@ -1,15 +1,12 @@
|
||||
FillsCleanup {
|
||||
FillsSoftCleanupCutoff {
|
||||
value {
|
||||
enabled: true
|
||||
sod_hh: 21
|
||||
sod_mm: 30
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
OrdersCleanup {
|
||||
OrdersSoftCleanupCutoff {
|
||||
value {
|
||||
enabled: true
|
||||
extra_days: 1
|
||||
sod_hh: 21
|
||||
sod_mm: 30
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
FillsSoftCleanup {
|
||||
value {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
|
||||
OrdersSoftCleanup {
|
||||
value {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,15 @@
|
||||
syntax='proto2';
|
||||
package bts.config;
|
||||
|
||||
message FillsCleanup{
|
||||
optional bool enabled = 10 [default=true];
|
||||
message FillsSoftCleanupCutoff{
|
||||
// utc time
|
||||
optional uint32 sod_hh = 20 [default=21];
|
||||
optional uint32 sod_mm = 30 [default=30];
|
||||
}
|
||||
|
||||
message OrdersCleanup{
|
||||
optional bool enabled = 10 [default=true];
|
||||
optional uint32 extra_days = 20 [default=1];
|
||||
message OrdersSoftCleanupCutoff{
|
||||
optional uint32 extra_days = 10 [default=1];
|
||||
// utc time
|
||||
optional uint32 sod_hh = 30 [default=21];
|
||||
optional uint32 sod_mm = 40 [default=30];
|
||||
optional uint32 sod_hh = 20 [default=21];
|
||||
optional uint32 sod_mm = 30 [default=30];
|
||||
}
|
||||
@@ -19,3 +19,11 @@ message CVOrderBook {
|
||||
message FilterOrdersWithDanglingSecurities {
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
|
||||
message FillsSoftCleanup{
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
|
||||
message OrdersSoftCleanup{
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "OrderStore.h"
|
||||
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/config/protos/orders_fills_cleanup.pb.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/toggles.pb.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
@@ -8,6 +9,7 @@
|
||||
#include "lib/orderman/events/OrderStateUpdateEvent.h"
|
||||
#include "lib/orderman/events/StoredOrderEvent.h"
|
||||
#include "lib/persistence/SqliteStore.h"
|
||||
#include "SODPositionMap.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -21,7 +23,10 @@ enum class OrderStore::State { WAIT_SEC, READY };
|
||||
struct OrderStore::PImpl {
|
||||
PImpl()
|
||||
: state(State::WAIT_SEC), known_orders(),
|
||||
store(new persistence::SqliteStore("orders")), order_stream() {}
|
||||
store(new persistence::SqliteStore("orders")), order_stream(),
|
||||
soft_cleanup_enabled (config::get<config::toggles::OrdersSoftCleanup>().enabled()),
|
||||
cutoff_time(SODPosition::get_orders_start_time())
|
||||
{}
|
||||
|
||||
State state;
|
||||
const GatewayName gw_name;
|
||||
@@ -29,6 +34,8 @@ struct OrderStore::PImpl {
|
||||
std::unique_ptr<persistence::IStore> store;
|
||||
mercury::Stream<StoredOrderEvent> order_stream;
|
||||
mercury::Actor::SubHandle stored_sec_sub;
|
||||
bool soft_cleanup_enabled;
|
||||
timeval cutoff_time;
|
||||
};
|
||||
|
||||
OrderStore::OrderStore() : me(new PImpl()) {}
|
||||
@@ -81,7 +88,8 @@ void OrderStore::init() {
|
||||
"Order {} refers to unresolved security {}",
|
||||
ok.value(), sk.value());
|
||||
} else {
|
||||
stored_batch.emplace_back(rec);
|
||||
if (!_order_cutoff(rec))
|
||||
stored_batch.emplace_back(rec);
|
||||
me->known_orders[ok] = rec.state().created();
|
||||
}
|
||||
} else
|
||||
@@ -132,5 +140,17 @@ void OrderStore::on_order_state_update(
|
||||
}
|
||||
}
|
||||
|
||||
bool OrderStore::_order_cutoff(const api::orderman::OrderRecord& rec){
|
||||
// TODO: move this to orderutils
|
||||
bool working=
|
||||
(rec.state().status()==
|
||||
api::orderman::OrderStatus::ORDER_STATUS_WORKING) ||
|
||||
(rec.state().status()==
|
||||
api::orderman::OrderStatus::ORDER_STATUS_PENDING_WORKING);
|
||||
return me->soft_cleanup_enabled &&
|
||||
!working &&
|
||||
rec.state().created().seconds() < me->cutoff_time.tv_sec;
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "lib/orderman/orderman_utils/orderman_common.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {namespace orderman {class OrderRecord;}}
|
||||
namespace orderman {
|
||||
class OrderStateUpdateEvent;
|
||||
|
||||
@@ -23,6 +24,7 @@ private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
|
||||
bool _order_cutoff(const api::orderman::OrderRecord& rec);
|
||||
void on_order_state_update(mercury::Update<OrderStateUpdateEvent> const&ev);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "SODPositionMap.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/config/protos/toggles.pb.h"
|
||||
#include "lib/config/protos/orders_fills_cleanup.pb.h"
|
||||
#include "lib/config/config.h"
|
||||
#include <sys/time.h>
|
||||
@@ -11,7 +12,7 @@ namespace orderman{
|
||||
|
||||
SODPosition::SODPosition()
|
||||
:
|
||||
_enabled(config::get<config::FillsCleanup>().enabled()),
|
||||
_enabled (config::get<config::toggles::FillsSoftCleanup>().enabled()),
|
||||
_sod_time(_get_fills_sod_time()){
|
||||
LOG(persist, Info, "SODPosition enabled:{} sec:{}",
|
||||
_enabled, _sod_time.tv_sec);
|
||||
@@ -43,7 +44,7 @@ timeval SODPosition::_subtract_days(const timeval& tv, uint32_t n_days){
|
||||
}
|
||||
|
||||
timeval SODPosition::_get_fills_sod_time(){
|
||||
const auto& fills_cleanup = config::get<config::FillsCleanup>();
|
||||
const auto& fills_cleanup = config::get<config::FillsSoftCleanupCutoff>();
|
||||
timeval sod=_to_timeval(fills_cleanup.sod_hh(),fills_cleanup.sod_mm(),0);
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
@@ -55,7 +56,7 @@ timeval SODPosition::_get_fills_sod_time(){
|
||||
}
|
||||
|
||||
timeval SODPosition::get_orders_start_time(){
|
||||
const auto& orders_cleanup = config::get<config::OrdersCleanup>();
|
||||
const auto& orders_cleanup = config::get<config::OrdersSoftCleanupCutoff>();
|
||||
timeval sod=_to_timeval(orders_cleanup.sod_hh(),orders_cleanup.sod_mm(),0);
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
Reference in new issue
Block a user