Skip to content

Commit 328c1ec

Browse files
authored
Release v1.17.0 (#165)
* 1.17.0
1 parent a441ab1 commit 328c1ec

File tree

13 files changed

+184
-28
lines changed

13 files changed

+184
-28
lines changed

.github/workflows/pythonpackage.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
uses: actions/setup-python@v1
2727
with:
2828
python-version: ${{ matrix.python-version }}
29+
- uses: actions/cache@v3
30+
with:
31+
path: ~/.cache/pip
32+
key: ${{ hashFiles('requirements/requirements-test.txt') }}
2933
- name: Install dependencies
3034
run: |
3135
python -m pip install --upgrade pip

CHANGELOG.md

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

3+
## 1.17.0 - 2022-09-05
4+
5+
### Added
6+
- New endpoint for Market:
7+
- `GET /api/v3/uiKlines`
8+
- New kline interval: `1s`
9+
10+
### Changed
11+
- Changes to `GET /api/v3/ticker` and `GET /api/v3/ticker/24hr`
12+
- New optional parameter type added
13+
- Supported values for parameter type are `FULL` and `MINI`
14+
- `FULL` is the default value and the response that is currently being returned from the endpoint
15+
- `MINI` omits the following fields from the response: `priceChangePercent`, `weightedAvgPrice`, `bidPrice`, `bidQty`, `askPrice`, `askQty`, and `lastQty`
16+
317
## 1.16.0 - 2022-08-11
418

519
### Added

binance/__version__.py

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

binance/spot/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(self, key=None, secret=None, **kwargs):
1616
from binance.spot.market import historical_trades
1717
from binance.spot.market import agg_trades
1818
from binance.spot.market import klines
19+
from binance.spot.market import ui_klines
1920
from binance.spot.market import avg_price
2021
from binance.spot.market import ticker_24hr
2122
from binance.spot.market import ticker_price

binance/spot/market.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def klines(self, symbol: str, interval: str, **kwargs):
141141
142142
Args:
143143
symbol (str): the trading pair
144-
interval (str): the interval of kline, e.g 1m, 5m, 1h, 1d, etc.
144+
interval (str): the interval of kline, e.g 1s, 1m, 5m, 1h, 1d, etc.
145145
Keyword Args:
146146
limit (int, optional): limit the results. Default 500; max 1000.
147147
startTime (int, optional): Timestamp in ms to get aggregate trades from INCLUSIVE.
@@ -153,6 +153,27 @@ def klines(self, symbol: str, interval: str, **kwargs):
153153
return self.query("/api/v3/klines", params)
154154

155155

156+
def ui_klines(self, symbol: str, interval: str, **kwargs):
157+
"""Kline/Candlestick Data
158+
159+
GET /api/v3/uiKlines
160+
161+
https://binance-docs.github.io/apidocs/spot/en/#uiklines
162+
163+
Args:
164+
symbol (str): the trading pair
165+
interval (str): the interval of kline, e.g 1s, 1m, 5m, 1h, 1d, etc.
166+
Keyword Args:
167+
limit (int, optional): limit the results. Default 500; max 1000.
168+
startTime (int, optional): Timestamp in ms to get aggregate trades from INCLUSIVE.
169+
endTime (int, optional): Timestamp in ms to get aggregate trades until INCLUSIVE.
170+
"""
171+
check_required_parameters([[symbol, "symbol"], [interval, "interval"]])
172+
173+
params = {"symbol": symbol, "interval": interval, **kwargs}
174+
return self.query("/api/v3/uiKlines", params)
175+
176+
156177
def avg_price(self, symbol: str):
157178
"""Current Average Price
158179
@@ -171,7 +192,7 @@ def avg_price(self, symbol: str):
171192
return self.query("/api/v3/avgPrice", params)
172193

173194

174-
def ticker_24hr(self, symbol: str = None, symbols: list = None):
195+
def ticker_24hr(self, symbol: str = None, symbols: list = None, **kwargs):
175196
"""24hr Ticker Price Change Statistics
176197
177198
GET /api/v3/ticker/24hr
@@ -186,7 +207,11 @@ def ticker_24hr(self, symbol: str = None, symbols: list = None):
186207
if symbol and symbols:
187208
raise ParameterArgumentError("symbol and symbols cannot be sent together.")
188209
check_type_parameter(symbols, "symbols", list)
189-
params = {"symbol": symbol, "symbols": convert_list_to_json_array(symbols)}
210+
params = {
211+
"symbol": symbol,
212+
"symbols": convert_list_to_json_array(symbols),
213+
**kwargs,
214+
}
190215
return self.query("/api/v3/ticker/24hr", params)
191216

192217

docs/source/CHANGELOG.rst

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,49 @@
22
Changelog
33
=========
44

5+
1.17.0 - 2022-09-05
6+
-------------------
7+
8+
Added
9+
^^^^^
10+
11+
* New endpoint for Market:
12+
* ``GET /api/v3/uiKlines``
13+
14+
* New kline interval: ``1s``
15+
16+
Changed
17+
^^^^^^^
18+
19+
* Changes to ``GET /api/v3/ticker`` and ``GET /api/v3/ticker/24hr``
20+
* New optional parameter type added
21+
* Supported values for parameter type are ``FULL`` and ``MINI``
22+
* ``FULL`` is the default value and the response that is currently being returned from the endpoint
23+
* ``MINI`` omits the following fields from the response: ``priceChangePercent``, ``weightedAvgPrice``, ``bidPrice``, ``bidQty``, ``askPrice``, ``askQty``, and ``lastQty``
24+
525
1.16.0 - 2022-08-11
626
-------------------
727

828
Added
929
^^^^^
1030

1131
* New endpoint for Portfolio Margin:
12-
* `GET /sapi/v1/portfolio/pmLoan` to query Portfolio Margin Bankruptcy Loan Record.
13-
* `POST /sapi/v1/portfolio/repay` to repay Portfolio Margin Bankruptcy Loan.
14-
* `GET /sapi/v1/portfolio/collateralRate` to get Portfolio Margin Collateral Rate.
32+
* ``GET /sapi/v1/portfolio/pmLoan`` to query Portfolio Margin Bankruptcy Loan Record.
33+
* ``POST /sapi/v1/portfolio/repay`` to repay Portfolio Margin Bankruptcy Loan.
34+
* ``GET /sapi/v1/portfolio/collateralRate`` to get Portfolio Margin Collateral Rate.
1535

1636
Update
1737
^^^^^^
1838

19-
* Changes to `POST /api/v3/order` and `POST /api/v3/order/cancelReplace`
20-
* New optional field `strategyId` is a parameter used to identify an order as part of a strategy.
21-
* New optional field `strategyType` is a parameter used to identify what strategy was running. (E.g. If all the orders are part of spot grid strategy, it can be set to strategyType=1000000)
22-
* Note: `strategyType` cannot be less than 1000000.
23-
* Changes to `POST /api/v3/order/oco`
24-
* New optional fields `limitStrategyId`, `limitStrategyType`, `stopStrategyId`, `stopStrategyType`
39+
* Changes to ``POST /api/v3/order`` and ``POST /api/v3/order/cancelReplace``
40+
* New optional field ``strategyId`` is a parameter used to identify an order as part of a strategy.
41+
* New optional field ``strategyType`` is a parameter used to identify what strategy was running. (E.g. If all the orders are part of spot grid strategy, it can be set to strategyType=1000000)
42+
* Note: ``strategyType`` cannot be less than 1000000.
43+
* Changes to ``POST /api/v3/order/oco``
44+
* New optional fields ``limitStrategyId``, ``limitStrategyType``, ``stopStrategyId``, ``stopStrategyType``
2545
* These are the strategy metadata parameters for both legs of the OCO orders.
26-
* `limitStrategyType` and `stopStrategyType` both cannot be less than 1000000.
27-
* `asset` is no longer mandatory in `GET /sapi/v1/lending/project/position/list`
46+
* ``limitStrategyType`` and ``stopStrategyType`` both cannot be less than 1000000.
47+
* ``asset`` is no longer mandatory in ``GET /sapi/v1/lending/project/position/list``
2848

2949
1.15.0 - 2022-07-19
3050
-------------------
@@ -34,27 +54,27 @@ Added
3454

3555
* New endpoint for Margin:
3656

37-
* `POST /sapi/v3/asset/getUserAsset` to get user assets.
57+
* ``POST /sapi/v3/asset/getUserAsset`` to get user assets.
3858

3959
* New endpoint for Wallet:
4060

41-
* `GET /sapi/v1/margin/dribblet` to query the historical information of user's margin account small-value asset conversion BNB.
61+
* ``GET /sapi/v1/margin/dribblet`` to query the historical information of user's margin account small-value asset conversion BNB.
4262

4363
1.14.0 - 2022-07-04
4464
-------------------
4565

4666
Added
4767
^^^^^
4868

49-
* New endpoint `GET /api/v3/ticker`
50-
* New endpoint `POST /api/v3/order/cancelReplace`
51-
* New websocket stream `<symbol>@ticker_<window_size>`
52-
* New websocket stream `!ticker_<window-size>@arr`
69+
* New endpoint ``GET /api/v3/ticker``
70+
* New endpoint ``POST /api/v3/order/cancelReplace``
71+
* New websocket stream ``<symbol>@ticker_<window_size>``
72+
* New websocket stream ``!ticker_<window-size>@arr``
5373

5474
Update
5575
^^^^^^
5676

57-
* #146 `savings_flexible_product_position` `asset` parameter should be optional
77+
* #146 ``savings_flexible_product_position`` ``asset`` parameter should be optional
5878

5979

6080
1.13.0 - 2022-05-23

docs/source/binance.spot.market.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Kline/Candlestick Data
3333
----------------------
3434
.. autofunction:: binance.spot.market.klines
3535

36+
UIKlines
37+
--------
38+
.. autofunction:: binance.spot.market.ui_klines
39+
3640
Current Average Price
3741
---------------------
3842
.. autofunction:: binance.spot.market.avg_price

examples/spot/market/rolling_window_ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
client = Client()
1212

1313
try:
14-
response = client.rolling_window_ticker("BNBUSDT", windowSize="1d")
14+
response = client.rolling_window_ticker("BNBUSDT", windowSize="1d", type="MINI")
1515
logging.info(response)
1616
except ClientError as error:
1717
logging.error(

examples/spot/market/ticker_24hr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88

99
spot_client = Client(base_url="https://testnet.binance.vision")
1010

11-
logging.info(spot_client.ticker_24hr("BTCUSDT"))
12-
logging.info(spot_client.ticker_24hr(symbols=["BTCUSDT", "BNBUSDT"]))
11+
logging.info(spot_client.ticker_24hr("BTCUSDT", symbols=None, type="MINI"))
12+
logging.info(
13+
spot_client.ticker_24hr(symbol=None, symbols=["BTCUSDT", "BNBUSDT"], type="FULL")
14+
)

examples/spot/market/ui_klines.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
spot_client = Client(base_url="https://testnet.binance.vision")
10+
11+
logging.info(spot_client.ui_klines("BTCUSDT", "1m"))
12+
logging.info(spot_client.ui_klines("BTCUSDT", "1h", limit=10))

tests/spot/market/test_rolling_window_ticker.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ def test_rolling_window_ticker_with_double_parameter():
5454

5555
@mock_http_response(
5656
responses.GET,
57-
"/api/v3/ticker\\?symbol=BTCUSDT&windowSize=" + str(windowSize),
57+
"/api/v3/ticker\\?symbol=BTCUSDT&windowSize=" + str(windowSize) + "&type=MINI",
5858
mock_item,
5959
200,
6060
)
6161
def test_rolling_window_ticker_with_given_params():
62-
"""Tests the API endpoint to get ticker with given parametes"""
62+
"""Tests the API endpoint to get ticker with given parameters"""
6363

6464
client = Client()
65-
response = client.rolling_window_ticker(symbol="BTCUSDT", windowSize=windowSize)
65+
response = client.rolling_window_ticker(
66+
symbol="BTCUSDT", windowSize=windowSize, type="MINI"
67+
)
6668
response.should.equal(mock_item)

tests/spot/market/test_ticker_24hr.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@ def test_avg_price_with_double_parameter():
5858
api.ticker_24hr.when.called_with(symbol=symbol, symbols=symbols).should.throw(
5959
ParameterArgumentError
6060
)
61+
62+
63+
@mock_http_response(
64+
responses.GET,
65+
"/api/v3/ticker/24hr\\?symbol=BTCUSDT&type=MINI",
66+
mock_item,
67+
200,
68+
)
69+
def test_rolling_window_ticker_with_given_params():
70+
"""Tests the API endpoint to get ticker with given parameters"""
71+
72+
api = Client()
73+
response = api.ticker_24hr(symbol="BTCUSDT", symbols=None, type="MINI")
74+
response.should.equal(mock_item)

tests/spot/market/test_ui_klines.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import responses
2+
3+
from binance.spot import Spot as Client
4+
5+
from tests.util import mock_http_response
6+
from tests.util import random_id
7+
from tests.util import timestamp
8+
from binance.error import ParameterRequiredError
9+
10+
mock_item = {"key_1": "value_1", "key_2": "value_2"}
11+
fromId = random_id()
12+
startTime = timestamp()
13+
endTime = startTime + random_id()
14+
client = Client()
15+
16+
17+
def test_kline_without_symbol():
18+
"""Tests the API endpoint to get uikline without symbol"""
19+
20+
client.ui_klines.when.called_with(symbol="", interval="1m").should.throw(
21+
ParameterRequiredError
22+
)
23+
24+
25+
def test_kline_without_interval():
26+
"""Tests the API endpoint to get kline without interval"""
27+
28+
client.ui_klines.when.called_with(symbol="BTCUSDT", interval="").should.throw(
29+
ParameterRequiredError
30+
)
31+
32+
33+
@mock_http_response(
34+
responses.GET, "/api/v3/uiKlines\\?symbol=BTCUSDT&interval=1h", mock_item, 200
35+
)
36+
def test_kline_with_default_limit():
37+
"""Tests the API endpoint to get kline with default limit"""
38+
39+
response = client.ui_klines(symbol="BTCUSDT", interval="1h")
40+
response.should.equal(mock_item)
41+
42+
43+
@mock_http_response(
44+
responses.GET,
45+
"/api/v3/uiKlines\\?symbol=BTCUSDT&interval=1h&limit=10&startTime="
46+
+ str(startTime)
47+
+ "&endTime="
48+
+ str(endTime),
49+
mock_item,
50+
200,
51+
)
52+
def test_kline_with_given_params():
53+
"""Tests the API endpoint to get kline with given parametes"""
54+
55+
response = client.ui_klines(
56+
symbol="BTCUSDT", interval="1h", limit=10, startTime=startTime, endTime=endTime
57+
)
58+
response.should.equal(mock_item)

0 commit comments

Comments
 (0)