diff --git a/datamaxi/binance/__init__.py b/datamaxi/binance/__init__.py index 93e5773..57864b8 100644 --- a/datamaxi/binance/__init__.py +++ b/datamaxi/binance/__init__.py @@ -79,3 +79,27 @@ def candle( params = {"symbol": symbol, "interval": interval, "market": market} return self.query("/v1/raw/binance/candle", params) + + @postprocess() + def funding_rate( + self, + symbol: str, + pandas: bool = True, + ) -> Union[List, pd.DataFrame]: + """Get Binance funding rate data + + `GET /v1/raw/binance/funding-rate` + + + + Args: + symbol (str): Binance symbol + pandas (bool): Return data as pandas DataFrame + + Returns: + Binance funding rate data for a given symbol in pandas DataFrame + """ + check_required_parameters([[symbol, "symbol"]]) + + params = {"symbol": symbol} + return self.query("/v1/raw/binance/funding-rate", params) diff --git a/tests/binance/test_binance_funding_rate.py b/tests/binance/test_binance_funding_rate.py new file mode 100644 index 0000000..7054411 --- /dev/null +++ b/tests/binance/test_binance_funding_rate.py @@ -0,0 +1,35 @@ +import responses + +from datamaxi.binance import Binance as Client +from tests.util import random_str +from tests.util import mock_http_response +from urllib.parse import urlencode + + +mock_item = [ + [ + "Date", + "Funding Rate", + "Mark Price", + ], + ["07/03/2024 16:00:00", "0.00010000", "60178.96865957"], +] + +key = random_str() +client = Client(key) + +req_params = {"symbol": "BTC-USDT"} +params = {"symbol": "BTC-USDT", "pandas": False} + + +@mock_http_response( + responses.GET, + "/v1/raw/binance/funding-rate\\?" + urlencode(req_params), + mock_item, + 200, +) +def test_binance_funding_rate(): + """Tests the API endpoint to get Binance funding rate.""" + + response = client.funding_rate(**params) + response.should.equal(mock_item)