Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Exchanges] handle MAX_FETCHED_OHLCV_COUNT #1398

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Trading/Exchange/kucoin/kucoin_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions Trading/Exchange/okx/okx_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -313,15 +313,15 @@ 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
return await script_keywords.get_amount_from_input_amount(
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,
Expand Down
Loading