Skip to content

Commit

Permalink
Forex, ticker, premium (#47)
Browse files Browse the repository at this point in the history
* feat: forex

* feat: ticker

* feat: premium

* feat: /v1 -> /api/v1

* fix: missing import

* fix: remove additional premium param

* feat: pandas conversion

* fix: flake8

* feat: bump up version to v0.14.0

* feat: docs
  • Loading branch information
martinkersner authored Jul 26, 2024
1 parent cfa5e64 commit 3e17555
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 56 deletions.
2 changes: 1 addition & 1 deletion datamaxi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.13.0"
__version__ = "0.14.0"
6 changes: 6 additions & 0 deletions datamaxi/datamaxi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from datamaxi.datamaxi.candle import Candle
from datamaxi.datamaxi.funding_rate import FundingRate
from datamaxi.datamaxi.dex_trade import DexTrade
from datamaxi.datamaxi.forex import Forex
from datamaxi.datamaxi.ticker import Ticker
from datamaxi.datamaxi.premium import Premium


class Datamaxi:
Expand All @@ -21,3 +24,6 @@ def __init__(self, api_key=None, **kwargs: Any):
self.candle = Candle(api_key, **kwargs)
self.funding_rate = FundingRate(api_key, **kwargs)
self.dex_trade = DexTrade(api_key, **kwargs)
self.forex = Forex(api_key, **kwargs)
self.ticker = Ticker(api_key, **kwargs)
self.premium = Premium(api_key, **kwargs)
16 changes: 8 additions & 8 deletions datamaxi/datamaxi/candle.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get(
) -> Union[Tuple[Dict, Callable], Tuple[pd.DataFrame, Callable]]:
"""Fetch candle data
`GET /v1/candle`
`GET /api/v1/candle`
<https://docs.datamaxiplus.com/api/datasets/candle/candle>
Expand Down Expand Up @@ -90,7 +90,7 @@ def get(
"sort": sort,
}

res = self.query("/v1/candle", params)
res = self.query("/api/v1/candle", params)
if res["data"] is None:
raise ValueError("no data found")

Expand Down Expand Up @@ -119,7 +119,7 @@ def exchanges(self, market: str = "spot") -> List[str]:
[datamaxi.Candle.get](./#datamaxi.datamaxi.Candle.get)
API.
`GET /v1/candle/exchanges`
`GET /api/v1/candle/exchanges`
<https://docs.datamaxiplus.com/api/datasets/candle/exchanges>
Expand All @@ -135,15 +135,15 @@ def exchanges(self, market: str = "spot") -> List[str]:
raise ValueError("market must be either spot or futures")

params = {"market": market}
url_path = "/v1/candle/exchanges"
url_path = "/api/v1/candle/exchanges"
return self.query(url_path, params)

def symbols(self, exchange: str, market: str = "spot") -> List[str]:
"""Fetch supported symbols accepted by
[datamaxi.Candle.get](./#datamaxi.datamaxi.Candle.get)
API.
`GET /v1/candle/symbols`
`GET /api/v1/candle/symbols`
<https://docs.datamaxiplus.com/api/datasets/candle/symbols>
Expand All @@ -165,15 +165,15 @@ def symbols(self, exchange: str, market: str = "spot") -> List[str]:
raise ValueError("market must be either spot or futures")

params = {"exchange": exchange, "market": market}
url_path = "/v1/candle/symbols"
url_path = "/api/v1/candle/symbols"
return self.query(url_path, params)

def intervals(self, exchange: str, market: str = "spot") -> List[str]:
"""Fetch supported intervals accepted by
[datamaxi.Candle.get](./#datamaxi.datamaxi.Candle.get)
API.
`GET /v1/candle/intervals`
`GET /api/v1/candle/intervals`
<https://docs.datamaxiplus.com/api/datasets/candle/intervals>
Expand All @@ -192,5 +192,5 @@ def intervals(self, exchange: str, market: str = "spot") -> List[str]:
)

params = {"exchange": exchange, "market": market}
url_path = "/v1/candle/intervals"
url_path = "/api/v1/candle/intervals"
return self.query(url_path, params)
8 changes: 4 additions & 4 deletions datamaxi/datamaxi/dex_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get(
) -> Union[Tuple[Dict, Callable], Tuple[pd.DataFrame, Callable]]:
"""Fetch DEX trade data
`GET /v1/dex/trade`
`GET /api/v1/dex/trade`
<https://docs.datamaxiplus.com/api/datasets/dex-trade/trade>
Expand Down Expand Up @@ -77,7 +77,7 @@ def get(
"sort": sort,
}

res = self.query("/v1/dex/trade", params)
res = self.query("/api/v1/dex/trade", params)
if res["data"] is None:
raise ValueError("no data found")

Expand All @@ -104,12 +104,12 @@ def exchanges(self) -> List[str]:
[datamaxi.DexTrade.get](./#datamaxi.datamaxi.DexTrade.get)
API.
`GET /v1/dex/trade/exchanges`
`GET /api/v1/dex/trade/exchanges`
<https://docs.datamaxiplus.com/api/datasets/dex-trade/exchanges>
Returns:
List of supported exchanges
"""
url_path = "/v1/dex/trade/exchanges"
url_path = "/api/v1/dex/trade/exchanges"
return self.query(url_path)
65 changes: 65 additions & 0 deletions datamaxi/datamaxi/forex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from typing import Any, List, Dict, Union
import pandas as pd
from datamaxi.api import API
from datamaxi.lib.utils import check_required_parameter


class Forex(API):
"""Client to fetch forex data from DataMaxi+ API."""

def __init__(self, api_key=None, **kwargs: Any):
"""Initialize forex client.
Args:
api_key (str): The DataMaxi+ API key
**kwargs: Keyword arguments used by `datamaxi.api.API`.
"""
super().__init__(api_key, **kwargs)

def get(
self,
symbol: str,
pandas: bool = True,
) -> Union[Dict, pd.DataFrame]:
"""Fetch forex data
`GET /api/v1/forex`
<https://docs.datamaxiplus.com/api/datasets/forex/forex>
Args:
symbol (str): Symbol name
pandas (bool): Return data as pandas DataFrame
Returns:
Forex data in pandas DataFrame
"""
check_required_parameter(symbol, "symbol")

params = {
"symbol": symbol,
}

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

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

def symbols(self) -> List[str]:
"""Fetch supported symbols accepted by
[datamaxi.Forex.get](./#datamaxi.datamaxi.Forex.get)
API.
`GET /api/v1/forex/symbols`
<https://docs.datamaxiplus.com/api/datasets/forex/symbols>
Returns:
List of supported symbols
"""
url_path = "/api/v1/forex/symbols"
return self.query(url_path)
12 changes: 6 additions & 6 deletions datamaxi/datamaxi/funding_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get(
) -> Union[Tuple[Dict, Callable], Tuple[pd.DataFrame, Callable]]:
"""Fetch funding rate data
`GET /v1/funding-rate`
`GET /api/v1/funding-rate`
<https://docs.datamaxiplus.com/api/datasets/funding-rate/funding-rate>
Expand Down Expand Up @@ -79,7 +79,7 @@ def get(
"sort": sort,
}

res = self.query("/v1/funding-rate", params)
res = self.query("/api/v1/funding-rate", params)
if res["data"] is None:
raise ValueError("no data found")

Expand All @@ -106,22 +106,22 @@ def exchanges(self) -> List[str]:
[datamaxi.FundingRate.get](./#datamaxi.datamaxi.FundingRate.get)
API.
`GET /v1/funding-rate/exchanges`
`GET /api/v1/funding-rate/exchanges`
<https://docs.datamaxiplus.com/api/datasets/funding-rate/exchanges>
Returns:
List of supported exchanges
"""
url_path = "/v1/funding-rate/exchanges"
url_path = "/api/v1/funding-rate/exchanges"
return self.query(url_path)

def symbols(self, exchange: str, market: str = "spot") -> List[str]:
"""Fetch supported symbols accepted by
[datamaxi.FundingRate.get](./#datamaxi.datamaxi.FundingRate.get)
API.
`GET /v1/funding-rate/symbols`
`GET /api/v1/funding-rate/symbols`
<https://docs.datamaxiplus.com/api/datasets/funding-rate/symbols>
Expand All @@ -133,5 +133,5 @@ def symbols(self, exchange: str, market: str = "spot") -> List[str]:
"""
check_required_parameter(exchange, "exchange")
params = {"exchange": exchange}
url_path = "/v1/funding-rate/symbols"
url_path = "/api/v1/funding-rate/symbols"
return self.query(url_path, params)
106 changes: 106 additions & 0 deletions datamaxi/datamaxi/premium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from typing import Any, List, Dict, Union
import pandas as pd
from datamaxi.api import API
from datamaxi.lib.utils import check_required_parameters


class Premium(API):
"""Client to fetch premium data from DataMaxi+ API."""

def __init__(self, api_key=None, **kwargs: Any):
"""Initialize premium client.
Args:
api_key (str): The DataMaxi+ API key
**kwargs: Keyword arguments used by `datamaxi.api.API`.
"""
super().__init__(api_key, **kwargs)

def get(
self,
sourceExchange: str,
targetExchange: str,
symbol: str,
pandas: bool = True,
) -> Union[Dict, pd.DataFrame]:
"""Fetch premium data
`GET /api/v1/premium`
<https://docs.datamaxiplus.com/api/datasets/premium/premium>
Args:
sourceExchange (str): Source exchange name
targetExchange (str): Target exchange name
symbol (str): Symbol name
pandas (bool): Return data as pandas DataFrame
Returns:
Premium data in pandas DataFrame
"""

check_required_parameters(
[
[sourceExchange, "sourceExchange"],
[targetExchange, "targetExchange"],
[symbol, "symbol"],
]
)

params = {
"sourceExchange": sourceExchange,
"targetExchange": targetExchange,
"symbol": symbol,
}

res = self.query("/api/v1/premium", 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.Premium.get](./#datamaxi.datamaxi.Premium.get)
API.
`GET /api/v1/Premium/exchanges`
<https://docs.datamaxiplus.com/api/datasets/Premium/exchanges>
Returns:
List of supported exchange
"""
url_path = "/api/v1/premium/exchanges"
return self.query(url_path)

def symbols(self, sourceExchange: str, targetExchange: str) -> List[str]:
"""Fetch supported symbols accepted by
[datamaxi.Premium.get](./#datamaxi.datamaxi.Premium.get)
API.
`GET /api/v1/premium/symbols`
<https://docs.datamaxiplus.com/api/datasets/premium/symbols>
Args:
sourceExchange (str): Source exchange name
targetExchange (str): Target exchange name
Returns:
List of supported symbols
"""
check_required_parameters(
[
[sourceExchange, "sourceExchange"],
[targetExchange, "targetExchange"],
]
)

params = {"sourceExchange": sourceExchange, "targetExchange": targetExchange}

url_path = "/api/v1/premium/symbols"
return self.query(url_path, params)
Loading

0 comments on commit 3e17555

Please sign in to comment.