Skip to content

Commit afcb5f3

Browse files
authored
release 1.11.0 (#126)
1 parent c0bc93e commit afcb5f3

21 files changed

+361
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 1.11.0 - 2022-02-23
4+
5+
### Added
6+
- New endpoints for Gift Card (Binance Code in the API Documentation):
7+
- `POST /sapi/v1/giftcard/createCode` to create a Binance Code
8+
- `POST /sapi/v1/giftcard/redeemCode` to redeem a Binance Code
9+
- `GET /sapi/v1/giftcard/verify` to verify a Binance Code
10+
- New endpoint for Wallet:
11+
- `POST /sapi/v1/asset/dust-btc` to get assets that can be converted into BNB
12+
313
## 1.10.0 - 2022-01-11
414

515
### Added

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Binance Public API Connector Python
2-
[![PyPI version](https://img.shields.io/pypi/v/binance-connector.svg)](https://pypi.python.org/pypi/binance-connector.svg)
2+
[![PyPI version](https://img.shields.io/pypi/v/binance-connector)](https://pypi.python.org/pypi/binance-connector)
33
[![Python version](https://img.shields.io/pypi/pyversions/binance-connector)](https://www.python.org/downloads/)
44
[![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://binance-connector.readthedocs.io/en/stable/)
55
[![Code Style](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)
@@ -33,11 +33,18 @@ Usage examples:
3333
from binance.spot import Spot
3434

3535
client = Spot()
36+
37+
# Get server timestamp
3638
print(client.time())
39+
# Get klines of BTCUSDT at 1m interval
40+
print(client.klines("BTCUSDT", "1m"))
41+
# Get last 10 klines of BNBUSDT at 1h interval
42+
print(client.klines("BNBUSDT", "1h", limit=10))
3743

44+
# api key/secret are required for user data endpoints
3845
client = Spot(key='<api_key>', secret='<api_secret>')
3946

40-
# Get account information
47+
# Get account and balance information
4148
print(client.account())
4249

4350
# Post a new order

binance/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.10.0"
1+
__version__ = "1.11.0"

binance/spot/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def __init__(self, key=None, secret=None, **kwargs):
130130
from binance.spot.wallet import trade_fee
131131
from binance.spot.wallet import funding_wallet
132132
from binance.spot.wallet import api_key_permissions
133+
from binance.spot.wallet import bnb_convertible_assets
133134

134135
# MINING
135136
from binance.spot.mining import mining_algo_list
@@ -248,3 +249,8 @@ def __init__(self, key=None, secret=None, **kwargs):
248249
from binance.spot.nft import nft_deposit_history
249250
from binance.spot.nft import nft_withdraw_history
250251
from binance.spot.nft import nft_asset
252+
253+
# Gift Card (Binance Code in the API documentation)
254+
from binance.spot.gift_card import gift_card_create_code
255+
from binance.spot.gift_card import gift_card_redeem_code
256+
from binance.spot.gift_card import gift_card_verify_code

binance/spot/gift_card.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from binance.lib.utils import check_required_parameters, check_required_parameter
2+
3+
4+
def gift_card_create_code(self, token: str, amount: float, **kwargs):
5+
"""Create a Binance Code (USER_DATA)
6+
7+
POST /sapi/v1/giftcard/createCode
8+
9+
This API is for creating a Binance Code. To get started with, please make sure:
10+
11+
- You have a sufficient balance in your Binance funding wallet
12+
- You need Enable Withdrawals for the API Key which requests this endpoint.
13+
14+
https://binance-docs.github.io/apidocs/spot/en/#create-a-binance-code-user_data
15+
16+
Args:
17+
token (str): The coin type contained in the Binance Code
18+
amount (float): The amount of the coin
19+
Keyword Args:
20+
recvWindow (int, optional): The value cannot be greater than 60000
21+
"""
22+
params = [[token, "token"], [amount, "amount"]]
23+
check_required_parameters(params)
24+
25+
payload = {"token": token, "amount": amount, **kwargs}
26+
27+
return self.sign_request("POST", "/sapi/v1/giftcard/createCode", payload)
28+
29+
30+
def gift_card_redeem_code(self, code: str, **kwargs):
31+
"""Redeem a Binance Code (USER_DATA)
32+
33+
POST /sapi/v1/giftcard/redeemCode
34+
35+
This API is for redeeming the Binance Code. Once redeemed, the coins will be deposited in your funding wallet.
36+
37+
Please note that if you enter the wrong code 5 times within 24 hours, you will no longer be able to redeem any Binance Code that day.
38+
39+
https://binance-docs.github.io/apidocs/spot/en/#redeem-a-binance-code-user_data
40+
41+
Args:
42+
code (str): Binance Code
43+
Keyword Args:
44+
recvWindow (int, optional): The value cannot be greater than 60000
45+
"""
46+
check_required_parameter(code, "code")
47+
48+
payload = {"code": code, **kwargs}
49+
50+
return self.sign_request("POST", "/sapi/v1/giftcard/redeemCode", payload)
51+
52+
53+
def gift_card_verify_code(self, referenceNo: str, **kwargs):
54+
"""Verify a Binance Code (USER_DATA)
55+
56+
GET /sapi/v1/giftcard/verify
57+
58+
This API is for verifying whether the Binance Code is valid or not by entering Binance Code or reference number.
59+
60+
Please note that if you enter the wrong binance code 5 times within an hour, you will no longer be able to verify any binance code for that hour.
61+
62+
https://binance-docs.github.io/apidocs/spot/en/#verify-a-binance-code-user_data
63+
64+
Args:
65+
referenceNo (str): reference number
66+
Keyword Args:
67+
recvWindow (int, optional): The value cannot be greater than 60000
68+
"""
69+
check_required_parameter(referenceNo, "referenceNo")
70+
71+
payload = {"referenceNo": referenceNo, **kwargs}
72+
73+
return self.sign_request("GET", "/sapi/v1/giftcard/verify", payload)

binance/spot/wallet.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def account_snapshot(self, type: str, **kwargs):
4646
Keyword Args:
4747
startTime (int, optional)
4848
endTime (int, optional)
49-
limit (int, optional): min 5, max 30, default 5
49+
limit (int, optional): min 7, max 30, default 7
5050
recvWindow (int, optional): The value cannot be greater than 60000
5151
"""
5252

@@ -368,3 +368,17 @@ def api_key_permissions(self, **kwargs):
368368
"""
369369

370370
return self.sign_request("GET", "/sapi/v1/account/apiRestrictions", kwargs)
371+
372+
373+
def bnb_convertible_assets(self, **kwargs):
374+
"""Get Assets That Can Be Converted Into BNB (USER_DATA)
375+
376+
POST /sapi/v1/asset/dust-btc
377+
378+
https://binance-docs.github.io/apidocs/spot/en/#get-assets-that-can-be-converted-into-bnb-user_data
379+
380+
Keyword Args:
381+
recvWindow (int, optional): The value cannot be greater than 60000
382+
"""
383+
384+
return self.sign_request("POST", "/sapi/v1/asset/dust-btc", kwargs)

binance/websocket/spot/websocket_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,5 @@ def diff_book_depth(self, symbol: str, id: int, speed, callback, **kwargs):
150150
)
151151

152152
def user_data(self, listen_key: str, id: int, callback, **kwargs):
153-
"""listen to user data by provided listenkey"""
153+
"""Listen to user data by using the provided listen_key"""
154154
self.live_subscribe(listen_key, id, callback, **kwargs)

docs/source/CHANGELOG.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22
Changelog
33
=========
44

5+
1.11.0 - 2022-02-23
6+
-------------------
7+
8+
Added
9+
^^^^^
10+
11+
12+
* New endpoints for Gift Card (Binance Code in the API Documentation):
13+
14+
* ``POST /sapi/v1/giftcard/createCode`` to create a Binance Code
15+
* ``POST /sapi/v1/giftcard/redeemCode`` to redeem a Binance Code
16+
* ``GET /sapi/v1/giftcard/verify`` to verify a Binance Code
17+
18+
* New endpoint for Wallet:
19+
20+
* ``POST /sapi/v1/asset/dust-btc`` to get assets that can be converted into BNB
21+
522
1.10.0 - 2022-01-11
623
-------------------
724

docs/source/binance.spot.convert.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Convert Endpoints
2-
================
2+
=================
33

44

55
Get Convert Trade History (USER_DATA)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Card Gift Endpoints
2+
===================
3+
4+
Create a Binance Code (USER_DATA)
5+
---------------------------------
6+
.. autofunction:: binance.spot.gift_card.gift_card_create_code
7+
8+
Redeem a Binance Code (USER_DATA)
9+
---------------------------------
10+
.. autofunction:: binance.spot.gift_card.gift_card_redeem_code
11+
12+
Verify a Binance Code (USER_DATA)
13+
---------------------------------
14+
.. autofunction:: binance.spot.gift_card.gift_card_verify_code

docs/source/binance.spot.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ Spot APIs
88
binance.spot.blvt
99
binance.spot.bswap
1010
binance.spot.c2c
11+
binance.spot.convert
1112
binance.spot.data_stream
12-
binance.spot.futures
1313
binance.spot.fiat
14+
binance.spot.futures
15+
binance.spot.gift_card
16+
binance.spot.loan
1417
binance.spot.margin
1518
binance.spot.market
1619
binance.spot.mining
20+
binance.spot.nft
21+
binance.spot.pay
22+
binance.spot.rebate
1723
binance.spot.savings
1824
binance.spot.sub_account
1925
binance.spot.wallet

docs/source/binance.spot.wallet.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,8 @@ Funding Wallet (USER_DATA)
7979

8080
API Key Permission (USER_DATA)
8181
------------------------------
82-
.. autofunction:: binance.spot.wallet.api_key_permissions
82+
.. autofunction:: binance.spot.wallet.api_key_permissions
83+
84+
Get Assets That Can Be Converted Into BNB (USER_DATA)
85+
-----------------------------------------------------
86+
.. autofunction:: binance.spot.wallet.bnb_convertible_assets

docs/source/getting_started.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ Usage example:
3232
from binance.spot import Spot
3333
3434
client = Spot()
35+
# Get server timestamp
3536
print(client.time())
37+
# Get klines of BTCUSDT at 1m interval
38+
print(client.klines("BTCUSDT", "1m"))
39+
# Get last 10 klines of BNBUSDT at 1h interval
40+
print(client.klines("BNBUSDT", "1h", limit=10))
3641
42+
# api key/secret are required for user data endpoints
3743
client = Spot(key='<api_key>', secret='<api_secret>')
3844
39-
# Get account information
45+
# Get account and balance information
4046
print(client.account())
4147
4248
# Post a new order
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.spot import Spot as Client
5+
from binance.lib.utils import config_logging
6+
7+
config_logging(logging, logging.DEBUG)
8+
9+
key = ""
10+
secret = ""
11+
12+
client = Client(key, secret)
13+
14+
logger = logging.getLogger(__name__)
15+
16+
response = client.gift_card_create_code("BNB", 0.2)
17+
logger.info(response)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.spot import Spot as Client
5+
from binance.lib.utils import config_logging
6+
7+
config_logging(logging, logging.DEBUG)
8+
9+
key = ""
10+
secret = ""
11+
client = Client(key, secret)
12+
13+
logger = logging.getLogger(__name__)
14+
15+
response = client.gift_card_redeem_code("<the_code_to_redeem>")
16+
logger.info(response)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.spot import Spot as Client
5+
from binance.lib.utils import config_logging
6+
7+
config_logging(logging, logging.DEBUG)
8+
9+
key = ""
10+
secret = ""
11+
12+
client = Client(key, secret)
13+
14+
logger = logging.getLogger(__name__)
15+
16+
response = client.gift_card_verify_code("<the_reference_number_to_verify")
17+
logger.info(response)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.spot import Spot as Client
5+
from binance.lib.utils import config_logging
6+
7+
config_logging(logging, logging.DEBUG)
8+
9+
key = ""
10+
secret = ""
11+
12+
logger = logging.getLogger(__name__)
13+
spot_client = Client(key, secret, show_header=True)
14+
logging.info(spot_client.bnb_convertible_assets())
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import responses
2+
3+
from tests.util import random_str
4+
from tests.util import mock_http_response
5+
from urllib.parse import urlencode
6+
from binance.spot import Spot as Client
7+
from binance.error import ParameterRequiredError
8+
9+
mock_item = {"key_1": "value_1", "key_2": "value_2"}
10+
11+
key = random_str()
12+
secret = random_str()
13+
14+
params = {
15+
"token": "BNB",
16+
"amount": 0.2,
17+
}
18+
19+
client = Client(key, secret)
20+
21+
22+
def test_gift_card_create_code_without_params():
23+
"""Tests the API endpoint to create a Binance Code without params"""
24+
25+
client.gift_card_create_code.when.called_with("", "").should.throw(
26+
ParameterRequiredError
27+
)
28+
29+
30+
@mock_http_response(
31+
responses.POST,
32+
"/sapi/v1/giftcard/createCode\\?" + urlencode(params),
33+
mock_item,
34+
200,
35+
)
36+
def test_gift_card_create_code():
37+
"""Tests the API endpoint to create a Binance Code"""
38+
39+
response = client.gift_card_create_code(**params)
40+
response.should.equal(mock_item)

0 commit comments

Comments
 (0)