diff --git a/src/lib/orderman/limiter/ProductLimitNode.cpp b/src/lib/orderman/limiter/ProductLimitNode.cpp index 5e78bed62..7e1992946 100644 --- a/src/lib/orderman/limiter/ProductLimitNode.cpp +++ b/src/lib/orderman/limiter/ProductLimitNode.cpp @@ -5,14 +5,16 @@ namespace orderman { ProductLimitNode::ProductLimitNode( uint32_t account_id, - uint32_t, // parent_account_id, + uint32_t, const bts::api::admin::AccountProductPositionLimitUnit &limit, bool enforce_net) - : _account_id(account_id), - //_parent_account_id(parent_account_id), - _limit(limit), _enforce_net(enforce_net), - _long_pos_limit(limit.long_position_limit()), - _short_pos_limit(limit.short_position_limit()), _long_pos(0), - _short_pos(0) {} + : + _account_id(account_id), + _limit(limit), + _enforce_net(enforce_net), + _long_pos_limit(limit.long_position_limit()), + _short_pos_limit(limit.short_position_limit()), + _long_pos(0), + _short_pos(0) {} } // namespace orderman -} // namespace bts +} // namespace bts \ No newline at end of file diff --git a/src/lib/orderman/limiter/ProductLimitNode.h b/src/lib/orderman/limiter/ProductLimitNode.h index c6f675454..a664165af 100644 --- a/src/lib/orderman/limiter/ProductLimitNode.h +++ b/src/lib/orderman/limiter/ProductLimitNode.h @@ -11,32 +11,37 @@ namespace bts{ namespace orderman{ -// Keeps the running position and risk limits -// for a single -// Its the equivelant to SecurityLimitNode -// however it does not need to check for -// clip size. +// Scope : +// All the level position limits are +// enforced here. +// Keeps the running long and short position (both working +// orders and positions - which is transparent to this class) +// and risk limits class ProductLimitNode{ private: - const uint32_t _account_id; // , _parent_account_id; + const uint32_t _account_id; + // this is only kept to faciliate testing const bts::api::admin::AccountProductPositionLimitUnit& _limit; const bool _enforce_net; const uint32_t _long_pos_limit, _short_pos_limit; // this is the only state here uint32_t _long_pos, _short_pos; public: - ProductLimitNode(uint32_t account_id, - uint32_t parent_account_id, - const bts::api::admin::AccountProductPositionLimitUnit& limit, - bool enforce_net); - // accessors - //////////// - uint32_t account_id() const {return _account_id;} + ProductLimitNode( + uint32_t account_id, + uint32_t parent_account_id, + const bts::api::admin::AccountProductPositionLimitUnit& limit, + bool enforce_net); + // accessors /////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + uint32_t account_id() const { + return _account_id; + } int net_pos() const { return static_cast(_long_pos)-static_cast(_short_pos); } - // position updates - /////////////////// + // position updates //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// void copy_positions_from(const ProductLimitNode& source){ _long_pos=source._long_pos; _short_pos=source._short_pos; @@ -55,37 +60,42 @@ public: } // risk limit checks //////////////////// - Limiter::LimiterQueryResult can_send_new_order(api::Side side, Quantity quantity) const{ + Limiter::LimiterQueryResult can_send_new_order(api::Side side, + Quantity quantity) const{ Limiter::LimiterQueryResult result; if (_enforce_net) - LimiterUtils::can_send_new_order_net (side, - quantity, - false, - static_cast(_long_pos_limit), - -1 * static_cast(_short_pos_limit), - net_pos(), - result); + LimiterUtils::can_send_new_order_net ( + side, + quantity, + false, + static_cast(_long_pos_limit), + -1 * static_cast(_short_pos_limit), + net_pos(), + result); else - LimiterUtils::can_send_new_order_abs (side, + LimiterUtils::can_send_new_order_abs (side, quantity, - _long_pos_limit, + _long_pos_limit, _short_pos_limit, _long_pos, _short_pos, result); return result; } - Limiter::LimiterQueryResult can_update_order(api::Side side, Quantity from, Quantity to) const{ + Limiter::LimiterQueryResult can_update_order(api::Side side, + Quantity from, + Quantity to) const{ Limiter::LimiterQueryResult result; if(_enforce_net) - LimiterUtils::can_update_order_net (side, - from, - to, - false, - static_cast(_long_pos_limit), - -1 * static_cast(_short_pos_limit), - net_pos(), - result); + LimiterUtils::can_update_order_net ( + side, + from, + to, + false, + static_cast(_long_pos_limit), + -1 * static_cast(_short_pos_limit), + net_pos(), + result); else LimiterUtils::can_update_order_abs (side, from, @@ -108,6 +118,9 @@ public: } // test only functions ////////////////////// - const bts::api::admin::AccountProductPositionLimitUnit& test_only_func_limit() const {return _limit;} + const bts::api::admin::AccountProductPositionLimitUnit& + test_only_func_limit() const { + return _limit; + } }; }} diff --git a/src/lib/orderman/limiter/SecurityLimitNode.cpp b/src/lib/orderman/limiter/SecurityLimitNode.cpp index 6ba45afb3..f5e8852f2 100644 --- a/src/lib/orderman/limiter/SecurityLimitNode.cpp +++ b/src/lib/orderman/limiter/SecurityLimitNode.cpp @@ -13,10 +13,10 @@ SecurityLimitNode::SecurityLimitNode( : _account_id(account_id), _clip_size(clip_size), - _product_node(product_node), - _long_pos(0), - _short_pos(0) - {} + _product_node(product_node), + _long_pos(0), + _short_pos(0) + {} } // namespace orderman -} // namespace bts +} // namespace bts \ No newline at end of file diff --git a/src/lib/orderman/limiter/SecurityLimitNode.h b/src/lib/orderman/limiter/SecurityLimitNode.h index 5137a2486..3e1a70977 100644 --- a/src/lib/orderman/limiter/SecurityLimitNode.h +++ b/src/lib/orderman/limiter/SecurityLimitNode.h @@ -16,16 +16,22 @@ namespace bts{ namespace orderman{ -// Keeps the running position and risk limits -// (both position limits and clip sizes) for a -// single -// It also keeps a reference to the product -// node, that is updated as fills come in. + +// Scope : +// Keeps the running position and clip limits +// for a single . +// Has a reference to the ProductLimitNode for the product +// that this security belongs to. +// Position limits are enforced through the ProductLimitNode class SecurityLimitNode{ private: const uint32_t _account_id; const uint32_t _clip_size; ProductLimitNode& _product_node; + // this is the committed position. working order + // adds and removes are passed straight to the + // product node. Position updates are changed to + // increments and then passed uint32_t _long_pos; uint32_t _short_pos; public: @@ -35,12 +41,13 @@ public: bool apply_sec_position_limits, ProductLimitNode& product_limit, uint32_t clip_size); - //accessors - /////////// - uint32_t account_id() const {return _account_id;} - //int net_pos() const {return 0;} - // position updates - /////////////////// + // accessors /////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + uint32_t account_id() const { + return _account_id; + } + // position updates //////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// void copy_positions_from(const SecurityLimitNode& source){ _long_pos = source._long_pos; _short_pos = source._short_pos; @@ -60,23 +67,29 @@ public: Quantity long_pos, Quantity short_pos){ bts_assert(_account_id == account_id.value()); - uint32_t new_long = long_pos.value(), new_short = short_pos.value(); + uint32_t new_long = long_pos.value(), + new_short = short_pos.value(); // long if(new_long > _long_pos) - _product_node.add_position(api::Side::SIDE_BUY, new_long-_long_pos); + _product_node.add_position(api::Side::SIDE_BUY, + new_long-_long_pos); else if(new_long < _long_pos) - _product_node.remove_position(api::Side::SIDE_BUY, _long_pos-new_long); + _product_node.remove_position(api::Side::SIDE_BUY, + _long_pos-new_long); _long_pos = new_long; // short if(new_short > _short_pos) - _product_node.add_position(api::Side::SIDE_SELL, new_short-_short_pos); + _product_node.add_position(api::Side::SIDE_SELL, + new_short-_short_pos); else if(new_short < _short_pos) - _product_node.remove_position(api::Side::SIDE_SELL, _short_pos-new_short); + _product_node.remove_position(api::Side::SIDE_SELL, + _short_pos-new_short); _short_pos = new_short; } - // risk limit checks - //////////////////// - Limiter::LimiterQueryResult can_send_new_order(api::Side side, + // risk limit checks /////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////// + Limiter::LimiterQueryResult can_send_new_order( + api::Side side, Quantity quantity, bool enforce_clip = true) const{ Limiter::LimiterQueryResult result;result.result= Limiter::OK; @@ -90,8 +103,10 @@ public: result = _product_node.can_send_new_order(side, quantity); return result; } - Limiter::LimiterQueryResult can_update_order(api::Side side, Quantity from, Quantity to, - bool enforce_clip = true) const{ + Limiter::LimiterQueryResult can_update_order(api::Side side, + Quantity from, + Quantity to, + bool enforce_clip = true) const{ Limiter::LimiterQueryResult result;result.result=Limiter::OK; if (enforce_clip && to.value() > _clip_size){ result.result = Limiter::CLIP_SIZE_BREACHED; @@ -104,4 +119,4 @@ public: return result; } }; -}} +}} \ No newline at end of file