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

get transferable api implemented #99

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
501 changes: 500 additions & 1 deletion .gitignore

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
===============================
Welcome to python-kucoin v2.1.1
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

Expand All @@ -21,7 +23,7 @@ Welcome to python-kucoin v2.1.1
:target: https://pypi.python.org/pypi/python-kucoin

This is an unofficial Python wrapper for the `Kucoin exchanges REST and Websocket API v2 <https://docs.kucoin.com/>`_.
I am in no way affiliated with Kucoin, use at your own risk.
I am in no way affiliated with `Kucoin <https://www.kucoin.com/ucenter/signup?rcode=E42cWB>`_, use at your own risk.


PyPi
Expand Down Expand Up @@ -158,6 +160,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
Expand All @@ -175,7 +180,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")
Expand Down
28 changes: 28 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
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
^^^^^^^^^^^^^^^^^^^^

**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
^^^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Contents
account
trading
market
sub_accounts
websockets
exceptions
changelog
Expand Down
2 changes: 1 addition & 1 deletion docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For previous v1 API install with
Register on Kucoin
-------------------

Firstly register an account with `Kucoin <https://www.kucoin.com/ucenter/signup?rcode=E42cWB>`_.
Firstly register an account with `Kucoin <https://www.kucoin.com/?rcode=E42cWB>`_.

To test on the Sandbox register with `Kucoin Sandbox <https://sandbox.kucoin.com/ucenter/signup?rcode=ewcefH>`_.

Expand Down
6 changes: 6 additions & 0 deletions docs/sub_accounts.rst
Original file line number Diff line number Diff line change
@@ -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:
8 changes: 6 additions & 2 deletions docs/websockets.rst
Original file line number Diff line number Diff line change
@@ -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:
-----
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion kucoin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

"""

__version__ = '2.1.1'
__version__ = '2.1.3'
82 changes: 72 additions & 10 deletions kucoin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -501,6 +502,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.upper(),
}
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

Expand Down Expand Up @@ -581,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

Expand All @@ -610,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
Expand Down Expand Up @@ -761,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')
Expand Down Expand Up @@ -796,10 +838,12 @@ def get_withdrawal_quotas(self, currency):
data = {
'currency': currency
}
if chain:
data['chain'] = chain

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
Expand All @@ -812,10 +856,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

Expand Down Expand Up @@ -845,6 +891,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)

Expand All @@ -871,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
Expand All @@ -891,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
Expand Down Expand Up @@ -918,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,
Expand All @@ -934,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:
Expand Down