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

Kucoin fix #1070

Merged
merged 2 commits into from
Oct 3, 2023
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
19 changes: 19 additions & 0 deletions Trading/Exchange/kucoin/kucoin_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import octobot_trading.errors
import octobot_trading.exchanges as exchanges
import octobot_trading.exchanges.connectors.ccxt.enums as ccxt_enums
import octobot_trading.exchanges.connectors.ccxt.constants as ccxt_constants
import octobot_commons.constants as commons_constants
import octobot_trading.constants as constants
import octobot_trading.enums as trading_enums
Expand Down Expand Up @@ -165,6 +166,24 @@ async def get_account_id(self, **kwargs: dict) -> str:
# raised when calling this endpoint with a subaccount
return constants.DEFAULT_SUBACCOUNT_ID

def get_market_status(self, symbol, price_example=None, with_fixer=True):
"""
local override to take "minFunds" into account
"minFunds the minimum spot and margin trading amounts" https://docs.kucoin.com/#get-symbols-list
"""
market_status = super().get_market_status(symbol, price_example=price_example, with_fixer=with_fixer)
min_funds = market_status.get(ccxt_constants.CCXT_INFO, {}).get("minFunds")
if min_funds is not None:
# should only be for spot and margin, use it if available anyway
limit_costs = market_status[trading_enums.ExchangeConstantsMarketStatusColumns.LIMITS.value][
trading_enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST.value
]
# use max (most restrictive) value
limit_costs[trading_enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST_MIN.value] = min(
limit_costs[trading_enums.ExchangeConstantsMarketStatusColumns.LIMITS_COST_MIN.value],
float(min_funds)
)
return market_status

@_kucoin_retrier
async def get_symbol_prices(self, symbol, time_frame, limit: int = 200, **kwargs: dict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,20 @@ async def _bundle_order(self, order_description, to_create_orders, ignored_order

async def _chain_order(self, order_description, created_orders, ignored_orders, chained_to, fees_currency_side,
created_groups, symbol, order_description_by_id):
failed_order_creation = False
try:
base_order = created_orders[chained_to]
if base_order is None:
# when an error occurred when creating the initial order
failed_order_creation = True
raise KeyError
except KeyError as e:
if chained_to in ignored_orders:
self.logger.error(f"Ignored order chained to id {chained_to}: "
f"associated master order has not been created")
if chained_to in ignored_orders or failed_order_creation:
message = f"Ignored order chained to id {chained_to}: associated master order has not been created"
if failed_order_creation:
self.logger.info(message)
else:
self.logger.error(message)
else:
self.logger.error(
f"Ignored chained order from {order_description}. Chained orders have to be sent in the same "
Expand Down