Skip to content

Commit

Permalink
feat: Binance Funding Rate (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
hayotbisonai authored Jul 8, 2024
1 parent cb26182 commit 852861e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
24 changes: 24 additions & 0 deletions datamaxi/binance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
<https://docs.datamaxiplus.com/api/datasets/cex-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)
35 changes: 35 additions & 0 deletions tests/binance/test_binance_funding_rate.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 852861e

Please sign in to comment.