Skip to content

Commit

Permalink
Latest Funding Rate (v0.17.0) (#54)
Browse files Browse the repository at this point in the history
* feat: latest funding rate

* chore: v0.17.0

* fix: return values

* fix: flake8
  • Loading branch information
martinkersner authored Aug 26, 2024
1 parent 3417997 commit acd8be1
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 12 deletions.
2 changes: 1 addition & 1 deletion datamaxi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.16.1"
__version__ = "0.17.0"
53 changes: 50 additions & 3 deletions datamaxi/datamaxi/funding_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def get(
sort: str = "desc",
pandas: bool = True,
) -> Union[Tuple[Dict, Callable], Tuple[pd.DataFrame, Callable]]:
"""Fetch funding rate data
"""Fetch historical funding rate data
`GET /api/v1/funding-rate`
<https://docs.datamaxiplus.com/api/datasets/funding-rate/funding-rate>
<https://docs.datamaxiplus.com/api/datasets/funding-rate/historical-funding-rate>
Args:
exchange (str): Exchange name
Expand All @@ -46,7 +46,7 @@ def get(
pandas (bool): Return data as pandas DataFrame
Returns:
Funding rate data in pandas DataFrame and next request function
Historical funding rate data in pandas DataFrame and next request function
"""
check_required_parameters(
[
Expand Down Expand Up @@ -101,6 +101,53 @@ def next_request():
else:
return res, next_request

def getLatest(
self,
sort: str = None,
limit: int = None,
symbol: str = None,
exchange: str = None,
pandas: bool = True,
) -> Union[Tuple[List, Callable], Tuple[pd.DataFrame, Callable]]:
"""Fetch latest funding rate data
`GET /api/v1/funding-rate/latest`
<https://docs.datamaxiplus.com/api/datasets/funding-rate/latest-funding-rate>
Args:
sort (str): Sort data by `asc` or `desc`
limit (int): Limit number of data to return
symbol (str): Symbol name
exchange (str): exchange name
pandas (bool): Return data as pandas DataFrame
Returns:
Latest funding rate data in pandas DataFrame
"""
params = {}

if sort is not None:
params["sort"] = sort

if limit is not None:
params["limit"] = limit

if symbol is not None:
params["symbol"] = symbol

if exchange is not None:
params["exchange"] = exchange

res = self.query("/api/v1/funding-rate/latest", params)

if pandas:
df = pd.DataFrame(res)
df = df.set_index("d")
return df
else:
return res

def exchanges(self) -> List[str]:
"""Fetch supported exchanges accepted by
[datamaxi.FundingRate.get](./#datamaxi.datamaxi.FundingRate.get)
Expand Down
15 changes: 8 additions & 7 deletions datamaxi/datamaxi/premium.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Dict, Union
from typing import Any, List, Union
import pandas as pd
from datamaxi.api import API
from datamaxi.lib.utils import check_required_parameters
Expand All @@ -24,7 +24,7 @@ def get(
sourceExchange: str = None,
targetExchange: str = None,
pandas: bool = True,
) -> Union[Dict, pd.DataFrame]:
) -> Union[List, pd.DataFrame]:
"""Fetch premium data
`GET /api/v1/premium`
Expand All @@ -42,11 +42,6 @@ def get(
Premium data in pandas DataFrame
"""
params = {}
if sourceExchange is not None:
params["sourceExchange"] = sourceExchange

if targetExchange is not None:
params["targetExchange"] = targetExchange

if sort is not None:
params["sort"] = sort
Expand All @@ -57,6 +52,12 @@ def get(
if symbol is not None:
params["symbol"] = symbol

if sourceExchange is not None:
params["sourceExchange"] = sourceExchange

if targetExchange is not None:
params["targetExchange"] = targetExchange

res = self.query("/api/v1/premium", params)

if pandas:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "datamaxi"
version = "0.16.1"
version = "0.17.0"
authors = [
{ name="Bisonai", email="[email protected]" },
]
Expand Down

0 comments on commit acd8be1

Please sign in to comment.