From 5db839c332b581db875f9d8859dabca23e7be999 Mon Sep 17 00:00:00 2001 From: Martin Kersner Date: Fri, 26 Jul 2024 12:37:04 +0900 Subject: [PATCH] feat: premium --- datamaxi/datamaxi/__init__.py | 2 + datamaxi/datamaxi/premium.py | 108 ++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 datamaxi/datamaxi/premium.py diff --git a/datamaxi/datamaxi/__init__.py b/datamaxi/datamaxi/__init__.py index 115ac15..9d7b63f 100644 --- a/datamaxi/datamaxi/__init__.py +++ b/datamaxi/datamaxi/__init__.py @@ -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: @@ -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) diff --git a/datamaxi/datamaxi/premium.py b/datamaxi/datamaxi/premium.py new file mode 100644 index 0000000..18d278d --- /dev/null +++ b/datamaxi/datamaxi/premium.py @@ -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` + + + + 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` + + + + 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` + + + + 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)