From 129f0cc10ceffd78f17ecef6e692f34cba70a12c Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Sun, 8 Dec 2024 21:12:34 +0100 Subject: [PATCH] [Coinbase] explicitly use stop limit orders --- Trading/Exchange/coinbase/coinbase_exchange.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Trading/Exchange/coinbase/coinbase_exchange.py b/Trading/Exchange/coinbase/coinbase_exchange.py index 8f6d0e9bc..05477703b 100644 --- a/Trading/Exchange/coinbase/coinbase_exchange.py +++ b/Trading/Exchange/coinbase/coinbase_exchange.py @@ -286,13 +286,18 @@ async def get_order(self, exchange_order_id: str, symbol: str = None, **kwargs: # override for retrier return await super().get_order(exchange_order_id, symbol=symbol, **kwargs) - @_coinbase_retrier async def _create_market_stop_loss_order(self, symbol, quantity, price, side, current_price, params=None) -> dict: - params = params or {} # warning coinbase only supports stop limit orders, stop markets are not available + stop_price = price + price = float(decimal.Decimal(str(price)) * self.STOP_LIMIT_ORDER_INSTANT_FILL_PRICE_RATIO) + # use limit stop loss with a "normally instantly" filled price + return await self._create_limit_stop_loss_order(symbol, quantity, price, stop_price, side, params=params) + + @_coinbase_retrier + async def _create_limit_stop_loss_order(self, symbol, quantity, price, stop_price, side, params=None) -> dict: + params = params or {} if "stopLossPrice" not in params: - params["stopLossPrice"] = price # make ccxt understand that it's a stop loss - price = float(decimal.Decimal(str(price)) * self.STOP_LIMIT_ORDER_INSTANT_FILL_PRICE_RATIO) + params["stopLossPrice"] = stop_price # make ccxt understand that it's a stop loss order = self.connector.adapter.adapt_order( await self.connector.client.create_order( symbol, trading_enums.TradeOrderType.LIMIT.value, side, quantity, price, params=params