From d2d01852e86047e5af2419d544125cab678e3a60 Mon Sep 17 00:00:00 2001 From: Sam McHardy Date: Sat, 20 Jul 2019 20:59:14 +1000 Subject: [PATCH 01/12] Update to v2.1.2 --- README.rst | 9 ++++++--- docs/changelog.rst | 19 +++++++++++++++---- docs/overview.rst | 2 +- docs/websockets.rst | 8 ++++++-- kucoin/__init__.py | 2 +- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index f65a56f..00fa2cf 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ =============================== -Welcome to python-kucoin v2.1.1 +Welcome to python-kucoin v2.1.2 =============================== .. image:: https://img.shields.io/pypi/v/python-kucoin.svg @@ -53,7 +53,7 @@ TODO Quick Start ----------- -Register an account with `Kucoin `_. +Register an account with `Kucoin `_. To test on the Sandbox register with `Kucoin Sandbox `_. @@ -158,6 +158,9 @@ Note only for python3.5+ ksm = await KucoinSocketManager.create(loop, client, handle_evt) + # for private topics such as '/account/balance' pass private=True + ksm_private = await KucoinSocketManager.create(loop, client, handle_evt, private=True) + # Note: try these one at a time, if all are on you will see a lot of output # ETH-USDT Market Ticker @@ -175,7 +178,7 @@ Note only for python3.5+ # Level 3 market data await ksm.subscribe('/market/level3:BTC-USDT') # Account balance - must be authenticated - await ksm.subscribe('/account/balance') + await ksm_private.subscribe('/account/balance') while True: print("sleeping to keep loop open") diff --git a/docs/changelog.rst b/docs/changelog.rst index 5650875..906ed8d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,7 +1,18 @@ Changelog ========= -v2.1.1 - 2010-04-17 +v2.1.2 - 2019-04-17 +^^^^^^^^^^^^^^^^^^^^ + +**Added** + +- exception if using a private websocket topic but not connected with private + +**Removed** + +- removed py3.6 type annotations for py3.5 support + +v2.1.1 - 2019-04-17 ^^^^^^^^^^^^^^^^^^^^ **Added** @@ -15,7 +26,7 @@ v2.1.1 - 2010-04-17 - websocket reconnect ability -v2.1.0 - 2010-02-25 +v2.1.0 - 2019-02-25 ^^^^^^^^^^^^^^^^^^^^ **Added** @@ -38,7 +49,7 @@ v2.1.0 - 2010-02-25 - LimitOrderException message -v2.0.2 - 2010-02-23 +v2.0.2 - 2019-02-23 ^^^^^^^^^^^^^^^^^^^^ **Fixed** @@ -46,7 +57,7 @@ v2.0.2 - 2010-02-23 - signature generation for get requests -v2.0.1 - 2010-01-23 +v2.0.1 - 2019-01-23 ^^^^^^^^^^^^^^^^^^^^ **Fixed** diff --git a/docs/overview.rst b/docs/overview.rst index dac280c..ceeb1d4 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -22,7 +22,7 @@ For previous v1 API install with Register on Kucoin ------------------- -Firstly register an account with `Kucoin `_. +Firstly register an account with `Kucoin `_. To test on the Sandbox register with `Kucoin Sandbox `_. diff --git a/docs/websockets.rst b/docs/websockets.rst index 619a31b..6c3d394 100644 --- a/docs/websockets.rst +++ b/docs/websockets.rst @@ -1,11 +1,12 @@ Websockets ========== -Note: The websocket client is only available for python3.6+ +Note: The websocket client is only available for python3.5+ This feature is still in development so check the documentation around message topics here https://docs.kucoin.com/#websocket-feed +For private topics such as '/account/balance' pass private=True to the KucoinSocketManager, see example below TODO: ----- @@ -76,6 +77,9 @@ Sample Code ksm = await KucoinSocketManager.create(loop, client, handle_evt) + # for private topics such as '/account/balance' pass private=True + ksm_private = await KucoinSocketManager.create(loop, client, handle_evt, private=True) + # Note: try these one at a time, if all are on you will see a lot of output # ETH-USDT Market Ticker @@ -93,7 +97,7 @@ Sample Code # Level 3 market data await ksm.subscribe('/market/level3:BTC-USDT') # Account balance - must be authenticated - await ksm.subscribe('/account/balance') + await ksm_private.subscribe('/account/balance') while True: print("sleeping to keep loop open") diff --git a/kucoin/__init__.py b/kucoin/__init__.py index 65aa491..85c2e14 100644 --- a/kucoin/__init__.py +++ b/kucoin/__init__.py @@ -4,4 +4,4 @@ """ -__version__ = '2.1.1' +__version__ = '2.1.2' From 574714a8fc1a960225bd8d947b4a1651643058d6 Mon Sep 17 00:00:00 2001 From: Sam McHardy Date: Sun, 2 May 2021 07:34:14 +1000 Subject: [PATCH 02/12] Update docs --- README.rst | 4 ++-- docs/index.rst | 1 + docs/sub_accounts.rst | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 docs/sub_accounts.rst diff --git a/README.rst b/README.rst index 00fa2cf..ef066c4 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ Welcome to python-kucoin v2.1.2 :target: https://pypi.python.org/pypi/python-kucoin This is an unofficial Python wrapper for the `Kucoin exchanges REST and Websocket API v2 `_. -I am in no way affiliated with Kucoin, use at your own risk. +I am in no way affiliated with `Kucoin `_, use at your own risk. PyPi @@ -53,7 +53,7 @@ TODO Quick Start ----------- -Register an account with `Kucoin `_. +Register an account with `Kucoin `_. To test on the Sandbox register with `Kucoin Sandbox `_. diff --git a/docs/index.rst b/docs/index.rst index a244709..0d80449 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -15,6 +15,7 @@ Contents account trading market + sub_accounts websockets exceptions changelog diff --git a/docs/sub_accounts.rst b/docs/sub_accounts.rst new file mode 100644 index 0000000..4adf759 --- /dev/null +++ b/docs/sub_accounts.rst @@ -0,0 +1,6 @@ +Sub Account Endpoints +===================== + +.. autoclass:: kucoin.client.Client + :members: get_symbols, get_ticker, get_24hr_stats, get_markets, get_order_book, get_full_order_book, get_full_order_book_level3, get_trade_histories, get_kline_data, get_historical_orders + :noindex: From dfdfa1715b70341f43a4cea0427b85f470bbd001 Mon Sep 17 00:00:00 2001 From: Sam McHardy Date: Mon, 4 Oct 2021 09:59:18 +0700 Subject: [PATCH 03/12] Update to v2.1.3 --- README.rst | 4 +++- docs/changelog.rst | 17 +++++++++++++++++ kucoin/__init__.py | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index ef066c4..87b93f4 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,9 @@ =============================== -Welcome to python-kucoin v2.1.2 +Welcome to python-kucoin v2.1.3 =============================== +Last Updated 4th Oct 2021 + .. image:: https://img.shields.io/pypi/v/python-kucoin.svg :target: https://pypi.python.org/pypi/python-kucoin diff --git a/docs/changelog.rst b/docs/changelog.rst index 906ed8d..fd13861 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,23 @@ Changelog ========= +v2.1.3 - 2021-10-04 +^^^^^^^^^^^^^^^^^^^^ + +**Added** + +- chain to get_deposit_address +- get_accounts to include currency and account_type params +- get_account_activity to use new params +- get_status to retrieve service status +- get and cancel order by orderOid +- trade_type to market and limit orders +- v2 and v3 API version options + +**Deprecated** + +- get_account_holds + v2.1.2 - 2019-04-17 ^^^^^^^^^^^^^^^^^^^^ diff --git a/kucoin/__init__.py b/kucoin/__init__.py index 85c2e14..7467b1a 100644 --- a/kucoin/__init__.py +++ b/kucoin/__init__.py @@ -4,4 +4,4 @@ """ -__version__ = '2.1.2' +__version__ = '2.1.3' From 29b640940a8792863d191db068ce416cb3c400d7 Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Thu, 7 Oct 2021 01:25:43 +0330 Subject: [PATCH 04/12] Deprecate '/api/v1/accounts/inner-transfer' endpoint for Inner Transfer. migrate to v2 api --- kucoin/client.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/kucoin/client.py b/kucoin/client.py index 028c8b0..15a7f7d 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -119,8 +119,8 @@ def _generate_signature(self, nonce, method, path, data): m = hmac.new(self.API_SECRET.encode('utf-8'), sig_str, hashlib.sha256) return base64.b64encode(m.digest()) - def _create_path(self, path): - return '/api/{}/{}'.format(self.API_VERSION, path) + def _create_path(self, path, api_version): + return '/api/{}/{}'.format(api_version, path) def _create_uri(self, path): return '{}{}'.format(self.API_URL, path) @@ -136,8 +136,8 @@ def _request(self, method, path, signed, **kwargs): kwargs['data'] = kwargs.get('data', {}) kwargs['headers'] = kwargs.get('headers', {}) - - full_path = self._create_path(path) + api_version = kwargs.get('api_version', 'v1') + full_path = self._create_path(path, api_version) uri = self._create_uri(full_path) if signed: @@ -512,23 +512,25 @@ def get_account_holds(self, account_id, page=None, page_size=None): return self._get('accounts/{}/holds'.format(account_id), True, data=data) - def create_inner_transfer(self, from_account_id, to_account_id, amount, order_id=None): + def create_inner_transfer(self, currency, from_account_type, to_account_type, amount, order_id=None): """Get account holds placed for any active orders or pending withdraw requests https://docs.kucoin.com/#get-holds - :param from_account_id: ID of account to transfer funds from - from list_accounts() - :type from_account_id: str - :param to_account_id: ID of account to transfer funds to - from list_accounts() - :type to_account_id: str + :param currency: currency + :type currency: str + :param from_account_type: Account type of payer: main, trade, margin or pool + :type from_account_type: str + :param to_account_type: Account type of payee: main, trade, margin , contract or pool + :type to_account_type: str :param amount: Amount to transfer - :type amount: int + :type amount: number :param order_id: (optional) Request ID (default flat_uuid()) :type order_id: string .. code:: python - transfer = client.create_inner_transfer('5bd6e9216d99522a52e458d6', 5bc7f080b39c5c03286eef8e', 20) + transfer = client.create_inner_transfer('BTC', 'main','trade', 0.8) :returns: API Response @@ -543,8 +545,9 @@ def create_inner_transfer(self, from_account_id, to_account_id, amount, order_id """ data = { - 'payAccountId': from_account_id, - 'recAccountId': to_account_id, + 'currency': currency, + 'from': from_account_type, + 'to': to_account_type, 'amount': amount } @@ -553,7 +556,7 @@ def create_inner_transfer(self, from_account_id, to_account_id, amount, order_id else: data['clientOid'] = flat_uuid() - return self._post('accounts/inner-transfer', True, data=data) + return self._post('accounts/inner-transfer', True, data=data, api_version="v2") # Deposit Endpoints @@ -1351,8 +1354,8 @@ def get_fills(self, order_id=None, symbol=None, side=None, order_type=None, :type start: string :param end: End time as unix timestamp (optional) :type end: string - :param tradeType: The type of trading : TRADE(Spot Trading), MARGIN_TRADE (Margin Trading). - :type tradeType: string + :param trade_type: The type of trading : TRADE(Spot Trading), MARGIN_TRADE (Margin Trading). + :type trade_type: string :param page: optional - Page to fetch :type page: int :param limit: optional - Number of orders From 0dff0647e28a9792e0f469adfe546db54a0d6fd5 Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Thu, 7 Oct 2021 01:53:38 +0330 Subject: [PATCH 05/12] get transferable api added --- kucoin/client.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/kucoin/client.py b/kucoin/client.py index b597a76..48091c0 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -501,6 +501,42 @@ def get_account_activity(self, currency=None, direction=None, biz_type=None, sta return self._get('accounts/ledgers', True, data=data) + def get_transferable(self, currency, account_type): + """Get the transferable balance of a specified account + + https://docs.kucoin.com/#get-the-transferable + + :param currency: Currency code + :type currency: string + :param account_type: Account type - main, trade, margin or pool + :type account_type: string + + .. code:: python + + accounts = client.get_transferable('BTC', 'trade') + + :returns: API Response + + .. code-block:: python + + { + "currency": "BTC", + "balance": "0", + "available": "0", + "holds": "0", + "transferable": "0" + } + + :raises: KucoinResponseException, KucoinAPIException + + """ + + data = { + 'currency': currency, + 'type': account_type, + } + return self._get('transferable', True, data=data) + def create_inner_transfer(self, currency, from_type, to_type, amount, order_id=None): """Transfer fund among accounts on the platform @@ -871,7 +907,7 @@ def cancel_withdrawal(self, withdrawal_id): # Order Endpoints def create_market_order( - self, symbol, side, size=None, funds=None, client_oid=None, remark=None, stp=None, trade_type=None + self, symbol, side, size=None, funds=None, client_oid=None, remark=None, stp=None, trade_type=None ): """Create a market order From 3d9f0c4b1789a93741b62a16470f82473fced26e Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Thu, 7 Oct 2021 10:52:16 +0330 Subject: [PATCH 06/12] hotfix on transferable path --- kucoin/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kucoin/client.py b/kucoin/client.py index 48091c0..118339e 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -535,7 +535,7 @@ def get_transferable(self, currency, account_type): 'currency': currency, 'type': account_type, } - return self._get('transferable', True, data=data) + return self._get('accounts/transferable', True, data=data) def create_inner_transfer(self, currency, from_type, to_type, amount, order_id=None): """Transfer fund among accounts on the platform From 5680f14745c5784b8545406ccca2b0ee838d8803 Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Thu, 7 Oct 2021 11:02:25 +0330 Subject: [PATCH 07/12] account type in transferable api must be upper case --- kucoin/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kucoin/client.py b/kucoin/client.py index 118339e..43e884c 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -533,7 +533,7 @@ def get_transferable(self, currency, account_type): data = { 'currency': currency, - 'type': account_type, + 'type': account_type.upper(), } return self._get('accounts/transferable', True, data=data) From 30c9f49b5973f1b79863e8891595a13899566369 Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Sun, 10 Oct 2021 11:13:21 +0330 Subject: [PATCH 08/12] fix get-deposit-address --- kucoin/client.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kucoin/client.py b/kucoin/client.py index 43e884c..4c6c5b5 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -409,7 +409,8 @@ def create_account(self, account_type, currency): return self._post('accounts', True, data=data) - def get_account_activity(self, currency=None, direction=None, biz_type=None, start=None, end=None, page=None, limit=None): + def get_account_activity(self, currency=None, direction=None, biz_type=None, start=None, end=None, page=None, + limit=None): """Get list of account activity https://docs.kucoin.com/#get-account-history @@ -617,17 +618,19 @@ def create_deposit_address(self, currency, chain=None): return self._post('deposit-addresses', True, data=data) - def get_deposit_address(self, currency): + def get_deposit_address(self, currency, chain=None): """Get deposit address for a currency https://docs.kucoin.com/#get-deposit-address :param currency: Name of currency + :param chain: chain name of currency :type currency: string + :type chain: string .. code:: python - address = client.get_deposit_address('USDT') + address = client.get_deposit_address('USDT','TRC20') :returns: ApiResponse @@ -646,8 +649,10 @@ def get_deposit_address(self, currency): data = { 'currency': currency } + if chain is not None: + data['chain'] = chain - return self._get('deposit-addresses', True, api_version=self.API_VERSION2, data=data) + return self._get('deposit-addresses', True, data=data) def get_deposits(self, currency=None, status=None, start=None, end=None, page=None, limit=None): """Get deposit records for a currency From 12fce12166e033f7f74e5726dd7c166814c6c0e9 Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Wed, 17 Nov 2021 04:34:20 +0330 Subject: [PATCH 09/12] add chain to create_withdrawal --- kucoin/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kucoin/client.py b/kucoin/client.py index 4c6c5b5..7527f2b 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -840,7 +840,7 @@ def get_withdrawal_quotas(self, currency): return self._get('withdrawals/quotas', True, data=data) - def create_withdrawal(self, currency, amount, address, memo=None, is_inner=False, remark=None): + def create_withdrawal(self, currency, amount, address, memo=None, is_inner=False, remark=None, chain=None): """Process a withdrawal https://docs.kucoin.com/#apply-withdraw @@ -853,10 +853,12 @@ def create_withdrawal(self, currency, amount, address, memo=None, is_inner=False :type address: string :param memo: (optional) Remark to the withdrawal address :type memo: string - :param is_inner: (optional) Remark to the withdrawal address + :param is_inner: (optional) Internal withdrawal or not :type is_inner: bool :param remark: (optional) Remark :type remark: string + :param chain: (optional) The chain name of currency, e.g. The available value for USDT are OMNI, ERC20, TRC20, default is ERC20. This only apply for multi-chain currency, and there is no need for single chain currency. + :type chain: string .. code:: python @@ -886,6 +888,8 @@ def create_withdrawal(self, currency, amount, address, memo=None, is_inner=False data['isInner'] = is_inner if remark: data['remark'] = remark + if chain: + data['chain'] = chain return self._post('withdrawals', True, data=data) From 8b3a8d055d97b4eeee047fc2184bfe7d0a9760e8 Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Wed, 17 Nov 2021 04:41:40 +0330 Subject: [PATCH 10/12] add chain parameter to get_withdrawal_quotas --- kucoin/client.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kucoin/client.py b/kucoin/client.py index 7527f2b..4388d00 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -802,14 +802,15 @@ def get_withdrawals(self, currency=None, status=None, start=None, end=None, page return self._get('withdrawals', True, data=data) - def get_withdrawal_quotas(self, currency): + def get_withdrawal_quotas(self, currency, chain=None): """Get withdrawal quotas for a currency https://docs.kucoin.com/#get-withdrawal-quotas :param currency: Name of currency :type currency: string - + :param chain: The chain name of currency, e.g. The available value for USDT are OMNI, ERC20, TRC20, default is ERC20. This only apply for multi-chain currency, and there is no need for single chain currency. + :type chain: string .. code:: python quotas = client.get_withdrawal_quotas('ETH') @@ -837,6 +838,8 @@ def get_withdrawal_quotas(self, currency): data = { 'currency': currency } + if chain: + data['chain'] = chain return self._get('withdrawals/quotas', True, data=data) From 9624eea19b20e7980b6b264cecc7181aad771bfb Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Wed, 26 Jan 2022 03:57:00 +0330 Subject: [PATCH 11/12] fix git ignore --- .gitignore | 501 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 500 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index accb26a..f578a40 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,500 @@ -docs/_build + +# Created by https://www.toptal.com/developers/gitignore/api/linux,jetbrains+all,pycharm+all,pycharm+iml,pycharm,django,python +# Edit at https://www.toptal.com/developers/gitignore?templates=linux,jetbrains+all,pycharm+all,pycharm+iml,pycharm,django,python +*.pyc +db.sqlite3 +venv/ +pyvenv/ +.vscode/ +.env +.idea +static/ +dump.sql + +### Django ### +*.log +*.pot +*.pyc +__pycache__/ +local_settings.py +*.sqlite +db.sqlite3-journal +media + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo + +# Django stuff: + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### PyCharm ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### PyCharm Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +### PyCharm+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### PyCharm+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + + +# Sonarlint plugin + +### PyCharm+iml ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### PyCharm+iml Patch ### +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + + +### Python ### +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow + +# Celery stuff + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# pytype static type analyzer + +# End of https://www.toptal.com/developers/gitignore/api/linux,jetbrains+all,pycharm+all,pycharm+iml,pycharm,django,python From 6db82cf792040ae67b8a8cd9a762be495da2970a Mon Sep 17 00:00:00 2001 From: amirmehdi Date: Wed, 26 Jan 2022 04:09:13 +0330 Subject: [PATCH 12/12] add stop market order --- kucoin/client.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/kucoin/client.py b/kucoin/client.py index 4388d00..bd4d96a 100644 --- a/kucoin/client.py +++ b/kucoin/client.py @@ -919,8 +919,9 @@ def cancel_withdrawal(self, withdrawal_id): # Order Endpoints def create_market_order( - self, symbol, side, size=None, funds=None, client_oid=None, remark=None, stp=None, trade_type=None - ): + self, symbol, side, size=None, funds=None, + client_oid=None, remark=None, stop=None, stop_price=None, + stp=None, trade_type=None): """Create a market order One of size or funds must be set @@ -939,6 +940,10 @@ def create_market_order( :type client_oid: string :param remark: (optional) remark for the order, max 100 utf8 characters :type remark: string + :param stop: (optional) stop type loss or entry - requires stop_price + :type stop: string + :param stop_price: (optional) trigger price for stop order + :type stop_price: string :param stp: (optional) self trade protection CN, CO, CB or DC (default is None) :type stp: string :param trade_type: (optional) The type of trading : TRADE(Spot Trade), MARGIN_TRADE (Margin Trade). Default is TRADE @@ -966,6 +971,12 @@ def create_market_order( if size and funds: raise MarketOrderException('Need size or fund parameter not both') + if stop and not stop_price: + raise LimitOrderException('Stop order needs stop_price') + + if stop_price and not stop: + raise LimitOrderException('Stop order type required with stop_price') + data = { 'side': side, 'symbol': symbol, @@ -982,6 +993,9 @@ def create_market_order( data['clientOid'] = flat_uuid() if remark: data['remark'] = remark + if stop: + data['stop'] = stop + data['stopPrice'] = stop_price if stp: data['stp'] = stp if trade_type: