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
  • Loading branch information
techfreaque committed Mar 13, 2023
1 parent 7e704fe commit 109e215
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions octobot_trading/exchanges/types/rest_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,45 @@ 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
else:
raise RuntimeError(
"Not able to replace a order. The new order was not created "
f"({order_id} - {order_type} - {symbol} - quantity: {quantity} - price: {price} - {side})"
)

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

0 comments on commit 109e215

Please sign in to comment.