@@ -915,6 +915,59 @@ async def test_edit_order(self):
915
915
916
916
await self .stop (exchange_manager )
917
917
918
+ async def test_edit_order_by_replacing (self ):
919
+ # test with binance usdm as it supports edit order by replacing
920
+ _ , exchange_manager , trader_inst = await self .init_default (is_future = True )
921
+ portfolio_manager = exchange_manager .exchange_personal_data .portfolio_manager
922
+ currency , market = commons_symbols .parse_symbol (self .DEFAULT_SYMBOL ).base_and_quote ()
923
+ assert portfolio_manager .portfolio .portfolio [currency ].available == decimal .Decimal (10 )
924
+ assert portfolio_manager .portfolio .portfolio [market ].available == decimal .Decimal (1000 )
925
+
926
+ market_buy = BuyMarketOrder (trader_inst )
927
+ market_buy .update (order_type = TraderOrderType .BUY_MARKET ,
928
+ symbol = self .DEFAULT_SYMBOL ,
929
+ current_price = decimal .Decimal ("70" ),
930
+ quantity = decimal .Decimal ("10" ),
931
+ price = decimal .Decimal ("70" ))
932
+ with pytest .raises (OrderEditError ):
933
+ # market orders can't be edited
934
+ await trader_inst .edit_order (market_buy , edited_price = decimal .Decimal ("100" ))
935
+ assert market_buy .origin_quantity == decimal .Decimal ("10" )
936
+ assert market_buy .origin_price == decimal .Decimal ("70" )
937
+ assert market_buy .origin_stop_price == decimal .Decimal ("0" )
938
+ assert market_buy .created_last_price == decimal .Decimal ("70" )
939
+
940
+ limit_buy = BuyLimitOrder (trader_inst )
941
+ limit_buy .update (order_type = TraderOrderType .BUY_LIMIT ,
942
+ symbol = self .DEFAULT_SYMBOL ,
943
+ current_price = decimal .Decimal ("70" ),
944
+ quantity = decimal .Decimal ("10" ),
945
+ price = decimal .Decimal ("70" ))
946
+ assert portfolio_manager .portfolio .portfolio [currency ].available == decimal .Decimal (10 )
947
+ assert portfolio_manager .portfolio .portfolio [market ].available == decimal .Decimal (1000 )
948
+ exchange_manager .exchange_personal_data .portfolio_manager .portfolio .update_portfolio_available (
949
+ limit_buy , is_new_order = True
950
+ )
951
+ assert portfolio_manager .portfolio .portfolio [currency ].available == decimal .Decimal (10 )
952
+ assert portfolio_manager .portfolio .portfolio [market ].available == decimal .Decimal (300 )
953
+ await trader_inst .edit_order (
954
+ limit_buy ,
955
+ edited_quantity = decimal .Decimal ("4" ),
956
+ edited_price = decimal .Decimal ("42" ),
957
+ edited_stop_price = decimal .Decimal ("424" ),
958
+ edited_current_price = decimal .Decimal ("4242" ),
959
+ )
960
+ assert limit_buy .origin_quantity == decimal .Decimal ("4" )
961
+ assert limit_buy .origin_price == decimal .Decimal ("42" )
962
+ assert limit_buy .origin_stop_price == decimal .Decimal ("424" )
963
+ assert limit_buy .created_last_price == decimal .Decimal ("4242" )
964
+ # also updated portfolio
965
+ assert portfolio_manager .portfolio .portfolio [currency ].available == decimal .Decimal (10 )
966
+ assert portfolio_manager .portfolio .portfolio [market ].available == decimal .Decimal (832 )
967
+ limit_buy .clear ()
968
+
969
+ await self .stop (exchange_manager )
970
+
918
971
async def test_bundle_chained_order_with_uncreated_order (self ):
919
972
_ , exchange_manager , trader_inst = await self .init_default ()
920
973
0 commit comments