Skip to content
Merged
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
flake8 . --statistics
- name: Test with pytest
run: |
python -m pytest tests/
python -m pytest tests/ --ignore=tests/test_call.py
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ This package is compatible with Python v3.8+.
- [Environment Variables](#environment-variables)
- [Quickstart](#quickstart)
- [Local Development](#local-development)
- [Setup](#setup)
- [Testing](#testing)
- [Tests](#tests)
- [Links](#links)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -55,7 +54,6 @@ DataMaxi+ Python package currently includes the following clients:

- `Datamaxi`
- `Naver`
- `Google`

All clients accept the same parameters that are described at [Configuration](#configuration) section.
First, import the clients,
Expand All @@ -66,7 +64,6 @@ from datamaxi.datamaxi import Datamaxi

# Trend
from datamaxi.naver import Naver
from datamaxi.google import Google
```

and initialize them.
Expand All @@ -77,16 +74,13 @@ maxi = Datamaxi(api_key=api_key)

# Trend
naver = Naver(api_key=api_key)
google = Google(api_key=api_key)
```

## Local Development

### Setup

If you wish to work on local development please clone/fork the git repo and use `pip install -r requirements.txt` to setup the project.

### Testing
## Tests

```shell
# In case packages are not installed yet
Expand All @@ -95,6 +89,7 @@ pip3 install -r requirements/requirements-test.txt
python3 -m pytest tests/
```


## Links

- [Official Website](https://datamaxiplus.com/)
Expand Down
2 changes: 1 addition & 1 deletion datamaxi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.24.0"
__version__ = "0.25.0"
11 changes: 4 additions & 7 deletions datamaxi/datamaxi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
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_fee import ( # used in documentation # noqa:F401
CexFee,
)
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.cex_token import ( # used in documentation # noqa:F401
CexToken,
)


Expand Down
19 changes: 10 additions & 9 deletions datamaxi/datamaxi/cex.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
from typing import Any
from datamaxi.api import API
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_fee import CexFee
from datamaxi.datamaxi.cex_wallet_status import CexWalletStatus
from datamaxi.datamaxi.cex_announcement import CexAnnouncement
from datamaxi.datamaxi.cex_token_updates import CexTokenUpdates
from datamaxi.datamaxi.cex_token import CexToken


class Cex:
class Cex(API):
"""Client to fetch CEX data from DataMaxi+ API."""

def __init__(self, api_key=None, **kwargs: Any):
"""Initialize candle client.
"""Initialize CEX client.

Args:
api_key (str): The DataMaxi+ API key
**kwargs: Keyword arguments used by `datamaxi.api.API`.
"""
super().__init__(api_key, **kwargs)

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.fee = CexFee(api_key, **kwargs)
self.wallet_status = CexWalletStatus(api_key, **kwargs)
self.announcements = CexAnnouncement(api_key, **kwargs)
self.token_updates = CexTokenUpdates(api_key, **kwargs)
self.announcement = CexAnnouncement(api_key, **kwargs)
self.token = CexToken(api_key, **kwargs)
12 changes: 5 additions & 7 deletions datamaxi/datamaxi/cex_announcement.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, Optional
from datamaxi.api import API
from datamaxi.lib.constants import BASE_URL
from datamaxi.lib.constants import ASC, DESC


class CexAnnouncement(API):
Expand All @@ -13,16 +13,14 @@ def __init__(self, api_key=None, **kwargs: Any):
api_key (str): The DataMaxi+ API key
**kwargs: Keyword arguments used by `datamaxi.api.API`.
"""
if "base_url" not in kwargs:
kwargs["base_url"] = BASE_URL
super().__init__(api_key, **kwargs)

def get(
def __call__(
self,
category: Optional[str] = None,
page: int = 1,
limit: int = 1000,
sort: str = "desc",
sort: str = DESC,
) -> Dict[str, Any]:
"""Get exchange announcements

Expand All @@ -45,7 +43,7 @@ def get(
if limit < 1:
raise ValueError("limit must be greater than 0")

if sort not in ["asc", "desc"]:
if sort not in [ASC, DESC]:
raise ValueError("sort must be either asc or desc")

params = {
Expand All @@ -60,7 +58,7 @@ def get(
raise ValueError("no data found")

def next_request():
return self.get(
return self.__call__(
category=category,
page=page + 1,
limit=limit,
Expand Down
82 changes: 26 additions & 56 deletions datamaxi/datamaxi/cex_candle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@
from datamaxi.lib.utils import check_required_parameter
from datamaxi.lib.utils import check_required_parameters
from datamaxi.datamaxi.utils import convert_data_to_data_frame
from datamaxi.lib.constants import SPOT, FUTURES, INTERVAL_1D, USD


class CexCandle(API):
"""Client to fetch CEX candle data from DataMaxi+ API."""

def __init__(self, api_key=None, **kwargs: Any):
"""Initialize client.
"""Initialize cex candle 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.__module__ = __name__
self.__qualname__ = self.__class__.__qualname__

def __call__(
self,
exchange: str,
market: str,
symbol: str,
interval: str = "1d",
market: str = "spot",
page: int = 1,
limit: int = 1000,
fromDateTime: str = None,
toDateTime: str = None,
sort: str = "desc",
interval: str = INTERVAL_1D,
from_unix: str = None,
to_unix: str = None,
currency: str = USD,
pandas: bool = True,
) -> Union[Tuple[Dict, Callable], Tuple[pd.DataFrame, Callable]]:
"""Fetch candle data
Expand All @@ -39,14 +41,12 @@ def get(

Args:
exchange (str): Exchange name
market (str): Market type (spot/futures)
symbol (str): Symbol name
interval (str): Candle interval
market (str): Market type (spot/futures)
page (int): Page number
limit (int): Limit of data
fromDateTime (str): Start date and time (accepts format "2006-01-02 15:04:05" or "2006-01-02")
toDateTime (str): End date and time (accepts format "2006-01-02 15:04:05" or "2006-01-02")
sort (str): Sort order
from_unix (str): Start time in Unix timestamp
to_unix (str): End time in Unix timestamp
currency (str): Currency
pandas (bool): Return data as pandas DataFrame

Returns:
Expand All @@ -58,63 +58,33 @@ def get(
[symbol, "symbol"],
[interval, "interval"],
[market, "market"],
[currency, "currency"],
]
)

if market not in ["spot", "futures"]:
if market not in [SPOT, FUTURES]:
raise ValueError("market must be either spot or futures")

if page < 1:
raise ValueError("page must be greater than 0")

if limit < 1:
raise ValueError("limit must be greater than 0")

if fromDateTime is not None and toDateTime is not None:
raise ValueError(
"fromDateTime and toDateTime cannot be set at the same time"
)

if sort not in ["asc", "desc"]:
raise ValueError("sort must be either asc or desc")

params = {
"exchange": exchange,
"market": market,
"symbol": symbol,
"interval": interval,
"market": market,
"page": page,
"limit": limit,
"from": fromDateTime,
"to": toDateTime,
"sort": sort,
"from": from_unix,
"to": to_unix,
"currency": currency,
}

res = self.query("/api/v1/cex/candle", params)
if res["data"] is None or len(res["data"]) == 0:
raise ValueError("no data found")

def next_request():
return self.get(
exchange,
symbol,
interval,
market,
page + 1,
limit,
fromDateTime,
toDateTime,
sort,
pandas,
)

if pandas:
df = convert_data_to_data_frame(res["data"])
return df, next_request
return convert_data_to_data_frame(res["data"])
else:
return res, next_request
return res

def exchanges(self, market: str = "spot") -> List[str]:
def exchanges(self, market: str) -> List[str]:
"""Fetch supported exchanges accepted by
[datamaxi.CexCandle.get](./#datamaxi.datamaxi.CexCandle.get)
API.
Expand All @@ -131,7 +101,7 @@ def exchanges(self, market: str = "spot") -> List[str]:
"""
check_required_parameter(market, "market")

if market not in ["spot", "futures"]:
if market not in [SPOT, FUTURES]:
raise ValueError("market must be either spot or futures")

params = {"market": market}
Expand All @@ -154,7 +124,7 @@ def symbols(self, exchange: str = None, market: str = None) -> List[Dict]:
Returns:
List of supported symbols
"""
if market is not None and market not in ["spot", "futures"]:
if market is not None and market not in [SPOT, FUTURES]:
raise ValueError("market must be either spot or futures")

params = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datamaxi.lib.utils import check_required_parameter


class CexTradingFees(API):
class CexFee(API):
"""Client to fetch CEX trading fee data from DataMaxi+ API."""

def __init__(self, api_key=None, **kwargs: Any):
Expand All @@ -15,7 +15,7 @@ def __init__(self, api_key=None, **kwargs: Any):
"""
super().__init__(api_key, **kwargs)

def get(
def __call__(
self,
exchange: str = None,
symbol: str = None,
Expand All @@ -39,12 +39,12 @@ def get(
if symbol:
params["symbol"] = symbol

url_path = "/api/v1/trading-fees"
url_path = "/api/v1/cex/fees"
return self.query(url_path, params)

def exchanges(self) -> List[str]:
"""Fetch supported exchanges accepted by
[datamaxi.CexTradingFees.get](./#datamaxi.datamaxi.CexTradingFees.get)
[datamaxi.CexFee.get](./#datamaxi.datamaxi.CexFee.get)
API.

`GET /api/v1/trading-fees/exchanges`
Expand All @@ -54,7 +54,7 @@ def exchanges(self) -> List[str]:
Returns:
List of supported exchange
"""
url_path = "/api/v1/trading-fees/exchanges"
url_path = "/api/v1/cex/fees/exchanges"
return self.query(url_path)

def symbols(self, exchange: str) -> List[str]:
Expand All @@ -78,5 +78,5 @@ def symbols(self, exchange: str) -> List[str]:
"exchange": exchange,
}

url_path = "/api/v1/trading-fees/symbols"
url_path = "/api/v1/cex/fees/symbols"
return self.query(url_path, params)
Loading