Skip to content

Commit 1d3bbff

Browse files
authored
feat: add uiKlines support (#1555)
1 parent a84a2ae commit 1d3bbff

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

binance/async_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ async def aggregate_trade_iter(self, symbol, start_str=None, last_id=None):
403403

404404
aggregate_trade_iter.__doc__ = Client.aggregate_trade_iter.__doc__
405405

406+
async def get_ui_klines(self, **params) -> Dict:
407+
return await self._get("uiKlines", data=params, version=self.PRIVATE_API_VERSION)
408+
409+
get_ui_klines.__doc__ = Client.get_ui_klines.__doc__
410+
406411
async def get_klines(self, **params) -> Dict:
407412
return await self._get("klines", data=params, version=self.PRIVATE_API_VERSION)
408413

binance/client.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,48 @@ def aggregate_trade_iter(self, symbol: str, start_str=None, last_id=None):
650650
yield t
651651
last_id = trades[-1][self.AGG_ID]
652652

653+
def get_ui_klines(self, **params) -> Dict:
654+
"""Kline/candlestick bars for a symbol with UI enhancements. Klines are uniquely identified by their open time.
655+
656+
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#uiklines
657+
658+
:param symbol: required
659+
:type symbol: str
660+
:param interval: required - The interval for the klines (e.g., 1m, 3m, 5m, etc.)
661+
:type interval: str
662+
:param limit: optional - Default 500; max 1000.
663+
:type limit: int
664+
:param startTime: optional - Start time in milliseconds
665+
:type startTime: int
666+
:param endTime: optional - End time in milliseconds
667+
:type endTime: int
668+
669+
:returns: API response
670+
671+
.. code-block:: python
672+
673+
[
674+
[
675+
1499040000000, # Open time
676+
"0.01634790", # Open
677+
"0.80000000", # High
678+
"0.01575800", # Low
679+
"0.01577100", # Close
680+
"148976.11427815", # Volume
681+
1499644799999, # Close time
682+
"2434.19055334", # Quote asset volume
683+
308, # Number of trades
684+
"1756.87402397", # Taker buy base asset volume
685+
"28.46694368", # Taker buy quote asset volume
686+
"17928899.62484339" # Can be ignored
687+
]
688+
]
689+
690+
:raises: BinanceRequestException, BinanceAPIException
691+
692+
"""
693+
return self._get("uiKlines", data=params, version=self.PRIVATE_API_VERSION)
694+
653695
def get_klines(self, **params) -> Dict:
654696
"""Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
655697

tests/test_async_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ async def test_get_klines(clientAsync):
6060
await clientAsync.get_klines(symbol="BTCUSDT", interval="1d")
6161

6262

63+
async def test_get_uiklines(clientAsync):
64+
await clientAsync.get_ui_klines(symbol="BTCUSDT", interval="1d")
65+
66+
6367
async def test_futures_mark_price_klines(clientAsync):
6468
await clientAsync.futures_mark_price_klines(symbol="BTCUSDT", interval="1h")
6569

tests/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def test_get_aggregate_trades(client):
5656
def test_get_klines(client):
5757
client.get_klines(symbol="BTCUSDT", interval="1d")
5858

59+
def test_get_ui_klines(client):
60+
client.get_ui_klines(symbol="BTCUSDT", interval="1d")
5961

6062
def test_get_avg_price(client):
6163
client.get_avg_price(symbol="BTCUSDT")

0 commit comments

Comments
 (0)