Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam McHardy committed Aug 12, 2019
2 parents 05da864 + 98d2975 commit 01939fa
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 32 deletions.
294 changes: 269 additions & 25 deletions binance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _request(self, method, uri, signed, force_params=False, **kwargs):

# if get request assign data array to params value for requests lib
if data and (method == 'get' or force_params):
kwargs['params'] = kwargs['data']
kwargs['params'] = '&'.join('%s=%s' % (data[0], data[1]) for data in kwargs['data'])
del(kwargs['data'])

response = getattr(self.session, method)(uri, **kwargs)
Expand Down Expand Up @@ -1768,6 +1768,91 @@ def get_dust_log(self, **params):
raise BinanceWithdrawException(res['msg'])
return res

def transfer_dust(self, **params):
"""Convert dust assets to BNB.
https://github.com/binance-exchange/binance-official-api-docs/blob/9dbe0e961b80557bb19708a707c7fad08842b28e/wapi-api.md#dust-transfer-user_data
:param asset: The asset being converted. e.g: 'ONE'
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code:: python
result = client.transfer_dust(asset='ONE')
:returns: API response
.. code-block:: python
{
"totalServiceCharge":"0.02102542",
"totalTransfered":"1.05127099",
"transferResult":[
{
"amount":"0.03000000",
"fromAsset":"ETH",
"operateTime":1563368549307,
"serviceChargeAmount":"0.00500000",
"tranId":2970932918,
"transferedAmount":"0.25000000"
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api('post', 'asset/dust', True, data=params)

def get_asset_dividend_history(self, **params):
"""Query asset dividend record.
https://github.com/binance-exchange/binance-official-api-docs/blob/9dbe0e961b80557bb19708a707c7fad08842b28e/wapi-api.md#asset-dividend-record-user_data
:param asset: optional
:type asset: str
:param startTime: optional
:type startTime: long
:param endTime: optional
:type endTime: long
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
.. code:: python
result = client.get_asset_dividend_history()
:returns: API response
.. code-block:: python
{
"rows":[
{
"amount":"10.00000000",
"asset":"BHFT",
"divTime":1563189166000,
"enInfo":"BHFT distribution",
"tranId":2968885920
},
{
"amount":"10.00000000",
"asset":"BHFT",
"divTime":1563189165000,
"enInfo":"BHFT distribution",
"tranId":2968885920
}
],
"total":2
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api('post', 'asset/assetDividend', True, data=params)

def get_trade_fee(self, **params):
"""Get trade fee.
Expand Down Expand Up @@ -1999,28 +2084,6 @@ def get_deposit_address(self, **params):
"""
return self._request_withdraw_api('get', 'depositAddress.html', True, data=params)

def get_withdraw_fee(self, **params):
"""Fetch the withdrawal fee for an asset
:param asset: required
:type asset: str
:param recvWindow: the number of milliseconds the request is valid for
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"withdrawFee": "0.0005",
"success": true
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_withdraw_api('get', 'withdrawFee.html', True, data=params)

# User Stream Endpoints

def stream_get_listen_key(self):
Expand Down Expand Up @@ -2092,7 +2155,7 @@ def stream_close(self, listenKey):

# Margin Trading Endpoints

def get_margin_account(self):
def get_margin_account(self, **params):
"""Query margin account details
https://github.com/binance-exchange/binance-official-api-docs/blob/master/margin-api.md#query-margin-account-details-user_data
Expand Down Expand Up @@ -2148,7 +2211,7 @@ def get_margin_account(self):
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_margin_api('get', 'margin/account', True)
return self._request_margin_api('get', 'margin/account', True, data=params)

def get_margin_asset(self, **params):
"""Query margin asset
Expand Down Expand Up @@ -2915,3 +2978,184 @@ def margin_stream_close(self, listenKey):
'listenKey': listenKey
}
return self._request_margin_api('delete', 'userDataStream', signed=True, data=params)

# Sub Accounts

def get_sub_account_list(self, **params):
"""Query Sub-account List.
https://github.com/binance-exchange/binance-official-api-docs/blob/master/wapi-api.md#query-sub-account-listfor-master-account
:param email: optional
:type email: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional
:type page: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"success":true,
"subAccounts":[
{
"email":"[email protected]",
"status":"enabled",
"activated":true,
"mobile":"91605290",
"gAuth":true,
"createTime":1544433328000
},
{
"email":"[email protected]",
"status":"disabled",
"activated":true,
"mobile":"22501238",
"gAuth":true,
"createTime":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_withdraw_api('get', 'sub-account/list.html', True, data=params)

def get_sub_account_transfer_history(self, **params):
"""Query Sub-account Transfer History.
https://github.com/binance-exchange/binance-official-api-docs/blob/master/wapi-api.md#query-sub-account-transfer-historyfor-master-account
:param email: required
:type email: str
:param startTime: optional
:type startTime: int
:param endTime: optional
:type endTime: int
:param page: optional
:type page: int
:param limit: optional
:type limit: int
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"success":true,
"transfers":[
{
"from":"[email protected]",
"to":"[email protected]",
"asset":"BTC",
"qty":"1",
"time":1544433328000
},
{
"from":"[email protected]",
"to":"[email protected]",
"asset":"ETH",
"qty":"2",
"time":1544433328000
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_withdraw_api('get', 'sub-account/transfer/history.html', True, data=params)

def create_sub_account_transfer(self, **params):
"""Execute sub-account transfer
https://github.com/binance-exchange/binance-official-api-docs/blob/9dbe0e961b80557bb19708a707c7fad08842b28e/wapi-api.md#sub-account-transferfor-master-account
:param fromEmail: required - Sender email
:type fromEmail: str
:param toEmail: required - Recipient email
:type toEmail: str
:param asset: required
:type asset: str
:param amount: required
:type amount: decimal
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"success":true,
"txnId":"2966662589"
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_withdraw_api('post', 'sub-account/transfer.html', True, data=params)

def get_sub_account_assets(self, **params):
"""Fetch sub-account assets
https://github.com/binance-exchange/binance-official-api-docs/blob/9dbe0e961b80557bb19708a707c7fad08842b28e/wapi-api.md#query-sub-account-assetsfor-master-account
:param email: required
:type email: str
:param symbol: optional
:type symbol: str
:param recvWindow: optional
:type recvWindow: int
:returns: API response
.. code-block:: python
{
"success":true,
"balances":[
{
"asset":"ADA",
"free":10000,
"locked":0
},
{
"asset":"BNB",
"free":10003,
"locked":0
},
{
"asset":"BTC",
"free":11467.6399,
"locked":0
},
{
"asset":"ETH",
"free":10004.995,
"locked":0
},
{
"asset":"USDT",
"free":11652.14213,
"locked":0
}
]
}
:raises: BinanceRequestException, BinanceAPIException
"""
return self._request_withdraw_api('get', 'sub-account/assets.html', True, data=params)
15 changes: 15 additions & 0 deletions docs/account.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,18 @@ Account
.. code:: python
log = client.get_dust_log()
`Transfer dust <binance.html#binance.client.Client.transfer_dust>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
transfer = client.transfer_dust(asset='BNZ')
`Get Asset Dividend History <binance.html#binance.client.Client.get_asset_dividend_history>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
history = client.get_asset_dividend_history()
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Contents
general
market_data
account
sub_accounts
margin
websockets
depth_cache
Expand Down
36 changes: 36 additions & 0 deletions docs/sub_accounts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Sub Account Endpoints
=====================


`Get Sub Account list <binance.html#binance.client.Client.get_sub_account_list>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
accounts = client.get_sub_account_list()
`Get Sub Account Transfer History <binance.html#binance.client.Client.get_sub_account_transfer_history>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
history = client.get_sub_account_transfer_history(email='[email protected]')
`Create Sub Account Transfer <binance.html#binance.client.Client.create_sub_account_transfer>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
transfer = client.create_sub_account_transfer(
fromEmail='[email protected]',
toEmail='[email protected]',
asset='BNB',
amount='100'
)
`Get Sub Account Assets <binance.html#binance.client.Client.get_sub_account_assets>`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code:: python
assets = client.get_sub_account_assets(email='[email protected]')
Loading

0 comments on commit 01939fa

Please sign in to comment.