Skip to content

Commit

Permalink
feat: include CEX-related classes under cex
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkersner committed Oct 15, 2024
1 parent de390af commit 38f85b3
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 37 deletions.
24 changes: 18 additions & 6 deletions datamaxi/datamaxi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
12 changes: 12 additions & 0 deletions datamaxi/datamaxi/cex.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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`
Expand All @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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`
Expand All @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
Expand All @@ -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")
Expand All @@ -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")

Expand Down
82 changes: 82 additions & 0 deletions datamaxi/datamaxi/cex_trading_fees.py
Original file line number Diff line number Diff line change
@@ -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`
<https://docs.datamaxiplus.com/rest/cex/trading-fees/data>
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`
<https://docs.datamaxiplus.com/rest/cex/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`
<https://docs.datamaxiplus.com/rest/cex/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)
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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`
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion docs/announcement.md → docs/cex-announcement.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CEX Announcement

::: datamaxi.announcement
::: datamaxi.datamaxi.CexAnnouncement
options:
show_submodules: true
show_source: false
2 changes: 1 addition & 1 deletion docs/orderbook.md → docs/cex-orderbook.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CEX Orderbook

::: datamaxi.datamaxi.Orderbook
::: datamaxi.datamaxi.CexOrderbook
options:
show_submodules: true
show_source: false
2 changes: 1 addition & 1 deletion docs/ticker.md → docs/cex-ticker.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CEX Ticker

::: datamaxi.datamaxi.Ticker
::: datamaxi.datamaxi.CexTicker
options:
show_submodules: true
show_source: false
2 changes: 1 addition & 1 deletion docs/token-updates.md → docs/cex-token-updates.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CEX Token Updates

::: datamaxi.token
::: datamaxi.datamaxi.CexTokenUpdates
options:
show_submodules: true
show_source: false
6 changes: 6 additions & 0 deletions docs/cex-trading-fees.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# CEX Trading Fees

::: datamaxi.datamaxi.CexTradingFees
options:
show_submodules: true
show_source: false
2 changes: 1 addition & 1 deletion docs/wallet-status.md → docs/cex-wallet-status.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CEX Wallet Status

::: datamaxi.datamaxi.WalletStatus
::: datamaxi.datamaxi.CexWalletStatus
options:
show_submodules: true
show_source: false
11 changes: 6 additions & 5 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38f85b3

Please sign in to comment.