Skip to content

Commit

Permalink
feat: premium
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkersner committed Jul 26, 2024
1 parent 18b7352 commit 5db839c
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datamaxi/datamaxi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 @@ -25,3 +26,4 @@ def __init__(self, api_key=None, **kwargs: Any):
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)
108 changes: 108 additions & 0 deletions datamaxi/datamaxi/premium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from typing import Any, List, Dict, Union
import pandas as pd
from datamaxi.api import API
from datamaxi.lib.utils import check_required_parameters
from datamaxi.datamaxi.utils import convert_data_to_data_frame


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:
return res
# FIXME
# df = convert_data_to_data_frame(res)
# return df
else:
return res

def exchanges(self, exchange: str) -> 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)

0 comments on commit 5db839c

Please sign in to comment.