Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trading fees & Package Reorganization (v0.21.0) #62

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datamaxi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.20.1"
__version__ = "0.21.0"
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 ( # used in documentation # noqa:F401
CexTicker,
)
from datamaxi.datamaxi.cex_orderbook import ( # used in documentation # noqa:F401
CexOrderbook,
)
from datamaxi.datamaxi.cex_trading_fees import ( # used in documentation # noqa:F401
CexTradingFees,
)
from datamaxi.datamaxi.cex_wallet_status import ( # used in documentation # noqa:F401
CexWalletStatus,
)
from datamaxi.datamaxi.cex_announcement import ( # used in documentation # noqa:F401
CexAnnouncement,
)
from datamaxi.datamaxi.cex_token_updates import ( # used in documentation # noqa:F401
CexTokenUpdates,
)
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 All @@ -28,7 +28,7 @@ def get(

`GET /api/v1/announcements`

<https://docs.datamaxiplus.com/rest/announcements>
<https://docs.datamaxiplus.com/rest/cex/announcements>

Args:
category (str): announcement category
Expand All @@ -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 All @@ -27,15 +27,15 @@ def get(

`GET /api/v1/orderbook`

<https://docs.datamaxiplus.com/rest/orderbook/orderbook>
<https://docs.datamaxiplus.com/rest/cex/orderbook/data>

Args:
exchange (str): Exchange name
symbol (str): symbol name
pandas (bool): Return data as pandas DataFrame

Returns:
Orderbook data in pandas DataFrame
CexOrderbook data in pandas DataFrame
"""

check_required_parameters(
Expand All @@ -57,12 +57,12 @@ 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`

<https://docs.datamaxiplus.com/rest/orderbook/exchanges>
<https://docs.datamaxiplus.com/rest/cex/orderbook/exchanges>

Returns:
List of supported exchange
Expand All @@ -72,12 +72,12 @@ 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`

<https://docs.datamaxiplus.com/rest/orderbook/symbols>
<https://docs.datamaxiplus.com/rest/cex/orderbook/symbols>

Args:
exchange (str): Exchange name
Expand Down
14 changes: 7 additions & 7 deletions datamaxi/datamaxi/ticker.py → datamaxi/datamaxi/cex_ticker.py
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 All @@ -27,15 +27,15 @@ def get(

`GET /api/v1/ticker`

<https://docs.datamaxiplus.com/rest/ticker/ticker>
<https://docs.datamaxiplus.com/rest/cex/ticker/data>

Args:
exchange (str): Exchange name
symbol (str): Symbol name
pandas (bool): Return data as pandas DataFrame

Returns:
Ticker data in pandas DataFrame
CexTicker data in pandas DataFrame
"""

check_required_parameters(
Expand All @@ -61,12 +61,12 @@ 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`

<https://docs.datamaxiplus.com/rest/ticker/exchanges>
<https://docs.datamaxiplus.com/rest/cex/ticker/exchanges>

Returns:
List of supported exchange
Expand All @@ -76,12 +76,12 @@ 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`

<https://docs.datamaxiplus.com/rest/ticker/symbols>
<https://docs.datamaxiplus.com/rest/cex/ticker/symbols>

Args:
exchange (str): Exchange name
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,18 +17,18 @@ 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`

<https://docs.datamaxiplus.com/rest/token-listing-delisting>
<https://docs.datamaxiplus.com/rest/cex/token-updates>

Args:
type (str): Update type
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)
Loading
Loading