@@ -167,7 +167,7 @@ impl MatchingEngineState {
167167 pub async fn modify_order (
168168 & mut self ,
169169 order_id : OrderId ,
170- cancel_quantity : ModifyQuantity ,
170+ new_quantity : Amount ,
171171 ) -> Option < Transfer > {
172172 let key_book = self
173173 . orders
@@ -178,7 +178,7 @@ impl MatchingEngineState {
178178 OrderNature :: Bid => {
179179 let view = self . bid_level ( & key_book. price . to_bid ( ) ) . await ;
180180 let ( cancel_quantity, remove_order_id) =
181- view. modify_order_level ( order_id, cancel_quantity ) . await ?;
181+ view. modify_order_level ( order_id, new_quantity ) . await ?;
182182 if remove_order_id {
183183 self . remove_order_id ( ( key_book. account . owner , order_id) )
184184 . await ;
@@ -195,7 +195,7 @@ impl MatchingEngineState {
195195 OrderNature :: Ask => {
196196 let view = self . ask_level ( & key_book. price . to_ask ( ) ) . await ;
197197 let ( cancel_quantity, remove_order_id) =
198- view. modify_order_level ( order_id, cancel_quantity ) . await ?;
198+ view. modify_order_level ( order_id, new_quantity ) . await ?;
199199 if remove_order_id {
200200 self . remove_order_id ( ( key_book. account . owner , order_id) )
201201 . await ;
@@ -426,15 +426,6 @@ pub struct Transfer {
426426 pub token_idx : u32 ,
427427}
428428
429- /// An order can be cancelled which removes it totally or
430- /// modified which is a partial cancellation. The size of the
431- /// order can never increase.
432- #[ derive( Clone , Debug ) ]
433- pub enum ModifyQuantity {
434- All ,
435- Partial ( Amount ) ,
436- }
437-
438429impl LevelView {
439430 fn parameters ( & self ) -> Parameters {
440431 * self . context ( ) . extra ( )
@@ -609,24 +600,20 @@ impl LevelView {
609600 pub async fn modify_order_level (
610601 & mut self ,
611602 order_id : OrderId ,
612- reduce_quantity : ModifyQuantity ,
603+ new_quantity : Amount ,
613604 ) -> Option < ( Amount , bool ) > {
614605 let mut iter = self
615606 . queue
616607 . iter_mut ( )
617608 . await
618609 . expect ( "Failed to load iterator over level queue" ) ;
619610 let state_order = iter. find ( |order| order. order_id == order_id) ?;
620- let new_quantity = match reduce_quantity {
621- ModifyQuantity :: All => Amount :: ZERO ,
622- ModifyQuantity :: Partial ( reduce_quantity) => state_order
623- . quantity
624- . try_sub ( reduce_quantity)
625- . expect ( "Attempt to cancel a larger quantity than available" ) ,
626- } ;
627- let corr_reduce_quantity = state_order. quantity . try_sub ( new_quantity) . unwrap ( ) ;
611+ let cancel_quantity = state_order
612+ . quantity
613+ . try_sub ( new_quantity)
614+ . expect ( "Attempt to increase quantity" ) ;
628615 state_order. quantity = new_quantity;
629616 self . remove_zero_orders_from_level ( ) . await ;
630- Some ( ( corr_reduce_quantity , new_quantity == Amount :: ZERO ) )
617+ Some ( ( cancel_quantity , new_quantity == Amount :: ZERO ) )
631618 }
632619}
0 commit comments