SPARK-1018, Code complete.
This commit is contained in:
1 parent
e2a3055046
commit
65fd36e9ae
5 files changed
+39
-33
No files matched your search
@@ -549,3 +549,16 @@ digraph G {
|
||||
|
||||
* Check with taha on wheter there is overlap between his merging of the book and the one that eric needs
|
||||
* Run a burn test for the shell, see memory usage
|
||||
* Mistakes
|
||||
- Needed one single normalized DB
|
||||
- Orders should be persisted always so we don't have to do crazy stuff
|
||||
to recover them
|
||||
- There is too much going on in the NativeOrder class:
|
||||
- FIX generation
|
||||
- Multiple kinds of native orders
|
||||
- Limit enforcement
|
||||
- Recovery from disk
|
||||
- There should be a better correlation between an order request and
|
||||
its outcome. In the case of errors its pretty lame.
|
||||
- Jetfix gateway threading model is wrong, cannot take one thread for
|
||||
each session
|
||||
@@ -12,13 +12,12 @@ Limiter::Limiter() : me(new PImpl()) {}
|
||||
Limiter::~Limiter() {}
|
||||
|
||||
void Limiter::update(api::admin::AdminData const &) {}
|
||||
void Limiter::add_securities(std::vector<api::Security const *> const &) {}
|
||||
|
||||
void Limiter::add_security(api::Security const &) {}
|
||||
void Limiter::add_to_working_quantity(api::Security const &, AccountID,
|
||||
api::Side, Quantity) {}
|
||||
void Limiter::remove_from_working_quantity(api::Security const &, AccountID,
|
||||
api::Side, Quantity) {}
|
||||
void Limiter::add_fill(api::Security const &, AccountID, api::Side, Quantity) {}
|
||||
|
||||
void Limiter::add(api::Security const &, AccountID, api::Side, Quantity) {}
|
||||
void Limiter::remove(api::Security const &, AccountID, api::Side, Quantity) {}
|
||||
|
||||
|
||||
Limiter::LimiterQueryResult Limiter::can_trade(UserID, AccountID) const {
|
||||
return LimiterQueryResult{true, ""};
|
||||
|
||||
@@ -17,13 +17,12 @@ class Limiter {
|
||||
public:
|
||||
Limiter();
|
||||
void update(api::admin::AdminData const &);
|
||||
void add_securities(std::vector<api::Security const *> const &securities);
|
||||
|
||||
void add_security(api::Security const &new_sec);
|
||||
void add_to_working_quantity(api::Security const &, AccountID, api::Side, Quantity);
|
||||
void remove_from_working_quantity(api::Security const &, AccountID,
|
||||
api::Side, Quantity);
|
||||
void add_fill(api::Security const&, AccountID, api::Side side, Quantity);
|
||||
|
||||
|
||||
void add(api::Security const &, AccountID, api::Side, Quantity);
|
||||
void remove(api::Security const &, AccountID, api::Side, Quantity);
|
||||
|
||||
struct LimiterQueryResult {
|
||||
bool ok;
|
||||
std::string error_msg;
|
||||
|
||||
@@ -26,13 +26,13 @@ OrderStatus map_external_status(NativeOrderStatus);
|
||||
struct NativeOrder::PImpl {
|
||||
PImpl()
|
||||
: services(nullptr), session_services(), sec(nullptr),
|
||||
previous_working_quantity(0) {}
|
||||
previous_position_contribution(0) {}
|
||||
|
||||
OrderServices *services;
|
||||
SessionServices *session_services;
|
||||
|
||||
const api::Security *sec;
|
||||
Quantity previous_working_quantity;
|
||||
Quantity previous_position_contribution;
|
||||
|
||||
OrderDefinition definition;
|
||||
OrderState state;
|
||||
@@ -269,6 +269,7 @@ void NativeOrder::on_activate(Price p, Quantity q,
|
||||
bts_assert(!me->services);
|
||||
me->services = &services;
|
||||
|
||||
|
||||
switch (me->state.status()) {
|
||||
|
||||
case ORDER_STATUS_INACTIVE: {
|
||||
@@ -573,9 +574,6 @@ void NativeOrder::on_exe_report(const NewExecutionReportEvent &er) {
|
||||
}
|
||||
state.set_filled_quantity(er.data->filled_quantity.value());
|
||||
state.set_last_price(er.data->last_price.value());
|
||||
me->services->limiter().add_new_fill(
|
||||
*me->sec, AccountID(me->definition.account_id()),
|
||||
me->definition.side(), Quantity(state.filled_quantity()));
|
||||
}
|
||||
|
||||
state.set_last_msg(er.data->msg);
|
||||
@@ -695,20 +693,20 @@ void NativeOrder::on_gateway_status(const GatewayStatusChangeEvent &ev) {
|
||||
}
|
||||
|
||||
void NativeOrder::report_state() {
|
||||
auto current_working_qty = working_quantity();
|
||||
auto previous_working_qty = me->previous_working_quantity;
|
||||
me->previous_working_quantity = current_working_qty;
|
||||
auto current_position = position_contribution();
|
||||
auto previous_position = me->previous_position_contribution;
|
||||
me->previous_position_contribution = current_position;
|
||||
|
||||
if (current_working_qty.value() > previous_working_qty.value())
|
||||
me->services->limiter().add_to_working_quantity(
|
||||
if (current_position.value() > previous_position.value())
|
||||
me->services->limiter().add(
|
||||
*me->sec, AccountID(me->definition.account_id()),
|
||||
me->definition.side(),
|
||||
Quantity(current_working_qty.value() - previous_working_qty.value()));
|
||||
else if (previous_working_qty.value() > current_working_qty.value())
|
||||
me->services->limiter().remove_from_working_quantity(
|
||||
Quantity(current_position.value() - previous_position.value()));
|
||||
else if (previous_position.value() > current_position.value())
|
||||
me->services->limiter().remove(
|
||||
*me->sec, AccountID(me->definition.account_id()),
|
||||
me->definition.side(),
|
||||
Quantity(current_working_qty.value() - previous_working_qty.value()));
|
||||
Quantity(previous_position.value() - current_position.value()));
|
||||
|
||||
me->services->report_state(me->state);
|
||||
}
|
||||
@@ -910,22 +908,19 @@ void NativeOrder::transition_to_error(
|
||||
transition(ORDER_STATUS_ERROR, msg);
|
||||
}
|
||||
|
||||
Quantity NativeOrder::working_quantity() {
|
||||
Quantity NativeOrder::position_contribution() {
|
||||
switch (me->state.status()) {
|
||||
|
||||
case ORDER_STATUS_WORKING:
|
||||
case ORDER_STATUS_PENDING_WORKING:
|
||||
case ORDER_STATUS_DISCONNECTED:
|
||||
if (me->state.quantity() > me->state.filled_quantity())
|
||||
return Quantity(me->state.quantity() - me->state.filled_quantity());
|
||||
else
|
||||
return Quantity(0);
|
||||
return Quantity(std::max(me->state.quantity(), me->state.filled_quantity()));
|
||||
|
||||
case ORDER_STATUS_REJECTED_BY_SPARK:
|
||||
case ORDER_STATUS_ERROR:
|
||||
case ORDER_STATUS_COMPLETED:
|
||||
case ORDER_STATUS_CANCELED:
|
||||
return Quantity(0);
|
||||
return Quantity(me->state.filled_quantity());
|
||||
|
||||
case ORDER_STATUS_INACTIVE:
|
||||
case OrderStatus_INT_MIN_SENTINEL_DO_NOT_USE_:
|
||||
|
||||
@@ -46,7 +46,7 @@ private:
|
||||
std::string const&msg);
|
||||
|
||||
bool has_exchange_order_id() ;
|
||||
Quantity working_quantity();
|
||||
Quantity position_contribution();
|
||||
bool terminal_state(api::orderman::OrderStatus status) const;
|
||||
api::orderman::NativeOrderState& get_native_state(api::orderman::OrderState &);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user