Skip to content

Commit

Permalink
feat: add uiKlines support (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcriadoperez authored Feb 22, 2025
1 parent a84a2ae commit 1d3bbff
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions binance/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ async def aggregate_trade_iter(self, symbol, start_str=None, last_id=None):

aggregate_trade_iter.__doc__ = Client.aggregate_trade_iter.__doc__

async def get_ui_klines(self, **params) -> Dict:
return await self._get("uiKlines", data=params, version=self.PRIVATE_API_VERSION)

get_ui_klines.__doc__ = Client.get_ui_klines.__doc__

async def get_klines(self, **params) -> Dict:
return await self._get("klines", data=params, version=self.PRIVATE_API_VERSION)

Expand Down
42 changes: 42 additions & 0 deletions binance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,48 @@ def aggregate_trade_iter(self, symbol: str, start_str=None, last_id=None):
yield t
last_id = trades[-1][self.AGG_ID]

def get_ui_klines(self, **params) -> Dict:
"""Kline/candlestick bars for a symbol with UI enhancements. Klines are uniquely identified by their open time.
https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints#uiklines
:param symbol: required
:type symbol: str
:param interval: required - The interval for the klines (e.g., 1m, 3m, 5m, etc.)
:type interval: str
:param limit: optional - Default 500; max 1000.
:type limit: int
:param startTime: optional - Start time in milliseconds
:type startTime: int
:param endTime: optional - End time in milliseconds
:type endTime: int
:returns: API response
.. code-block:: python
[
[
1499040000000, # Open time
"0.01634790", # Open
"0.80000000", # High
"0.01575800", # Low
"0.01577100", # Close
"148976.11427815", # Volume
1499644799999, # Close time
"2434.19055334", # Quote asset volume
308, # Number of trades
"1756.87402397", # Taker buy base asset volume
"28.46694368", # Taker buy quote asset volume
"17928899.62484339" # Can be ignored
]
]
:raises: BinanceRequestException, BinanceAPIException
"""
return self._get("uiKlines", data=params, version=self.PRIVATE_API_VERSION)

def get_klines(self, **params) -> Dict:
"""Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
Expand Down
4 changes: 4 additions & 0 deletions tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ async def test_get_klines(clientAsync):
await clientAsync.get_klines(symbol="BTCUSDT", interval="1d")


async def test_get_uiklines(clientAsync):
await clientAsync.get_ui_klines(symbol="BTCUSDT", interval="1d")


async def test_futures_mark_price_klines(clientAsync):
await clientAsync.futures_mark_price_klines(symbol="BTCUSDT", interval="1h")

Expand Down
2 changes: 2 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def test_get_aggregate_trades(client):
def test_get_klines(client):
client.get_klines(symbol="BTCUSDT", interval="1d")

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

def test_get_avg_price(client):
client.get_avg_price(symbol="BTCUSDT")
Expand Down

0 comments on commit 1d3bbff

Please sign in to comment.