Removed Risk Limiter dependency on OrderState.
This commit is contained in:
1 parent
d4de7300ff
commit
bd2e07033e
4 files changed
+23
-54
No files matched your search
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "SharedRiskLimiter.h"
|
||||
|
||||
#include "server/sparkd/order_man/OrderState.h"
|
||||
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/Account.pb.h"
|
||||
@@ -23,11 +22,11 @@ namespace risklimits
|
||||
struct RiskLimiter::PImpl
|
||||
{
|
||||
SharedLimiterData& shared;
|
||||
OrderKey key;
|
||||
orderman::OrderKey key;
|
||||
Quantity remaining_quantity;
|
||||
Quantity filled_quantity;
|
||||
|
||||
PImpl(SharedRiskLimiter& sh, OrderKey ok) :
|
||||
PImpl(SharedRiskLimiter& sh, orderman::OrderKey ok) :
|
||||
shared(sh.shared_data()),
|
||||
key(ok),
|
||||
remaining_quantity(0),
|
||||
@@ -96,7 +95,7 @@ struct RiskLimiter::PImpl
|
||||
};
|
||||
|
||||
|
||||
RiskLimiter::RiskLimiter(SharedRiskLimiter& sh, OrderKey key)
|
||||
RiskLimiter::RiskLimiter(SharedRiskLimiter& sh, orderman::OrderKey key)
|
||||
: me(new PImpl(sh, key))
|
||||
{
|
||||
}
|
||||
@@ -118,20 +117,21 @@ RiskLimiter::RiskLimitResult RiskLimiter::check(Quantity qty, api::BuySell side)
|
||||
}
|
||||
|
||||
|
||||
void RiskLimiter::on_order_state(const OrderState& state)
|
||||
void RiskLimiter::on_order_state(api::BuySell side, Quantity quantity, Quantity filled_quantity)
|
||||
{
|
||||
int working_diff = state.remaining_quantity.value() - me->remaining_quantity.value();
|
||||
if(state.side == api::BUY)
|
||||
auto remaining = Quantity(quantity.value() - filled_quantity.value());
|
||||
int working_diff = remaining.value() - me->remaining_quantity.value();
|
||||
if(side == api::BUY)
|
||||
me->shared.position_info.long_working += working_diff;
|
||||
else
|
||||
me->shared.position_info.short_working += working_diff;
|
||||
|
||||
int filled_diff = state.filled_quantity.value() - me->filled_quantity.value();
|
||||
if(state.side == api::BUY)
|
||||
int filled_diff = filled_quantity.value() - me->filled_quantity.value();
|
||||
if(side == api::BUY)
|
||||
me->shared.position_info.long_position += filled_diff;
|
||||
else
|
||||
me->shared.position_info.short_position += filled_diff;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,6 @@
|
||||
#include <vector>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman {
|
||||
class OrderState;
|
||||
}
|
||||
namespace risklimits
|
||||
{
|
||||
class SharedRiskLimiter;
|
||||
@@ -23,9 +20,9 @@ public:
|
||||
|
||||
RiskLimitResult check(Quantity, api::BuySell) const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
friend class RiskLimitsTests;
|
||||
void on_order_state(const orderman::OrderState&);
|
||||
void on_order_state(api::BuySell side, Quantity quantity, Quantity filled_quantity);
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "../RiskLimitState.h"
|
||||
#include "../IRiskLimitObserver.h"
|
||||
|
||||
#include "server/sparkd/order_man/OrderState.h"
|
||||
#include "server/sparkd/order_man/order_man_utils.h"
|
||||
|
||||
#include "lib/config/config.h"
|
||||
@@ -60,9 +59,9 @@ public:
|
||||
{
|
||||
shared.on_risk_limit_update(risk);
|
||||
}
|
||||
static void order_state_update(RiskLimiter& lim, const OrderState& state)
|
||||
static void order_state_update(RiskLimiter &lim,api::BuySell side, Quantity quantity, Quantity filled_quantity)
|
||||
{
|
||||
lim.on_order_state(state);
|
||||
lim.on_order_state(side,quantity,filled_quantity);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -145,31 +144,6 @@ bool limits_ok(const std::vector<RiskLimitState>& state)
|
||||
return cancel;
|
||||
}
|
||||
|
||||
OrderState order_state(const AccountName& acctname, const OperatorID& opid, const api::Security& security,
|
||||
OrderKey key, api::BuySell side, int filled, int remaining)
|
||||
{
|
||||
OrderState state;
|
||||
state.account_name = acctname;
|
||||
state.operator_id = opid;
|
||||
state.order_key = key;
|
||||
state.security_key = SecurityKey(security.id());
|
||||
state.side = side;
|
||||
|
||||
state.time_in_force = api::orderman::TIF_DAY;
|
||||
state.order_type = api::orderman::OT_LIMIT;
|
||||
state.customer_or_firm = api::orderman::COF_CUSTOMER;
|
||||
state.cti_code = api::orderman::CTI_CTI1;
|
||||
state.exchange_order_id = to<ExchangeOrderID>("exchangeid");
|
||||
state.manual_order_indicator = api::orderman::MOI_YES;
|
||||
state.price = Price(1.0);
|
||||
state.quantity = Quantity(remaining + filled);
|
||||
state.status = api::orderman::OS_NEW;
|
||||
state.avg_fill_price = Price(1.0);
|
||||
state.filled_quantity = Quantity(filled);
|
||||
state.remaining_quantity = Quantity(remaining);
|
||||
return state;
|
||||
}
|
||||
|
||||
TEST_CASE ("RiskLimits Limits", "[risklimits]")
|
||||
{
|
||||
using namespace api;
|
||||
@@ -274,23 +248,21 @@ TEST_CASE ("RiskLimits Limits", "[risklimits]")
|
||||
auto tradeup = rand() % maxpos % limits.max_order_size();
|
||||
auto filled = maxpos - tradeup;
|
||||
auto remaining = 0u;
|
||||
OrderState state = order_state(data.account_info.account, data.operator_info.opid, sec, key,
|
||||
side, filled, remaining);
|
||||
RiskLimitsTests::order_state_update(lim, state);
|
||||
RiskLimitsTests::order_state_update(lim, side,Quantity(remaining+filled),Quantity(filled));
|
||||
res = lim.check(Quantity(tradeup), side);
|
||||
REQUIRE(res.success);
|
||||
if(!res.success)
|
||||
remaining = remaining;
|
||||
// if(!res.success)
|
||||
// remaining = remaining;
|
||||
|
||||
res = lim.check(Quantity(tradeup + (rand() % limits.max_order_size())), side);
|
||||
REQUIRE(!res.success);
|
||||
if(!res.success)
|
||||
remaining = remaining;
|
||||
// if(!res.success)
|
||||
// remaining = remaining;
|
||||
|
||||
res = lim.check(Quantity(tradeup + (rand() % limits.max_order_size())), other_side);
|
||||
REQUIRE(res.success);
|
||||
if(!res.success)
|
||||
remaining = remaining;
|
||||
// if(!res.success)
|
||||
// remaining = remaining;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace bts
|
||||
:
|
||||
_tick_size(this_leg.security().contract_spec().low_tick()),
|
||||
_size_ratio(static_cast<double>(this_leg.quantity())),
|
||||
_spread_security(spread_security),
|
||||
// _spread_security(spread_security),
|
||||
_contract_leg(this_leg),
|
||||
_order_bridge(order_bridge),
|
||||
_bridge_client_id(order_bridge->get_id(this_leg.security(), this_leg.side())),
|
||||
@@ -385,4 +385,4 @@ namespace bts
|
||||
out_quantity = Quantity(out_quantity_u);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user