From b53329f2d05b5814e0a14a057d90ddcfc9ae2f93 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Wed, 18 Dec 2024 10:08:34 +0100 Subject: [PATCH 1/3] [Exchanges] handle MAX_FETCHED_OHLCV_COUNT --- Trading/Exchange/okx/okx_exchange.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Trading/Exchange/okx/okx_exchange.py b/Trading/Exchange/okx/okx_exchange.py index 53c720b27..82da6011a 100644 --- a/Trading/Exchange/okx/okx_exchange.py +++ b/Trading/Exchange/okx/okx_exchange.py @@ -112,6 +112,10 @@ class Okx(exchanges.RestExchange): DEFAULT_CONNECTOR_CLASS = OkxConnector MAX_PAGINATION_LIMIT: int = 100 # value from https://www.okex.com/docs/en/#spot-orders_pending + # set when the exchange returns nothing when fetching historical candles with a too early start time + # (will iterate historical OHLCV requests over this window) + MAX_FETCHED_OHLCV_COUNT = 100 + # Okx default take profits are market orders # note: use BUY_MARKET and SELL_MARKET since in reality those are conditional market orders, which behave the same # way as limit order but with higher fees From ede03acc3f393dc2419d407a21088fe0aa2c817c Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Thu, 26 Dec 2024 14:36:39 +0100 Subject: [PATCH 2/3] [Kucoin] fix parsing --- Trading/Exchange/kucoin/kucoin_exchange.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Trading/Exchange/kucoin/kucoin_exchange.py b/Trading/Exchange/kucoin/kucoin_exchange.py index 3d2c828af..1be3fc1e9 100644 --- a/Trading/Exchange/kucoin/kucoin_exchange.py +++ b/Trading/Exchange/kucoin/kucoin_exchange.py @@ -483,7 +483,7 @@ def fix_order(self, raw, symbol=None, **kwargs): fixed = super().fix_order(raw, symbol=symbol, **kwargs) self._ensure_fees(fixed) if self.connector.exchange_manager.is_future and \ - fixed[trading_enums.ExchangeConstantsOrderColumns.COST.value] is not None: + fixed.get(trading_enums.ExchangeConstantsOrderColumns.COST.value) is not None: fixed[trading_enums.ExchangeConstantsOrderColumns.COST.value] = \ fixed[trading_enums.ExchangeConstantsOrderColumns.COST.value] * \ float(raw_order_info.get(self.KUCOIN_LEVERAGE, 1)) From 79892f5f84131b4805a9f09c3d6de7401922f6b7 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Thu, 26 Dec 2024 14:37:01 +0100 Subject: [PATCH 3/3] [TV] handle reduce_only quantity --- .../trading_view_signals_trading.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py b/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py index 372c914e0..f8a35ec6a 100644 --- a/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py +++ b/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py @@ -278,18 +278,18 @@ async def _parse_order_details(self, ctx, parsed_data): ctx, parsed_data, f"{TradingViewSignalsTradingMode.TAKE_PROFIT_PRICE_KEY}_", math.nan ) allow_holdings_adaptation = parsed_data.get(TradingViewSignalsTradingMode.ALLOW_HOLDINGS_ADAPTATION_KEY, False) - + reduce_only = parsed_data.get(TradingViewSignalsTradingMode.REDUCE_ONLY_KEY, False) + amount = await self._parse_volume( + ctx, parsed_data, parsed_side, target_price, allow_holdings_adaptation, reduce_only + ) order_data = { TradingViewSignalsModeConsumer.PRICE_KEY: target_price, - TradingViewSignalsModeConsumer.VOLUME_KEY: await self._parse_volume( - ctx, parsed_data, parsed_side, target_price, allow_holdings_adaptation - ), + TradingViewSignalsModeConsumer.VOLUME_KEY: amount, TradingViewSignalsModeConsumer.STOP_PRICE_KEY: stop_price, TradingViewSignalsModeConsumer.STOP_ONLY: order_type == TradingViewSignalsTradingMode.STOP_SIGNAL, TradingViewSignalsModeConsumer.TAKE_PROFIT_PRICE_KEY: tp_price, TradingViewSignalsModeConsumer.ADDITIONAL_TAKE_PROFIT_PRICES_KEY: additional_tp_prices, - TradingViewSignalsModeConsumer.REDUCE_ONLY_KEY: - parsed_data.get(TradingViewSignalsTradingMode.REDUCE_ONLY_KEY, False), + TradingViewSignalsModeConsumer.REDUCE_ONLY_KEY: reduce_only, TradingViewSignalsModeConsumer.TAG_KEY: parsed_data.get(TradingViewSignalsTradingMode.TAG_KEY, None), TradingViewSignalsModeConsumer.EXCHANGE_ORDER_IDS: @@ -313,7 +313,7 @@ async def _parse_price(self, ctx, parsed_data, key, default): ) return target_price - async def _parse_volume(self, ctx, parsed_data, side, target_price, allow_holdings_adaptation): + async def _parse_volume(self, ctx, parsed_data, side, target_price, allow_holdings_adaptation, reduce_only): user_volume = str(parsed_data.get(TradingViewSignalsTradingMode.VOLUME_KEY, 0)) if user_volume == "0": return trading_constants.ZERO @@ -321,7 +321,7 @@ async def _parse_volume(self, ctx, parsed_data, side, target_price, allow_holdin context=ctx, input_amount=user_volume, side=side, - reduce_only=False, + reduce_only=reduce_only, is_stop_order=False, use_total_holding=False, target_price=target_price,