Skip to content

Commit 42f7957

Browse files
authored
1.7.0 release (#111)
1 parent 9e7c819 commit 42f7957

19 files changed

+145
-32
lines changed

CHANGELOG.md

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

3+
## 1.7.0 - 2021-11-4
4+
5+
### Updated
6+
- Universal transfer types:
7+
- Added `MAIN_FUNDING`, `FUNDING_MAIN`, `FUNDING_UMFUTURE`, `UMFUTURE_FUNDING`, `MARGIN_FUNDING`, `FUNDING_MARGIN`, `FUNDING_CMFUTURE` and `CMFUTURE_FUNDING` to support transfer assets among funding account and other accounts
8+
- Deleted `MAIN_C2C`, `C2C_MAIN`, `C2C_UMFUTURE`, `C2C_MINING`, `UMFUTURE_C2C`, `MINING_C2C`, `MARGIN_C2C`, `C2C_MARGIN`, `MAIN_PAY` and `PAY_MAIN` as C2C account, Binance Payment, Binance Card and other business accounts are merged into a Funding account and they'll be discontinued on November 04, 2021 08:00 AM UTC
9+
- Util method `config_logging` can now provide date time in UTC and epoch time
10+
11+
### Added
12+
- New endpoint `GET api/v3/rateLimit/order` to display the user's current order count usage for all intervals
13+
314
## 1.6.0 - 2021-09-24
415

516
### Added

binance/__version__.py

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

binance/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(
6161
if type(proxies) is dict:
6262
self.proxies = proxies
6363

64+
self._logger = logging.getLogger(__name__)
6465
return
6566

6667
def query(self, url_path, payload=None):
@@ -102,7 +103,7 @@ def send_request(self, http_method, url_path, payload=None):
102103
if payload is None:
103104
payload = {}
104105
url = self.base_url + url_path
105-
logging.debug("url: " + url)
106+
self._logger.debug("url: " + url)
106107
params = cleanNoneValue(
107108
{
108109
"url": url,
@@ -112,7 +113,7 @@ def send_request(self, http_method, url_path, payload=None):
112113
}
113114
)
114115
response = self._dispatch_request(http_method)(**params)
115-
logging.debug("raw response from server:" + response.text)
116+
self._logger.debug("raw response from server:" + response.text)
116117
self._handle_exception(response)
117118

118119
try:

binance/lib/enums.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,29 @@ def _generate_next_value_(name, start, count, last_values):
77

88

99
class TransferType(AutoName):
10-
MAIN_C2C = auto()
1110
MAIN_UMFUTURE = auto()
1211
MAIN_CMFUTURE = auto()
1312
MAIN_MARGIN = auto()
1413
MAIN_MINING = auto()
15-
C2C_MAIN = auto()
16-
C2C_UMFUTURE = auto()
17-
C2C_MINING = auto()
18-
C2C_MARGIN = auto()
1914
UMFUTURE_MAIN = auto()
20-
UMFUTURE_C2C = auto()
2115
UMFUTURE_MARGIN = auto()
2216
CMFUTURE_MAIN = auto()
2317
CMFUTURE_MARGIN = auto()
2418
MARGIN_MAIN = auto()
2519
MARGIN_UMFUTURE = auto()
2620
MARGIN_CMFUTURE = auto()
2721
MARGIN_MINING = auto()
28-
MARGIN_C2C = auto()
2922
MINING_MAIN = auto()
3023
MINING_UMFUTURE = auto()
31-
MINING_C2C = auto()
3224
MINING_MARGIN = auto()
33-
MAIN_PAY = auto()
34-
PAY_MAIN = auto()
3525
ISOLATEDMARGIN_MARGIN = auto()
3626
MARGIN_ISOLATEDMARGIN = auto()
3727
ISOLATEDMARGIN_ISOLATEDMARGIN = auto()
28+
MAIN_FUNDING = auto()
29+
FUNDING_MAIN = auto()
30+
FUNDING_UMFUTURE = auto()
31+
UMFUTURE_FUNDING = auto()
32+
MARGIN_FUNDING = auto()
33+
FUNDING_MARGIN = auto()
34+
FUNDING_CMFUTURE = auto()
35+
CMFUTURE_FUNDING = auto()

binance/lib/utils.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def check_required_parameter(value, name):
2323

2424

2525
def check_required_parameters(params):
26-
"""validate multiple parameters
26+
"""Validate multiple parameters
2727
params = [
2828
['btcusdt', 'symbol'],
2929
[10, 'price']
@@ -59,5 +59,22 @@ def convert_list_to_json_array(symbols):
5959
return res.replace(" ", "")
6060

6161

62-
def config_logging(logging, logging_devel, log_file=None):
63-
logging.basicConfig(level=logging_devel, filename=log_file)
62+
def config_logging(logging, logging_level, log_file: str = None):
63+
"""Configures logging to provide a more detailed log format, which includes date time in UTC and an epoch timestamp in msec
64+
Example: 2021-11-02 19:42:04 UTC 1635882124165 <logging_level> <log_name>: <log_message>
65+
66+
Args:
67+
logging: python logging
68+
logging_level (int/str): For logging to include all messages with log levels >= logging_level. Ex: 10 or "DEBUG"
69+
logging level should be based on https://docs.python.org/3/library/logging.html#logging-levels
70+
Keyword Args:
71+
log_file (str, optional): The filename to pass the logging to a file, instead of using console. Default filemode: "a"
72+
"""
73+
74+
logging.Formatter.converter = time.gmtime # date time in GMT/UTC
75+
logging.basicConfig(
76+
level=logging_level,
77+
filename=log_file,
78+
format="%(asctime)s%(msecs)03d %(levelname)s %(name)s: %(message)s",
79+
datefmt="%Y-%m-%d %H:%M:%S UTC %s",
80+
)

binance/spot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(self, key=None, secret=None, **kwargs):
3636
from binance.spot.account import get_oco_open_orders
3737
from binance.spot.account import account
3838
from binance.spot.account import my_trades
39+
from binance.spot.account import get_order_rate_limit
3940

4041
# STREAMS
4142
from binance.spot.data_stream import new_listen_key

binance/spot/account.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,20 @@ def my_trades(self, symbol: str, **kwargs):
357357
url_path = "/api/v3/myTrades"
358358
payload = {"symbol": symbol, **kwargs}
359359
return self.sign_request("GET", url_path, payload)
360+
361+
362+
def get_order_rate_limit(self, **kwargs):
363+
"""Query Current Order Count Usage (TRADE)
364+
365+
Displays the user's current order count usage for all intervals.
366+
367+
GET /api/v3/rateLimit/order
368+
369+
https://binance-docs.github.io/apidocs/spot/en/#query-current-order-count-usage-trade
370+
371+
Keyword Args:
372+
recvWindow (int, optional): The value cannot be greater than 60000
373+
"""
374+
375+
url_path = "/api/v3/rateLimit/order"
376+
return self.sign_request("GET", url_path, {**kwargs})

binance/websocket/binance_client_factory.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ def __init__(self, *args, payload=None, **kwargs):
1717
self.protocol_instance = None
1818
self.base_client = None
1919
self.payload = payload
20+
self._logger = logging.getLogger(__name__)
2021

2122
_reconnect_error_payload = {"e": "error", "m": "Max reconnect retries reached"}
2223

2324
def startedConnecting(self, connector):
24-
logging.info("Start to connect....")
25+
self._logger.info("Start to connect....")
2526

2627
def clientConnectionFailed(self, connector, reason):
27-
logging.error(
28+
self._logger.error(
2829
"Can't connect to server. Reason: {}. Retrying: {}".format(
2930
reason, self.retries + 1
3031
)
@@ -34,7 +35,7 @@ def clientConnectionFailed(self, connector, reason):
3435
self.callback(self._reconnect_error_payload)
3536

3637
def clientConnectionLost(self, connector, reason):
37-
logging.error(
38+
self._logger.error(
3839
"Lost connection to Server. Reason: {}. Retrying: {}".format(
3940
reason, self.retries + 1
4041
)

binance/websocket/binance_client_protocol.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ def __init__(self, factory, payload=None):
88
super().__init__()
99
self.factory = factory
1010
self.payload = payload
11+
self._logger = logging.getLogger(__name__)
1112

1213
def onOpen(self):
1314
self.factory.protocol_instance = self
1415

1516
def onConnect(self, response):
16-
logging.info("Server connected")
17+
self._logger.info("Server connected")
1718
if self.payload:
18-
logging.info("Sending message to Server: {}".format(self.payload))
19+
self._logger.info("Sending message to Server: {}".format(self.payload))
1920
self.sendMessage(self.payload, isBinary=False)
2021
# reset the delay after reconnecting
2122
self.factory.resetDelay()
@@ -30,16 +31,16 @@ def onMessage(self, payload, isBinary):
3031
self.factory.callback(payload_obj)
3132

3233
def onClose(self, wasClean, code, reason):
33-
logging.warn(
34+
self._logger.warning(
3435
"WebSocket connection closed: {0}, code: {1}, clean: {2}, reason: {0}".format(
3536
reason, code, wasClean
3637
)
3738
)
3839

3940
def onPing(self, payload):
40-
logging.info("Received Ping from server")
41+
self._logger.info("Received Ping from server")
4142
self.sendPong()
42-
logging.info("Responded Pong to server")
43+
self._logger.info("Responded Pong to server")
4344

4445
def onPong(self, payload):
45-
logging.info("Received Pong from server")
46+
self._logger.info("Received Pong from server")

binance/websocket/binance_socket_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, stream_url):
1818
self.stream_url = stream_url
1919
self._conns = {}
2020
self._user_callback = None
21+
self._logger = logging.getLogger(__name__)
2122

2223
def _start_socket(
2324
self, stream_name, payload, callback, is_combined=False, is_live=True
@@ -39,7 +40,7 @@ def _start_socket(
3940
factory_url = factory_url + "/" + payload_obj["params"]
4041
payload = None
4142

42-
logging.info("Connection with URL: {}".format(factory_url))
43+
self._logger.info("Connection with URL: {}".format(factory_url))
4344

4445
factory = BinanceClientFactory(factory_url, payload=payload)
4546
factory.base_client = self

docs/source/CHANGELOG.rst

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

5+
6+
1.7.0 - 2021-11-04
7+
------------------
8+
9+
Updated
10+
^^^^^^^
11+
* Universal transfer types:
12+
* Added ``MAIN_FUNDING``, ``FUNDING_MAIN``, ``FUNDING_UMFUTURE``, ``UMFUTURE_FUNDING``, ``MARGIN_FUNDING``, ``FUNDING_MARGIN``, ``FUNDING_CMFUTURE`` and ``CMFUTURE_FUNDING`` to support transfer assets among funding account and other accounts
13+
* Deleted ``MAIN_C2C``, ``C2C_MAIN``, ``C2C_UMFUTURE``, ``C2C_MINING``, ``UMFUTURE_C2C``, ``MINING_C2C``, ``MARGIN_C2C``, ``C2C_MARGIN``, ``MAIN_PAY`` and ``PAY_MAIN`` as C2C account, Binance Payment, Binance Card and other business accounts are merged into a Funding account and they'll be discontinued on November 04, 2021 08:00 AM UTC
14+
* Util method ``config_logging`` can now provide date time in UTC and epoch time
15+
16+
Added
17+
^^^^^
18+
* New endpoint ``GET api/v3/rateLimit/order`` to display the user's current order count usage for all intervals
19+
20+
521
1.6.0 - 2021-09-24
622
------------------
723

docs/source/binance.spot.account.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,7 @@ Account Information (USER_DATA)
5757
Account Trade List (USER_DATA)
5858
------------------------------
5959
.. autofunction:: binance.spot.account.my_trades
60+
61+
Query Current Order Count Usage (TRADE)
62+
---------------------------------------
63+
.. autofunction:: binance.spot.account.get_order_rate_limit

examples/spot/blvt/blvt_info.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
secret = ""
1111

1212
client = Client(key, secret)
13-
logging.info(client.blvt_info(tokenName="LINKUP"))
13+
14+
logger = logging.getLogger(__name__)
15+
logger.info(client.blvt_info(tokenName="LINKUP"))

examples/spot/blvt/user_limit_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
config_logging(logging, logging.DEBUG)
88

9-
key = "AqUZiEuzIXKf3c7PIOV2LmDCY4PXOWcAyqpVZrpsXnt5x0BQtgNqDNTGrp0JGFEv"
10-
secret = "5ptDHTvuudtkaQttQ1KDxmQyEiPLt0N1XjYRp7jbf7BV7DbTYTvVv8gx9fYtQjpx"
9+
key = ""
10+
secret = ""
1111

1212
client = Client(key, secret)
1313
logging.info(client.user_limit_info(tokenName="BTCDOWN"))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
3+
import logging
4+
from binance.lib.utils import config_logging
5+
from binance.spot import Spot as Client
6+
7+
config_logging(logging, logging.DEBUG)
8+
9+
key = ""
10+
secret = ""
11+
12+
client = Client(key=key, secret=secret, base_url="https://testnet.binance.vision")
13+
logger = logging.getLogger(__name__)
14+
15+
logger.info(client.get_order_rate_limit())

examples/spot/trade/new_order_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
"type": "LIMIT",
1717
"timeInForce": "GTC",
1818
"quantity": 0.002,
19-
"price": 9500,
19+
"price": 49500,
2020
}
2121

2222
client = Client(key, secret, base_url="https://testnet.binance.vision")
2323

2424
try:
25-
response = client.test_new_order(**params)
25+
response = client.new_order_test(**params)
2626
logging.info(response)
2727
except ClientError as error:
2828
logging.error(

tests/spot/market/test_ping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@mock_http_response(responses.GET, "/api/v3/ping", {}, 200)
88
def test_ping():
9-
"""Tests the API endpoint to get conectivity"""
9+
"""Tests the API endpoint to get connectivity"""
1010

1111
api = Client()
1212
response = api.ping()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import responses
2+
from tests.util import random_str
3+
from tests.util import mock_http_response
4+
from binance.spot import Spot as Client
5+
6+
mock_item = {"key_1": "value_1", "key_2": "value_2"}
7+
key = random_str()
8+
secret = random_str()
9+
10+
client = Client(key, secret)
11+
12+
13+
@mock_http_response(responses.GET, "/api/v3/rateLimit/order", mock_item, 200)
14+
def test_get_order_rate_limit():
15+
"""Tests the API endpoint to get current order count usage for all intervals."""
16+
response = client.get_order_rate_limit()
17+
response.should.equal(mock_item)
18+
19+
20+
@mock_http_response(
21+
responses.GET, "/api/v3/rateLimit/order\\?recvWindow=1000", mock_item, 200
22+
)
23+
def test_get_order_rate_limit_with_recvWindow():
24+
"""Tests the API endpoint to get current order count usage for all intervals."""
25+
response = client.get_order_rate_limit(recvWindow=1000)
26+
response.should.equal(mock_item)

tests/test_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from binance.api import API
77
from binance.error import ParameterRequiredError, ServerError
88
from binance.error import ClientError
9+
import logging
910

1011
mock_item = {"key_1": "value_1", "key_2": "value_2"}
1112
mock_error_body = "<HTML><HEAD><META HTTP-EQUIV></HEAD></HTML>"
@@ -39,6 +40,7 @@ def test_API_initial():
3940
"binance-connector/" + __version__
4041
)
4142
client.session.headers.should.have.key("X-MBX-APIKEY").which.should.be.none
43+
client._logger.should.be(logging.getLogger("binance.api"))
4244

4345

4446
def test_API_with_extra_parameters():

0 commit comments

Comments
 (0)