Skip to content

Commit

Permalink
[Exchanges] add closed position & instant trigger error
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Jan 3, 2025
1 parent 42b69e5 commit 2caa80a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Trading/Exchange/binance/binance_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class Binance(exchanges.RestExchange):
# Binance ex: InvalidOrder binance {"code":-2010,"msg":"This symbol is not permitted for this account."}
("symbol", "not permitted", "for this account"),
]
# text content of errors due to a closed position on the exchange. Relevant for reduce-only orders
EXCHANGE_CLOSED_POSITION_ERRORS: typing.List[typing.Iterable[str]] = [
# doesn't seem to happen on binance
]
# text content of errors due to an order that would immediately trigger if created. Relevant for stop losses
EXCHANGE_ORDER_IMMEDIATELY_TRIGGER_ERRORS: typing.List[typing.Iterable[str]] = [
# binance {"code":-2021,"msg":"Order would immediately trigger."}
("order would immediately trigger", )
]

BUY_STR = "BUY"
SELL_STR = "SELL"
Expand Down
9 changes: 9 additions & 0 deletions Trading/Exchange/kucoin/kucoin_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,15 @@ class Kucoin(exchanges.RestExchange):
# 'kucoin The order does not exist.'
("order does not exist",),
]
# text content of errors due to a closed position on the exchange. Relevant for reduce-only orders
EXCHANGE_CLOSED_POSITION_ERRORS: typing.List[typing.Iterable[str]] = [
# 'kucoinfutures No open positions to close.'
("No open positions to close", )
]
# text content of errors due to an order that would immediately trigger if created. Relevant for stop losses
EXCHANGE_ORDER_IMMEDIATELY_TRIGGER_ERRORS: typing.List[typing.Iterable[str]] = [
# doesn't seem to happen on kucoin
]

DEFAULT_BALANCE_CURRENCIES_TO_FETCH = ["USDT"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ async def _chain_order(self, order_description, created_orders, ignored_orders,
base_order, chained_order, chained_order.update_with_triggering_order_fees, False
)
if base_order.state is not None and base_order.is_filled() and chained_order.should_be_created():
await personal_data.create_as_chained_order(chained_order)
try:
await personal_data.create_as_chained_order(chained_order)
except errors.OctoBotExchangeError as err:
# todo later on: handle locale error if necessary
self.logger.error(f"Failed to create chained order: {chained_order}: {err}")
return 1
return 0

Expand Down

0 comments on commit 2caa80a

Please sign in to comment.