From 38f85b37c0b30200ec9afe7862696683cd84989a Mon Sep 17 00:00:00 2001 From: Martin Kersner Date: Tue, 15 Oct 2024 16:38:24 +0900 Subject: [PATCH] feat: include CEX-related classes under `cex` --- datamaxi/datamaxi/__init__.py | 24 ++++-- datamaxi/datamaxi/cex.py | 12 +++ .../cex_announcement.py} | 6 +- .../{orderbook.py => cex_orderbook.py} | 8 +- .../datamaxi/{ticker.py => cex_ticker.py} | 8 +- .../cex_token_updates.py} | 14 ++-- datamaxi/datamaxi/cex_trading_fees.py | 82 +++++++++++++++++++ ...{wallet_status.py => cex_wallet_status.py} | 6 +- docs/{announcement.md => cex-announcement.md} | 2 +- docs/{orderbook.md => cex-orderbook.md} | 2 +- docs/{ticker.md => cex-ticker.md} | 2 +- ...{token-updates.md => cex-token-updates.md} | 2 +- docs/cex-trading-fees.md | 6 ++ ...{wallet-status.md => cex-wallet-status.md} | 2 +- mkdocs.yml | 11 +-- 15 files changed, 150 insertions(+), 37 deletions(-) rename datamaxi/{announcement/__init__.py => datamaxi/cex_announcement.py} (93%) rename datamaxi/datamaxi/{orderbook.py => cex_orderbook.py} (91%) rename datamaxi/datamaxi/{ticker.py => cex_ticker.py} (91%) rename datamaxi/{token/__init__.py => datamaxi/cex_token_updates.py} (85%) create mode 100644 datamaxi/datamaxi/cex_trading_fees.py rename datamaxi/datamaxi/{wallet_status.py => cex_wallet_status.py} (92%) rename docs/{announcement.md => cex-announcement.md} (69%) rename docs/{orderbook.md => cex-orderbook.md} (70%) rename docs/{ticker.md => cex-ticker.md} (71%) rename docs/{token-updates.md => cex-token-updates.md} (69%) create mode 100644 docs/cex-trading-fees.md rename docs/{wallet-status.md => cex-wallet-status.md} (69%) diff --git a/datamaxi/datamaxi/__init__.py b/datamaxi/datamaxi/__init__.py index e20a3af..d0b7758 100644 --- a/datamaxi/datamaxi/__init__.py +++ b/datamaxi/datamaxi/__init__.py @@ -4,13 +4,28 @@ from datamaxi.datamaxi.dex import Dex from datamaxi.datamaxi.funding_rate import FundingRate from datamaxi.datamaxi.forex import Forex -from datamaxi.datamaxi.ticker import Ticker from datamaxi.datamaxi.premium import Premium from datamaxi.datamaxi.cex_candle import CexCandle # used in documentation # noqa:F401 +from datamaxi.datamaxi.cex_ticker import ( + CexTicker, +) # used in documentation # noqa:F401 +from datamaxi.datamaxi.cex_orderbook import ( + CexOrderbook, +) # used in documentation # noqa:F401 +from datamaxi.datamaxi.cex_trading_fees import ( + CexTradingFees, +) # used in documentation # noqa:F401 +from datamaxi.datamaxi.cex_wallet_status import ( + CexWalletStatus, +) # used in documentation # noqa:F401 +from datamaxi.datamaxi.cex_announcement import ( + CexAnnouncement, +) # used in documentation # noqa:F401 +from datamaxi.datamaxi.cex_token_updates import ( + CexTokenUpdates, +) # used in documentation # noqa:F401 from datamaxi.datamaxi.dex_candle import DexCandle # used in documentation # noqa:F401 from datamaxi.datamaxi.dex_trade import DexTrade # used in documentation # noqa:F401 -from datamaxi.datamaxi.orderbook import Orderbook -from datamaxi.datamaxi.wallet_status import WalletStatus class Datamaxi: @@ -30,7 +45,4 @@ def __init__(self, api_key=None, **kwargs: Any): self.dex = Dex(api_key, **kwargs) self.funding_rate = FundingRate(api_key, **kwargs) self.forex = Forex(api_key, **kwargs) - self.ticker = Ticker(api_key, **kwargs) self.premium = Premium(api_key, **kwargs) - self.orderbook = Orderbook(api_key, **kwargs) - self.wallet_status = WalletStatus(api_key, **kwargs) diff --git a/datamaxi/datamaxi/cex.py b/datamaxi/datamaxi/cex.py index 57324db..d5e4ef3 100644 --- a/datamaxi/datamaxi/cex.py +++ b/datamaxi/datamaxi/cex.py @@ -1,5 +1,11 @@ from typing import Any from datamaxi.datamaxi.cex_candle import CexCandle +from datamaxi.datamaxi.cex_ticker import CexTicker +from datamaxi.datamaxi.cex_orderbook import CexOrderbook +from datamaxi.datamaxi.cex_trading_fees import CexTradingFees +from datamaxi.datamaxi.cex_wallet_status import CexWalletStatus +from datamaxi.datamaxi.cex_announcement import CexAnnouncement +from datamaxi.datamaxi.cex_token_updates import CexTokenUpdates class Cex: @@ -13,3 +19,9 @@ def __init__(self, api_key=None, **kwargs: Any): **kwargs: Keyword arguments used by `datamaxi.api.API`. """ self.candle = CexCandle(api_key, **kwargs) + self.ticker = CexTicker(api_key, **kwargs) + self.orderbook = CexOrderbook(api_key, **kwargs) + self.trading_fees = CexTradingFees(api_key, **kwargs) + self.wallet_status = CexWalletStatus(api_key, **kwargs) + self.announcements = CexAnnouncement(api_key, **kwargs) + self.token_updates = CexTokenUpdates(api_key, **kwargs) diff --git a/datamaxi/announcement/__init__.py b/datamaxi/datamaxi/cex_announcement.py similarity index 93% rename from datamaxi/announcement/__init__.py rename to datamaxi/datamaxi/cex_announcement.py index 1219861..202938d 100644 --- a/datamaxi/announcement/__init__.py +++ b/datamaxi/datamaxi/cex_announcement.py @@ -3,7 +3,7 @@ from datamaxi.lib.constants import BASE_URL -class Announcement(API): +class CexAnnouncement(API): """Client to fetch announcement data from DataMaxi+ API.""" def __init__(self, api_key=None, **kwargs: Any): @@ -37,7 +37,7 @@ def get( sort (str): Sort order Returns: - Announcements + Historical announcements """ if page < 1: raise ValueError("page must be greater than 0") @@ -55,7 +55,7 @@ def get( "sort": sort, } - res = self.query("/api/v1/announcements", params) + res = self.query("/api/v1/cex/announcements", params) if res["data"] is None: raise ValueError("no data found") diff --git a/datamaxi/datamaxi/orderbook.py b/datamaxi/datamaxi/cex_orderbook.py similarity index 91% rename from datamaxi/datamaxi/orderbook.py rename to datamaxi/datamaxi/cex_orderbook.py index 91659f3..a277b83 100644 --- a/datamaxi/datamaxi/orderbook.py +++ b/datamaxi/datamaxi/cex_orderbook.py @@ -5,7 +5,7 @@ from datamaxi.lib.utils import check_required_parameter -class Orderbook(API): +class CexOrderbook(API): """Client to fetch orderbook data from DataMaxi+ API.""" def __init__(self, api_key=None, **kwargs: Any): @@ -35,7 +35,7 @@ def get( pandas (bool): Return data as pandas DataFrame Returns: - Orderbook data in pandas DataFrame + CexOrderbook data in pandas DataFrame """ check_required_parameters( @@ -57,7 +57,7 @@ def get( def exchanges(self) -> List[str]: """Fetch supported exchanges accepted by - [datamaxi.Orderbook.get](./#datamaxi.datamaxi.Orderbook.get) + [datamaxi.CexOrderbook.get](./#datamaxi.datamaxi.CexOrderbook.get) API. `GET /api/v1/orderbook/exchanges` @@ -72,7 +72,7 @@ def exchanges(self) -> List[str]: def symbols(self, exchange: str) -> List[str]: """Fetch supported symbols accepted by - [datamaxi.Orderbook.get](./#datamaxi.datamaxi.Orderbook.get) + [datamaxi.CexOrderbook.get](./#datamaxi.datamaxi.CexOrderbook.get) API. `GET /api/v1/orderbook/symbols` diff --git a/datamaxi/datamaxi/ticker.py b/datamaxi/datamaxi/cex_ticker.py similarity index 91% rename from datamaxi/datamaxi/ticker.py rename to datamaxi/datamaxi/cex_ticker.py index 3209cdb..42a8c3b 100644 --- a/datamaxi/datamaxi/ticker.py +++ b/datamaxi/datamaxi/cex_ticker.py @@ -5,7 +5,7 @@ from datamaxi.lib.utils import check_required_parameter -class Ticker(API): +class CexTicker(API): """Client to fetch ticker data from DataMaxi+ API.""" def __init__(self, api_key=None, **kwargs: Any): @@ -35,7 +35,7 @@ def get( pandas (bool): Return data as pandas DataFrame Returns: - Ticker data in pandas DataFrame + CexTicker data in pandas DataFrame """ check_required_parameters( @@ -61,7 +61,7 @@ def get( def exchanges(self) -> List[str]: """Fetch supported exchanges accepted by - [datamaxi.Ticker.get](./#datamaxi.datamaxi.Ticker.get) + [datamaxi.CexTicker.get](./#datamaxi.datamaxi.CexTicker.get) API. `GET /api/v1/ticker/exchanges` @@ -76,7 +76,7 @@ def exchanges(self) -> List[str]: def symbols(self, exchange: str) -> List[str]: """Fetch supported symbols accepted by - [datamaxi.Ticker.get](./#datamaxi.datamaxi.Ticker.get) + [datamaxi.CexTicker.get](./#datamaxi.datamaxi.CexTicker.get) API. `GET /api/v1/ticker/symbols` diff --git a/datamaxi/token/__init__.py b/datamaxi/datamaxi/cex_token_updates.py similarity index 85% rename from datamaxi/token/__init__.py rename to datamaxi/datamaxi/cex_token_updates.py index ea25149..b567171 100644 --- a/datamaxi/token/__init__.py +++ b/datamaxi/datamaxi/cex_token_updates.py @@ -3,11 +3,11 @@ from datamaxi.lib.constants import BASE_URL -class Token(API): - """Client to fetch token status data from DataMaxi+ API.""" +class CexTokenUpdates(API): + """Client to fetch token update data from DataMaxi+ API.""" def __init__(self, api_key=None, **kwargs: Any): - """Initialize the object. + """Initialize token update client. Args: api_key (str): The DataMaxi+ API key @@ -17,14 +17,14 @@ def __init__(self, api_key=None, **kwargs: Any): kwargs["base_url"] = BASE_URL super().__init__(api_key, **kwargs) - def updates( + def get( self, type: Optional[str] = None, page: int = 1, limit: int = 1000, sort: str = "desc", ) -> Dict[str, Any]: - """Get Token Updates + """Get token update data `GET /api/v1/token/updates` @@ -37,7 +37,7 @@ def updates( sort (str): Sort order Returns: - Token Updates data in list of dictionary + Token update data in list of dictionary """ if page < 1: raise ValueError("page must be greater than 0") @@ -58,7 +58,7 @@ def updates( "sort": sort, } - res = self.query("/api/v1/token/updates", params) + res = self.query("/api/v1/cex/token-updates", params) if res["data"] is None: raise ValueError("no data found") diff --git a/datamaxi/datamaxi/cex_trading_fees.py b/datamaxi/datamaxi/cex_trading_fees.py new file mode 100644 index 0000000..4b8158e --- /dev/null +++ b/datamaxi/datamaxi/cex_trading_fees.py @@ -0,0 +1,82 @@ +from typing import Any, List, Dict +from datamaxi.api import API +from datamaxi.lib.utils import check_required_parameter + + +class CexTradingFees(API): + """Client to fetch CEX trading fee data from DataMaxi+ API.""" + + def __init__(self, api_key=None, **kwargs: Any): + """Initialize trading fee 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, + exchange: str = None, + symbol: str = None, + ) -> List[Dict]: + """Fetch trading fee data + + `GET /api/v1/trading-fees` + + + + Args: + exchange (str): Exchange name + symbol (str): Symbol name + + Returns: + Trading fee data + """ + params = {} + if exchange: + params["exchange"] = exchange + if symbol: + params["symbol"] = symbol + + url_path = "/api/v1/trading-fees" + return self.query(url_path, params) + + def exchanges(self) -> List[str]: + """Fetch supported exchanges accepted by + [datamaxi.CexTradingFees.get](./#datamaxi.datamaxi.CexTradingFees.get) + API. + + `GET /api/v1/trading-fees/exchanges` + + + + Returns: + List of supported exchange + """ + url_path = "/api/v1/trading-fees/exchanges" + return self.query(url_path) + + def symbols(self, exchange: str) -> List[str]: + """Fetch supported symbols accepted by + [datamaxi.CexTradingFees.get](./#datamaxi.datamaxi.CexTradingFees.get) + API. + + `GET /api/v1/trading-fees/symbols` + + + + Args: + exchange (str): Exchange name + + Returns: + List of supported assets + """ + check_required_parameter(exchange, "exchange") + + params = { + "exchange": exchange, + } + + url_path = "/api/v1/trading-fees/symbols" + return self.query(url_path, params) diff --git a/datamaxi/datamaxi/wallet_status.py b/datamaxi/datamaxi/cex_wallet_status.py similarity index 92% rename from datamaxi/datamaxi/wallet_status.py rename to datamaxi/datamaxi/cex_wallet_status.py index e8001cd..09f9842 100644 --- a/datamaxi/datamaxi/wallet_status.py +++ b/datamaxi/datamaxi/cex_wallet_status.py @@ -5,7 +5,7 @@ from datamaxi.lib.utils import check_required_parameter -class WalletStatus(API): +class CexWalletStatus(API): """Client to fetch wallet status data from DataMaxi+ API.""" def __init__(self, api_key=None, **kwargs: Any): @@ -60,7 +60,7 @@ def get( def exchanges(self) -> List[str]: """Fetch supported exchanges accepted by - [datamaxi.WalletStatus.get](./#datamaxi.datamaxi.WalletStatus.get) + [datamaxi.CexWalletStatus.get](./#datamaxi.datamaxi.CexWalletStatus.get) API. `GET /api/v1/wallet-status/exchanges` @@ -75,7 +75,7 @@ def exchanges(self) -> List[str]: def assets(self, exchange: str) -> List[str]: """Fetch supported assets accepted by - [datamaxi.WalletStatus.get](./#datamaxi.datamaxi.WalletStatus.get) + [datamaxi.CexWalletStatus.get](./#datamaxi.datamaxi.CexWalletStatus.get) API. `GET /api/v1/wallet-status/assets` diff --git a/docs/announcement.md b/docs/cex-announcement.md similarity index 69% rename from docs/announcement.md rename to docs/cex-announcement.md index b861c14..7728480 100644 --- a/docs/announcement.md +++ b/docs/cex-announcement.md @@ -1,6 +1,6 @@ # CEX Announcement -::: datamaxi.announcement +::: datamaxi.datamaxi.CexAnnouncement options: show_submodules: true show_source: false diff --git a/docs/orderbook.md b/docs/cex-orderbook.md similarity index 70% rename from docs/orderbook.md rename to docs/cex-orderbook.md index 5f9fcdd..71c6891 100644 --- a/docs/orderbook.md +++ b/docs/cex-orderbook.md @@ -1,6 +1,6 @@ # CEX Orderbook -::: datamaxi.datamaxi.Orderbook +::: datamaxi.datamaxi.CexOrderbook options: show_submodules: true show_source: false diff --git a/docs/ticker.md b/docs/cex-ticker.md similarity index 71% rename from docs/ticker.md rename to docs/cex-ticker.md index f21bd6b..a058c29 100644 --- a/docs/ticker.md +++ b/docs/cex-ticker.md @@ -1,6 +1,6 @@ # CEX Ticker -::: datamaxi.datamaxi.Ticker +::: datamaxi.datamaxi.CexTicker options: show_submodules: true show_source: false diff --git a/docs/token-updates.md b/docs/cex-token-updates.md similarity index 69% rename from docs/token-updates.md rename to docs/cex-token-updates.md index 7e07319..ee0c0af 100644 --- a/docs/token-updates.md +++ b/docs/cex-token-updates.md @@ -1,6 +1,6 @@ # CEX Token Updates -::: datamaxi.token +::: datamaxi.datamaxi.CexTokenUpdates options: show_submodules: true show_source: false diff --git a/docs/cex-trading-fees.md b/docs/cex-trading-fees.md new file mode 100644 index 0000000..fd0560d --- /dev/null +++ b/docs/cex-trading-fees.md @@ -0,0 +1,6 @@ +# CEX Trading Fees + +::: datamaxi.datamaxi.CexTradingFees + options: + show_submodules: true + show_source: false diff --git a/docs/wallet-status.md b/docs/cex-wallet-status.md similarity index 69% rename from docs/wallet-status.md rename to docs/cex-wallet-status.md index 9ecfb53..a7d9cc8 100644 --- a/docs/wallet-status.md +++ b/docs/cex-wallet-status.md @@ -1,6 +1,6 @@ # CEX Wallet Status -::: datamaxi.datamaxi.WalletStatus +::: datamaxi.datamaxi.CexWalletStatus options: show_submodules: true show_source: false diff --git a/mkdocs.yml b/mkdocs.yml index 79fab41..897749c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -33,11 +33,12 @@ nav: - API: api.md - CEX: - Candle: cex-candle.md - - Ticker: ticker.md - - Orderbook: orderbook.md - - Wallet Status: wallet-status.md - - Announcement: announcement.md - - Token Updates: token-updates.md + - Ticker: cex-ticker.md + - Orderbook: cex-orderbook.md + - Trading Fees: cex-trading-fees.md + - Wallet Status: cex-wallet-status.md + - Announcement: cex-announcement.md + - Token Updates: cex-token-updates.md - DEX: - Candle: dex-candle.md - Trade: dex-trade.md