2021-11-09 10:31:54 +00:00
|
|
|
"""Kucoin exchange subclass."""
|
2024-05-12 14:58:33 +00:00
|
|
|
|
2021-04-13 10:28:07 +00:00
|
|
|
import logging
|
|
|
|
from typing import Dict
|
|
|
|
|
2022-10-26 05:12:49 +00:00
|
|
|
from freqtrade.constants import BuySell
|
2021-04-13 10:28:07 +00:00
|
|
|
from freqtrade.exchange import Exchange
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class Kucoin(Exchange):
|
2021-11-09 10:31:54 +00:00
|
|
|
"""Kucoin exchange class.
|
|
|
|
|
|
|
|
Contains adjustments needed for Freqtrade to work with this exchange.
|
2021-04-13 10:28:07 +00:00
|
|
|
|
|
|
|
Please note that this exchange is not included in the list of exchanges
|
|
|
|
officially supported by the Freqtrade development team. So some features
|
|
|
|
may still not work as expected.
|
|
|
|
"""
|
|
|
|
|
|
|
|
_ft_has: Dict = {
|
2022-02-03 06:57:58 +00:00
|
|
|
"stoploss_on_exchange": True,
|
2023-09-28 17:33:59 +00:00
|
|
|
"stop_price_param": "stopPrice",
|
|
|
|
"stop_price_prop": "stopPrice",
|
2022-02-03 06:57:58 +00:00
|
|
|
"stoploss_order_types": {"limit": "limit", "market": "market"},
|
2021-04-13 10:28:07 +00:00
|
|
|
"l2_limit_range": [20, 100],
|
|
|
|
"l2_limit_range_required": False,
|
2024-05-12 14:58:33 +00:00
|
|
|
"order_time_in_force": ["GTC", "FOK", "IOC"],
|
2022-03-29 14:23:45 +00:00
|
|
|
"ohlcv_candle_limit": 1500,
|
2021-04-13 10:28:07 +00:00
|
|
|
}
|
2022-02-03 06:57:58 +00:00
|
|
|
|
2022-10-26 05:12:49 +00:00
|
|
|
def _get_stop_params(self, side: BuySell, ordertype: str, stop_price: float) -> Dict:
|
2022-02-03 06:57:58 +00:00
|
|
|
params = self._params.copy()
|
2024-05-12 14:58:33 +00:00
|
|
|
params.update({"stopPrice": stop_price, "stop": "loss"})
|
2022-02-03 06:57:58 +00:00
|
|
|
return params
|
2023-01-31 19:42:41 +00:00
|
|
|
|
|
|
|
def create_order(
|
2024-05-12 14:58:33 +00:00
|
|
|
self,
|
|
|
|
*,
|
|
|
|
pair: str,
|
|
|
|
ordertype: str,
|
|
|
|
side: BuySell,
|
|
|
|
amount: float,
|
|
|
|
rate: float,
|
|
|
|
leverage: float,
|
|
|
|
reduceOnly: bool = False,
|
|
|
|
time_in_force: str = "GTC",
|
|
|
|
) -> Dict:
|
2023-01-31 19:42:41 +00:00
|
|
|
res = super().create_order(
|
|
|
|
pair=pair,
|
|
|
|
ordertype=ordertype,
|
|
|
|
side=side,
|
|
|
|
amount=amount,
|
|
|
|
rate=rate,
|
|
|
|
leverage=leverage,
|
|
|
|
reduceOnly=reduceOnly,
|
|
|
|
time_in_force=time_in_force,
|
|
|
|
)
|
|
|
|
# Kucoin returns only the order-id.
|
|
|
|
# ccxt returns status = 'closed' at the moment - which is information ccxt invented.
|
|
|
|
# Since we rely on status heavily, we must set it to 'open' here.
|
|
|
|
# ref: https://github.com/ccxt/ccxt/pull/16674, (https://github.com/ccxt/ccxt/pull/16553)
|
2024-05-12 14:58:33 +00:00
|
|
|
if not self._config["dry_run"]:
|
|
|
|
res["type"] = ordertype
|
|
|
|
res["status"] = "open"
|
2023-01-31 19:42:41 +00:00
|
|
|
return res
|