Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binance Funding Rate #35

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading