Skip to content

Commit 8db3cde

Browse files
2pdchairzishuen
authored
Fox release 1.5.0 (#92)
* exchangeInfo endpoints now supports single or multi symbol query (#85) * 2430 add precommit hook (#86) * add c2c endpoints (#88) * add testcase * add orderId in /myTrades endpoint (#91) * add orderId in /myTrades endpoint * fixing test case * pump version to 1.5.0 * add links in rst doc files Co-authored-by: Chai <31032561+chairz@users.noreply.github.com> Co-authored-by: ishuen <12228644+ishuen@users.noreply.github.com>
1 parent dab4980 commit 8db3cde

40 files changed

+366
-64
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,14 @@ jobs:
2929
- name: Install dependencies
3030
run: |
3131
python -m pip install --upgrade pip
32-
pip install flake8 pytest
33-
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi
32+
pip install -r requirements/requirements-test.txt
3433
- name: Run black to review standard code format
3534
run: |
3635
# Checks if need to reformat files
3736
black --check --diff .
3837
- name: Run flake8 to check specific rules not covered by black
3938
run: |
40-
# Checks syntax and undefined names errors
41-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
42-
# Checks code complexity, exit-zero treats all errors as warnings.
43-
flake8 . --count --exit-zero --max-complexity=10 --statistics
39+
flake8 . --statistics
4440
- name: Test with pytest
4541
run: |
4642
pytest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __pycache__
1010
# Environments
1111
.env
1212
.venv
13+
venv/
1314

1415
# IDE
1516
.idea/

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
default_stages: [commit]
2+
fail_fast: true
3+
repos:
4+
- repo: https://github.com/ambv/black
5+
rev: 21.7b0
6+
hooks:
7+
- id: black
8+
- repo: https://gitlab.com/pycqa/flake8
9+
rev: 3.9.2
10+
hooks:
11+
- id: flake8
12+
- repo: local
13+
hooks:
14+
- id: pytest-check
15+
name: pytest-check
16+
entry: pytest
17+
language: system
18+
pass_filenames: false
19+
always_run: true

CHANGELOG.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

5+
## 1.5.0 - 2021-08-17
6+
7+
### Changed
8+
- `GET api/v3/exchangeInfo` now supports single or multi-symbol query
9+
- `GET api/v3/myTrades` has a new optional field `orderId`
10+
11+
### Added
12+
- `GET /sapi/v1/c2c/orderMatch/listUserOrderHistory` to query user C2C trade history
13+
514
## 1.4.0 - 2021-07-30
615

716
### Added
@@ -20,12 +29,12 @@
2029

2130
## 1.2.0 - 2021-07-12
2231

23-
### Change
32+
### Changed
2433
- Remove default value in the parameters
2534

2635
## 1.1.1 - 2021-06-24
2736

28-
### Change
37+
### Changed
2938
- Upgrade the dependency packages
3039

3140
## 1.1.0 - 2021-06-23

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include requirements/common.txt

binance/__version__.py

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

binance/error.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,19 @@ def __init__(self, params):
3434

3535
def __str__(self):
3636
return "the enum value %s is invalid." % (", ".join(self.params))
37+
38+
39+
class ParameterTypeError(Error):
40+
def __init__(self, params):
41+
self.params = params
42+
43+
def __str__(self):
44+
return f"{self.params[0]} data type has to be {self.params[1]}"
45+
46+
47+
class ParameterArgumentError(Error):
48+
def __init__(self, error_message):
49+
self.error_message = error_message
50+
51+
def __str__(self):
52+
return self.error_message

binance/lib/utils.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import json
12
import time
23

34
from urllib.parse import urlencode
4-
from binance.error import ParameterRequiredError, ParameterValueError
5+
from binance.error import (
6+
ParameterRequiredError,
7+
ParameterValueError,
8+
ParameterTypeError,
9+
)
510

611

712
def cleanNoneValue(d) -> dict:
@@ -13,7 +18,7 @@ def cleanNoneValue(d) -> dict:
1318

1419

1520
def check_required_parameter(value, name):
16-
if not value:
21+
if not value and value != 0:
1722
raise ParameterRequiredError([name])
1823

1924

@@ -34,6 +39,11 @@ def check_enum_parameter(value, enum_class):
3439
raise ParameterValueError([value])
3540

3641

42+
def check_type_parameter(value, name, data_type):
43+
if value is not None and type(value) != data_type:
44+
raise ParameterTypeError([name, data_type])
45+
46+
3747
def get_timestamp():
3848
return int(time.time() * 1000)
3949

@@ -42,5 +52,12 @@ def encoded_string(query):
4252
return urlencode(query, True).replace("%40", "@")
4353

4454

55+
def convert_list_to_json_array(symbols):
56+
if symbols is None:
57+
return symbols
58+
res = json.dumps(symbols)
59+
return res.replace(" ", "")
60+
61+
4562
def config_logging(logging, logging_devel, log_file=None):
4663
logging.basicConfig(level=logging_devel, filename=log_file)

binance/spot/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,6 @@ def __init__(self, key=None, secret=None, **kwargs):
204204
# Fiat
205205
from binance.spot.fiat import fiat_order_history
206206
from binance.spot.fiat import fiat_payment_history
207+
208+
# C2C
209+
from binance.spot.c2c import c2c_trade_history

binance/spot/account.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ def my_trades(self, symbol: str, **kwargs):
343343
symbol (str)
344344
Keyword Args:
345345
fromId (int, optional): TradeId to fetch from. Default gets most recent trades.
346+
orderId (int, optional): This can only be used in combination with symbol
346347
startTime (int, optional)
347348
endTime (int, optional)
348349
limit (int, optional): Default Value: 500; Max Value: 1000

binance/spot/c2c.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from binance.lib.utils import check_required_parameter
2+
3+
4+
def c2c_trade_history(self, tradeType: str, **kwargs):
5+
"""Get C2C Trade History (USER_DATA)
6+
7+
GET /sapi/v1/c2c/orderMatch/listUserOrderHistory
8+
9+
https://binance-docs.github.io/apidocs/spot/en/#get-c2c-trade-history-user_data
10+
11+
Args:
12+
tradeType (str): BUY, SELL
13+
Keyword Args:
14+
startTimestamp (int, optional)
15+
endTimestamp (int, optional)
16+
page (int, optional): default 1
17+
rows (int, optional): default 100, max 100
18+
recvWindow (int, optional): The value cannot be greater than 60000
19+
"""
20+
21+
check_required_parameter(tradeType, "tradeType")
22+
23+
payload = {"tradeType": tradeType, **kwargs}
24+
return self.sign_request(
25+
"GET", "/sapi/v1/c2c/orderMatch/listUserOrderHistory", payload
26+
)

binance/spot/fiat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from binance.lib.utils import check_required_parameter
2+
3+
14
def fiat_order_history(self, transactionType: int, **kwargs):
25
"""Get Fiat Deposit/Withdraw History (USER_DATA)
36
@@ -15,6 +18,7 @@ def fiat_order_history(self, transactionType: int, **kwargs):
1518
recvWindow (int, optional): The value cannot be greater than 60000
1619
"""
1720

21+
check_required_parameter(transactionType, "transactionType")
1822
payload = {"transactionType": transactionType, **kwargs}
1923
return self.sign_request("GET", "/sapi/v1/fiat/orders", payload)
2024

@@ -36,5 +40,6 @@ def fiat_payment_history(self, transactionType: int, **kwargs):
3640
recvWindow (int, optional): The value cannot be greater than 60000
3741
"""
3842

43+
check_required_parameter(transactionType, "transactionType")
3944
payload = {"transactionType": transactionType, **kwargs}
4045
return self.sign_request("GET", "/sapi/v1/fiat/payments", payload)

binance/spot/market.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from binance.lib.utils import check_required_parameter
1+
from binance.error import ParameterArgumentError
2+
from binance.lib.utils import (
3+
check_required_parameter,
4+
check_type_parameter,
5+
convert_list_to_json_array,
6+
)
27
from binance.lib.utils import check_required_parameters
38

49

@@ -30,18 +35,25 @@ def time(self):
3035
return self.query(url_path)
3136

3237

33-
def exchange_info(self):
38+
def exchange_info(self, symbol: str = None, symbols: list = None):
3439
"""Exchange Information
3540
Current exchange trading rules and symbol information
3641
3742
GET /api/v3/exchangeinfo
3843
3944
https://binance-docs.github.io/apidocs/spot/en/#exchange-information
4045
46+
Args:
47+
symbol (str, optional): the trading pair
48+
symbols (list, optional): list of trading pairs
4149
"""
4250

4351
url_path = "/api/v3/exchangeInfo"
44-
return self.query(url_path)
52+
if symbol and symbols:
53+
raise ParameterArgumentError("symbol and symbols cannot be sent together.")
54+
check_type_parameter(symbols, "symbols", list)
55+
params = {"symbol": symbol, "symbols": convert_list_to_json_array(symbols)}
56+
return self.query(url_path, params)
4557

4658

4759
def depth(self, symbol: str, **kwargs):

docs/source/CHANGELOG.rst

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,76 @@ Changelog
55
Unreleased
66
----------
77

8+
1.5.0 - 2021-08-17
9+
------------------
10+
11+
Changed
12+
^^^^^^^
13+
14+
* ``GET api/v3/exchangeInfo`` now supports single or multi-symbol query
15+
* ``GET api/v3/myTrades`` has a new optional field ``orderId``
16+
17+
Added
18+
^^^^^
19+
20+
* ``GET /sapi/v1/c2c/orderMatch/listUserOrderHistory`` to query user C2C trade history
21+
22+
823
1.4.0 - 2021-07-30
924
------------------
25+
26+
Added
27+
^^^^^
28+
29+
1030
* New Fiat endpoints
1131

1232
* ``GET /sapi/v1/fiat/orders`` to query user fiat deposit and withdraw history
1333
* ``GET /sapi/v1/fiat/payments`` to query user fiat payments history
1434

15-
* Fixed
35+
Fixed
36+
^^^^^
37+
1638

17-
* Typo in ``margin_max_transferable``
39+
* Typo in ``margin_max_transferable``
1840

1941
1.3.0 - 2021-07-22
2042
------------------
2143

2244
Added
2345
^^^^^
2446

25-
* New endpoint for Wallet:
47+
48+
* New endpoints for Wallet:
2649

2750
* ``POST /sapi/v1/asset/get-funding-asset`` to query funding wallet, includes Binance Pay, Binance Card, Binance Gift Card, Stock Token
2851
* ``GET /sapi/v1/account/apiRestrictions`` to query user API Key permission
2952

30-
3153
1.2.0 - 2021-07-12
3254
------------------
3355

3456
Changed
3557
^^^^^^^
3658

37-
* Remove default value in the parameters
3859

60+
* Remove default value in the parameters
3961

4062
1.1.1 - 2021-06-24
4163
------------------
4264

4365
Changed
4466
^^^^^^^
4567

46-
* Upgrade the dependency packages
4768

69+
* Upgrade the dependency packages
4870

4971
1.1.0 - 2021-06-23
5072
------------------
5173

5274
Added
5375
^^^^^
5476

77+
5578
* A link to the document on ``README.md``
5679
* Enabled the sub menu on document nav bar.
5780
* ``GET /sapi/v1/lending/daily/product/list`` includes new parameters, current and size.
@@ -61,11 +84,11 @@ Added
6184
* ``GET /sapi/v1/managed-subaccount/asset`` to query managed sub-account asset details (only for investor master account)
6285
* ``POST /sapi/v1/managed-subaccount/withdraw`` to withdrawal assets from the managed sub-account (only for investor master account)
6386

64-
6587
1.0.0 - 2021-06-15
6688
------------------
6789

6890
Added
6991
^^^^^
7092

93+
7194
* First release, please find details from ``README.md``

docs/source/binance.spot.c2c.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
C2C Endpoints
2+
=============
3+
4+
Get C2C Trade History (USER_DATA)
5+
---------------------------------
6+
.. autofunction:: binance.spot.c2c.c2c_trade_history

docs/source/binance.spot.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ Spot APIs
77
binance.spot.account
88
binance.spot.blvt
99
binance.spot.bswap
10+
binance.spot.c2c
1011
binance.spot.data_stream
1112
binance.spot.futures
13+
binance.spot.fiat
1214
binance.spot.margin
1315
binance.spot.market
1416
binance.spot.mining
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
from binance.error import ClientError
7+
8+
config_logging(logging, logging.DEBUG)
9+
10+
key = ""
11+
secret = ""
12+
13+
client = Client(key, secret)
14+
15+
try:
16+
response = client.c2c_trade_history("BUY")
17+
logging.info(response)
18+
except ClientError as error:
19+
logging.error(
20+
"Found error. status: {}, error code: {}, error message: {}".format(
21+
error.status_code, error.error_code, error.error_message
22+
)
23+
)

0 commit comments

Comments
 (0)