diff --git a/binance/async_client.py b/binance/async_client.py index a3dc449e0..44c847726 100644 --- a/binance/async_client.py +++ b/binance/async_client.py @@ -402,6 +402,14 @@ async def _klines( return await self.futures_klines(**params) elif HistoricalKlinesType.FUTURES_COIN == klines_type: return await self.futures_coin_klines(**params) + elif HistoricalKlinesType.FUTURES_MARK_PRICE == klines_type: + return await self.futures_mark_price_klines(**params) + elif HistoricalKlinesType.FUTURES_INDEX_PRICE == klines_type: + return await self.futures_index_price_klines(**params) + elif HistoricalKlinesType.FUTURES_COIN_MARK_PRICE == klines_type: + return await self.futures_coin_mark_price_klines(**params) + elif HistoricalKlinesType.FUTURES_COIN_INDEX_PRICE == klines_type: + return await self.futures_coin_index_price_klines(**params) else: raise NotImplementedException(klines_type) @@ -1667,6 +1675,21 @@ async def futures_aggregate_trades(self, **params): async def futures_klines(self, **params): return await self._request_futures_api("get", "klines", data=params) + async def futures_mark_price_klines(self, **params): + return await self._request_futures_api("get", "markPriceKlines", data=params) + + futures_mark_price_klines.__doc__ = Client.futures_mark_price_klines.__doc__ + + async def futures_index_price_klines(self, **params): + return await self._request_futures_api("get", "indexPriceKlines", data=params) + + futures_index_price_klines.__doc__ = Client.futures_index_price_klines.__doc__ + + async def futures_premium_index_klines(self, **params): + return await self._request_futures_api("get", "premiumIndexKlines", data=params) + + futures_premium_index_klines.__doc__ = Client.futures_index_price_klines.__doc__ + async def futures_continous_klines(self, **params): return await self._request_futures_api("get", "continuousKlines", data=params) @@ -1992,6 +2015,17 @@ async def futures_coin_mark_price_klines(self, **params): "get", "markPriceKlines", data=params ) + futures_coin_mark_price_klines.__doc__ = Client.futures_mark_price_klines.__doc__ + + async def futures_coin_premium_index_klines(self, **params): + return await self._request_futures_coin_api( + "get", "premiumIndexKlines", data=params + ) + + futures_coin_premium_index_klines.__doc__ = ( + Client.futures_premium_index_klines.__doc__ + ) + async def futures_coin_mark_price(self, **params): return await self._request_futures_coin_api("get", "premiumIndex", data=params) @@ -3803,4 +3837,6 @@ async def options_account_get_block_trades(self, **params): "get", "block/user-trades", signed=True, data=params ) - options_account_get_block_trades.__doc__ = Client.options_account_get_block_trades.__doc__ + options_account_get_block_trades.__doc__ = ( + Client.options_account_get_block_trades.__doc__ + ) diff --git a/binance/client.py b/binance/client.py index bf04c8ecc..cdd44c971 100755 --- a/binance/client.py +++ b/binance/client.py @@ -698,6 +698,14 @@ def _klines( return self.futures_klines(**params) elif HistoricalKlinesType.FUTURES_COIN == klines_type: return self.futures_coin_klines(**params) + elif HistoricalKlinesType.FUTURES_MARK_PRICE == klines_type: + return self.futures_mark_price_klines(**params) + elif HistoricalKlinesType.FUTURES_INDEX_PRICE == klines_type: + return self.futures_index_price_klines(**params) + elif HistoricalKlinesType.FUTURES_COIN_MARK_PRICE == klines_type: + return self.futures_coin_mark_price_klines(**params) + elif HistoricalKlinesType.FUTURES_COIN_INDEX_PRICE == klines_type: + return self.futures_coin_index_price_klines(**params) else: raise NotImplementedException(klines_type) @@ -7092,6 +7100,30 @@ def futures_klines(self, **params): """ return self._request_futures_api("get", "klines", data=params) + def futures_mark_price_klines(self, **params): + """Kline/candlestick bars for the mark price of a symbol. Klines are uniquely identified by their open time. + + https://binance-docs.github.io/apidocs/futures/en/#mark-price-kline-candlestick-data + + """ + return self._request_futures_api("get", "markPriceKlines", data=params) + + def futures_index_price_klines(self, **params): + """Kline/candlestick bars for the index price of a symbol. Klines are uniquely identified by their open time. + + https://binance-docs.github.io/apidocs/futures/en/#index-price-kline-candlestick-data + + """ + return self._request_futures_api("get", "indexPriceKlines", data=params) + + def futures_premium_index_klines(self, **params): + """Premium index kline bars of a symbol.l. Klines are uniquely identified by their open time. + + https://binance-docs.github.io/apidocs/futures/en/#premium-index-kline-data + + """ + return self._request_futures_api("get", "premiumIndexKlines", data=params) + def futures_continous_klines(self, **params): """Kline/candlestick bars for a specific contract type. Klines are uniquely identified by their open time. @@ -7128,6 +7160,34 @@ def futures_historical_klines( klines_type=HistoricalKlinesType.FUTURES, ) + def futures_historical_mark_price_klines( + self, symbol, interval, start_str, end_str=None, limit=500 + ): + """Get historical futures mark price klines from Binance + + :param symbol: Name of symbol pair e.g. BNBBTC + :type symbol: str + :param interval: Binance Kline interval + :type interval: str + :param start_str: Start date string in UTC format or timestamp in milliseconds + :type start_str: str|int + :param end_str: optional - end date string in UTC format or timestamp in milliseconds (default will fetch everything up to now) + :type end_str: str|int + :param limit: Default 500; max 1000. + :type limit: int + + :return: list of OHLCV values (Open time, Open, High, Low, Close, Volume, Close time, Quote asset volume, Number of trades, Taker buy base asset volume, Taker buy quote asset volume, Ignore) + + """ + return self._historical_klines( + symbol, + interval, + start_str, + end_str=end_str, + limit=limit, + klines_type=HistoricalKlinesType.FUTURES_MARK_PRICE, + ) + def futures_historical_klines_generator( self, symbol, interval, start_str, end_str=None ): @@ -7769,6 +7829,14 @@ def futures_coin_index_price_klines(self, **params): """ return self._request_futures_coin_api("get", "indexPriceKlines", data=params) + def futures_coin_premium_index_klines(self, **params): + """Kline/candlestick bars for the index price of a pair.. + + https://binance-docs.github.io/apidocs/delivery/en/#premium-index-kline-data + + """ + return self._request_futures_coin_api("get", "premiumIndexKlines", data=params) + def futures_coin_mark_price_klines(self, **params): """Kline/candlestick bars for the index price of a pair.. diff --git a/binance/enums.py b/binance/enums.py index a1f6ae54d..539f9e130 100644 --- a/binance/enums.py +++ b/binance/enums.py @@ -70,6 +70,10 @@ class HistoricalKlinesType(Enum): SPOT = 1 FUTURES = 2 FUTURES_COIN = 3 + FUTURES_MARK_PRICE = 4 + FUTURES_INDEX_PRICE = 5 + FUTURES_COIN_MARK_PRICE = 6 + FUTURES_COIN_INDEX_PRICE = 7 class FuturesType(Enum): diff --git a/tests/test_async_client.py b/tests/test_async_client.py index d7c32fb33..5e499e3e5 100644 --- a/tests/test_async_client.py +++ b/tests/test_async_client.py @@ -57,6 +57,23 @@ async def test_get_klines(clientAsync): await clientAsync.get_klines(symbol="BTCUSDT", interval="1d") +async def test_futures_mark_price_klines(clientAsync): + await clientAsync.futures_mark_price_klines(symbol="BTCUSDT", interval="1h") + + +async def test_futures_index_price_klines(clientAsync): + await clientAsync.futures_index_price_klines(pair="BTCUSDT", interval="1h") + + +async def test_futures_premium_index_klines(clientAsync): + await clientAsync.futures_premium_index_klines(symbol="BTCUSDT", interval="1h") + + +@pytest.mark.skip(reason="network error") +async def test_futures_coin_premium_index_klines(clientAsync): + await clientAsync.futures_coin_premium_index_klines(symbol="BTCUSD", interval="1h") + + async def test_get_avg_price(clientAsync): await clientAsync.get_avg_price(symbol="BTCUSDT") diff --git a/tests/test_async_client_futures.py b/tests/test_async_client_futures.py index 7dabf7027..38f73fb98 100644 --- a/tests/test_async_client_futures.py +++ b/tests/test_async_client_futures.py @@ -598,4 +598,6 @@ async def test_futures_coin_account_trade_history_download(futuresClientAsync): @pytest.mark.skip(reason="No sandbox support") async def test_futures_coin_account_trade_download_id(futuresClientAsync): - await futuresClientAsync.futures_coin_account_trade_history_download_link(downloadId="123") + await futuresClientAsync.futures_coin_account_trade_history_download_link( + downloadId="123" + ) diff --git a/tests/test_client_futures.py b/tests/test_client_futures.py index c9b3478f9..a72161667 100644 --- a/tests/test_client_futures.py +++ b/tests/test_client_futures.py @@ -40,6 +40,18 @@ def test_futures_klines(futuresClient): futuresClient.futures_klines(symbol="BTCUSDT", interval="1h") +def test_futures_mark_price_klines(futuresClient): + futuresClient.futures_mark_price_klines(symbol="BTCUSDT", interval="1h") + + +def test_futures_index_price_klines(futuresClient): + futuresClient.futures_index_price_klines(pair="BTCUSDT", interval="1h") + + +def test_futures_premium_index_klines(futuresClient): + futuresClient.futures_premium_index_klines(symbol="BTCUSDT", interval="1h") + + def test_futures_continous_klines(futuresClient): futuresClient.futures_continous_klines( pair="BTCUSDT", contractType="PERPETUAL", interval="1h" @@ -567,10 +579,12 @@ def test_futures_coin_stream_close(futuresClient): listen_key = futuresClient.futures_coin_stream_get_listen_key() futuresClient.futures_coin_stream_close(listenKey=listen_key) + ######################################################## # Test block trades ######################################################## + @pytest.mark.skip(reason="No sandbox support") def test_futures_coin_account_order_history_download(futuresClient): futuresClient.futures_coin_account_order_download() @@ -632,6 +646,7 @@ def test_futures_coin_account_order_download_id_mock(futuresClient): ) assert response == expected_response + def test_futures_coin_account_trade_history_download_id_mock(futuresClient): expected_response = { "avgCostTimestampOfLast30d": 7241837,