Skip to content

Commit

Permalink
[RestExchange] add option to edit_order_by_replacing
Browse files Browse the repository at this point in the history
tmp
tmp
  • Loading branch information
techfreaque committed Mar 18, 2023
1 parent 995390e commit 8e59be1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions octobot_trading/exchanges/types/rest_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,46 @@ async def _edit_order(self, order_id: str, order_type: enums.TraderOrderType, sy
quantity, price, stop_price, side,
current_price, params)

async def edit_order_by_replacing(
self,
order_id: str,
order_type: enums.TraderOrderType,
symbol: str,
quantity: decimal.Decimal,
price: decimal.Decimal,
stop_price: decimal.Decimal = None,
side: enums.TradeOrderSide = None,
):
# Can be used if api doesnt have an endpoint to edit orders
# see binance USD m as an example
order_to_cancle = (
self.exchange_manager.exchange_personal_data.orders_manager.get_order(
order_id
)
)
await self.cancel_order(order_id=order_id, symbol=symbol)
await order_to_cancel.state.wait_for_terminate(
constants.INDIVIDUAL_ORDER_SYNC_TIMEOUT
)
replaced_order = await self.create_order(
order_type,
symbol,
quantity,
price=stop_price or price,
stop_price=stop_price,
side=side,
current_price=order_to_cancle.created_last_price,
reduce_only=order_to_cancle.reduce_only,
)
if replaced_order:
return replaced_order
raise RuntimeError(
"Not able to edit a order by replacing. The new order was not created, "
f"while the original order got already cancelled. ({order_id} - "
f"{order_type} - {symbol} - quantity: {quantity} - "
f"price: {price} - {side})"
)

@contextlib.asynccontextmanager
async def _order_operation(self, order_type, symbol, quantity, price, stop_price):
try:
Expand Down

0 comments on commit 8e59be1

Please sign in to comment.