datamaxi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
datamaxi-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Bisonai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ include requirements/common.txt
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.1
2
+ Name: datamaxi
3
+ Version: 0.1.0
4
+ Summary: Official Python client for DataMaxi+ API
5
+ Author-email: Bisonai <business@bisonai.com>
6
+ Project-URL: Homepage, https://github.com/bisonai/datamaxi-python
7
+ Project-URL: Issues, https://github.com/bisonai/datamaxi-python/issues
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Intended Audience :: Financial and Insurance Industry
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: requests>=2.31.0
19
+ Requires-Dist: pandas
20
+
21
+ # DataMaxi+ Python Client
22
+ [![PyPI version](https://img.shields.io/pypi/v/datamaxi)](https://pypi.python.org/pypi/datamaxi)
23
+ [![Python version](https://img.shields.io/pypi/pyversions/datamaxi)](https://www.python.org/downloads/)
24
+ [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://datamaxi.readthedocs.io/en/stable/)
25
+ [![Code Style](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)
26
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
27
+
28
+ This is the official implementation of Python client for DataMaxi+ API.
29
+ The package can be used to fetch both historical and latest data using [DataMaxi+ API](https://docs.neverest.finance/).
30
+ This package is compatible with Python v3.8+.
31
+
32
+ * [Installation](#installation)
33
+ * [Configuration](#configuration)
34
+ * [Environment Variables](#environment-variables)
35
+ * [Quickstart](#quickstart)
36
+ * [Local Development](#local-development)
37
+ * [Setup](#setup)
38
+ * [Testing](#testing)
39
+ * [Links](#links)
40
+ * [Contributing](#contributing)
41
+ * [License](#license)
42
+
43
+ ## Installation
44
+
45
+ ```shell
46
+ pip install datamaxi
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ Access to DataMaxi+ is protected by API Key.
52
+ If you are interested to try DataMaxi+, you can request your API key at [business@bisonai.com](mailto:business@bisonai.com).
53
+
54
+ | Option | Explanation |
55
+ |--------------------|---------------------------------------------------------------------------------------|
56
+ | `api_key` | Your API key |
57
+ | `base_url` | If `base_url` is not provided, it defaults to `api.neverest.finance`. |
58
+ | `timeout` | Number of seconds to wait for a server response. By default requests do not time out. |
59
+ | `proxies` | Proxy through which the request is queried |
60
+ | `show_limit_usage` | Return response as dictionary including including `"limit_usage"` and `"data"` keys |
61
+ | `show_header` | Return response as dictionary including including `"header"` and `"data"` keys |
62
+
63
+ ### Environment Variables
64
+
65
+ You may use environment variables to configure the DataMaxi+ client to avoid any inline boilerplate.
66
+
67
+ | Env | Description |
68
+ |--------------------|----------------------------------------------|
69
+ | `NEVEREST_API_KEY` | Used instead of `api_key` if none is passed. |
70
+
71
+ ## Quickstart
72
+
73
+ DataMaxi+ Python package currently includes the following clients:
74
+
75
+ * `Binance`
76
+ * `Defillama`
77
+ * `Naver`
78
+ * `Google`
79
+
80
+ All clients accept the same parameters that are described at [Configuration](#configuration) section.
81
+ First, import the clients,
82
+
83
+ ```python
84
+ from datamaxi.binance import Binance
85
+ from datamaxi.defillama import Defillama
86
+ from datamaxi.naver import Naver
87
+ from datamaxi.google import Google
88
+ ```
89
+
90
+ and initialize them.
91
+
92
+ ```python
93
+ binance = Binance(api_key=api_key)
94
+ defillama = Defillama(api_key=api_key)
95
+ naver = Naver(api_key=api_key)
96
+ google = Google(api_key=api_key)
97
+ ```
98
+
99
+ ## Local Development
100
+
101
+ ### Setup
102
+
103
+ 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.
104
+
105
+ ### Testing
106
+
107
+ ```shell
108
+ # In case packages are not installed yet
109
+ pip install -r requirements/requirements-test.txt
110
+
111
+ python -m pytest tests/
112
+ ```
113
+
114
+ ## Links
115
+
116
+ * [DataMaxi+](https://datamaxiplus.com/)
117
+ * [DataMaxi+ API](https://api.neverest.finance/)
118
+ * [DataMaxi+ API Documentation](https://docs.neverest.finance/)
119
+
120
+ ## Contributing
121
+
122
+ We welcome contributions!
123
+ If you discover a bug in this project, please feel free to open an issue to discuss the changes you would like to propose.
124
+
125
+ ## License
126
+
127
+ [MIT License](LICENSE)
@@ -0,0 +1,107 @@
1
+ # DataMaxi+ Python Client
2
+ [![PyPI version](https://img.shields.io/pypi/v/datamaxi)](https://pypi.python.org/pypi/datamaxi)
3
+ [![Python version](https://img.shields.io/pypi/pyversions/datamaxi)](https://www.python.org/downloads/)
4
+ [![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://datamaxi.readthedocs.io/en/stable/)
5
+ [![Code Style](https://img.shields.io/badge/code_style-black-black)](https://black.readthedocs.io/en/stable/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ This is the official implementation of Python client for DataMaxi+ API.
9
+ The package can be used to fetch both historical and latest data using [DataMaxi+ API](https://docs.neverest.finance/).
10
+ This package is compatible with Python v3.8+.
11
+
12
+ * [Installation](#installation)
13
+ * [Configuration](#configuration)
14
+ * [Environment Variables](#environment-variables)
15
+ * [Quickstart](#quickstart)
16
+ * [Local Development](#local-development)
17
+ * [Setup](#setup)
18
+ * [Testing](#testing)
19
+ * [Links](#links)
20
+ * [Contributing](#contributing)
21
+ * [License](#license)
22
+
23
+ ## Installation
24
+
25
+ ```shell
26
+ pip install datamaxi
27
+ ```
28
+
29
+ ## Configuration
30
+
31
+ Access to DataMaxi+ is protected by API Key.
32
+ If you are interested to try DataMaxi+, you can request your API key at [business@bisonai.com](mailto:business@bisonai.com).
33
+
34
+ | Option | Explanation |
35
+ |--------------------|---------------------------------------------------------------------------------------|
36
+ | `api_key` | Your API key |
37
+ | `base_url` | If `base_url` is not provided, it defaults to `api.neverest.finance`. |
38
+ | `timeout` | Number of seconds to wait for a server response. By default requests do not time out. |
39
+ | `proxies` | Proxy through which the request is queried |
40
+ | `show_limit_usage` | Return response as dictionary including including `"limit_usage"` and `"data"` keys |
41
+ | `show_header` | Return response as dictionary including including `"header"` and `"data"` keys |
42
+
43
+ ### Environment Variables
44
+
45
+ You may use environment variables to configure the DataMaxi+ client to avoid any inline boilerplate.
46
+
47
+ | Env | Description |
48
+ |--------------------|----------------------------------------------|
49
+ | `NEVEREST_API_KEY` | Used instead of `api_key` if none is passed. |
50
+
51
+ ## Quickstart
52
+
53
+ DataMaxi+ Python package currently includes the following clients:
54
+
55
+ * `Binance`
56
+ * `Defillama`
57
+ * `Naver`
58
+ * `Google`
59
+
60
+ All clients accept the same parameters that are described at [Configuration](#configuration) section.
61
+ First, import the clients,
62
+
63
+ ```python
64
+ from datamaxi.binance import Binance
65
+ from datamaxi.defillama import Defillama
66
+ from datamaxi.naver import Naver
67
+ from datamaxi.google import Google
68
+ ```
69
+
70
+ and initialize them.
71
+
72
+ ```python
73
+ binance = Binance(api_key=api_key)
74
+ defillama = Defillama(api_key=api_key)
75
+ naver = Naver(api_key=api_key)
76
+ google = Google(api_key=api_key)
77
+ ```
78
+
79
+ ## Local Development
80
+
81
+ ### Setup
82
+
83
+ 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.
84
+
85
+ ### Testing
86
+
87
+ ```shell
88
+ # In case packages are not installed yet
89
+ pip install -r requirements/requirements-test.txt
90
+
91
+ python -m pytest tests/
92
+ ```
93
+
94
+ ## Links
95
+
96
+ * [DataMaxi+](https://datamaxiplus.com/)
97
+ * [DataMaxi+ API](https://api.neverest.finance/)
98
+ * [DataMaxi+ API Documentation](https://docs.neverest.finance/)
99
+
100
+ ## Contributing
101
+
102
+ We welcome contributions!
103
+ If you discover a bug in this project, please feel free to open an issue to discuss the changes you would like to propose.
104
+
105
+ ## License
106
+
107
+ [MIT License](LICENSE)
File without changes
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,144 @@
1
+ import os
2
+ import json
3
+ from json import JSONDecodeError
4
+ import logging
5
+ import requests
6
+ from .__version__ import __version__
7
+ from datamaxi.error import ClientError, ServerError
8
+ from datamaxi.lib.utils import cleanNoneValue
9
+ from datamaxi.lib.utils import encoded_string
10
+
11
+
12
+ class API(object):
13
+ """The base class for all DataMaxi+ Python clients. `api_key` can be set
14
+ as an environment variable `NEVEREST_API_KEY`.
15
+ """
16
+
17
+ def __init__(
18
+ self,
19
+ api_key=None,
20
+ base_url=None,
21
+ timeout=None,
22
+ proxies=None,
23
+ show_limit_usage=False,
24
+ show_header=False,
25
+ ):
26
+ """Client API constructor. `api_key` can be set
27
+ as an environment variable `NEVEREST_API_KEY`.
28
+
29
+ Args:
30
+ api_key (str): The API key for the DataMaxi+ API.
31
+ base_url (str): The base URL for the DataMaxi+ API.
32
+ timeout (int): The timeout for the requests.
33
+ proxies (dict): The proxies for the requests.
34
+ show_limit_usage (bool): Show the limit usage.
35
+ show_header (bool): Show the header.
36
+ """
37
+ self.api_key = api_key or os.environ.get("NEVEREST_API_KEY")
38
+ self.base_url = base_url
39
+ self.timeout = timeout
40
+ self.proxies = None
41
+ self.show_limit_usage = False
42
+ self.show_header = False
43
+
44
+ self.session = requests.Session()
45
+ self.session.headers.update(
46
+ {
47
+ "Content-Type": "application/json;charset=utf-8",
48
+ "User-Agent": "datamaxi/" + __version__,
49
+ "Authorization": "X-NVRST-APIKEY " + str(self.api_key),
50
+ }
51
+ )
52
+
53
+ if show_limit_usage is True:
54
+ self.show_limit_usage = True
55
+
56
+ if show_header is True:
57
+ self.show_header = True
58
+
59
+ if type(proxies) is dict:
60
+ self.proxies = proxies
61
+
62
+ self._logger = logging.getLogger(__name__)
63
+ return
64
+
65
+ def query(self, url_path, payload=None):
66
+ return self.send_request("GET", url_path, payload=payload)
67
+
68
+ def send_request(self, http_method, url_path, payload=None):
69
+ if payload is None:
70
+ payload = {}
71
+ url = self.base_url + url_path
72
+ self._logger.debug("url: " + url)
73
+ params = cleanNoneValue(
74
+ {
75
+ "url": url,
76
+ "params": self._prepare_params(payload),
77
+ "timeout": self.timeout,
78
+ "proxies": self.proxies,
79
+ }
80
+ )
81
+ response = self._dispatch_request(http_method)(**params)
82
+ self._logger.debug("raw response from server:" + response.text)
83
+ self._handle_exception(response)
84
+
85
+ try:
86
+ data = response.json()
87
+ except ValueError:
88
+ data = response.text
89
+ result = {}
90
+
91
+ if self.show_limit_usage:
92
+ limit_usage = {}
93
+ for key in response.headers.keys():
94
+ key = key.lower()
95
+ if (
96
+ key.startswith("x-ratelimit-limit")
97
+ or key.startswith("x-ratelimit-remaining")
98
+ or key.startswith("x-ratelimit-reset")
99
+ ):
100
+ limit_usage[key] = response.headers[key]
101
+ result["limit_usage"] = limit_usage
102
+
103
+ if self.show_header:
104
+ result["header"] = response.headers
105
+
106
+ if len(result) != 0:
107
+ result["data"] = data
108
+ return result
109
+
110
+ return data
111
+
112
+ def _prepare_params(self, params):
113
+ return encoded_string(cleanNoneValue(params))
114
+
115
+ def _dispatch_request(self, http_method):
116
+ return {
117
+ "GET": self.session.get,
118
+ "DELETE": self.session.delete,
119
+ "PUT": self.session.put,
120
+ "POST": self.session.post,
121
+ }.get(http_method, "GET")
122
+
123
+ def _handle_exception(self, response):
124
+ status_code = response.status_code
125
+ if status_code < 400:
126
+ return
127
+ if 400 <= status_code < 500:
128
+ try:
129
+ err = json.loads(response.text)
130
+ except JSONDecodeError:
131
+ raise ClientError(
132
+ status_code, None, response.text, None, response.headers
133
+ )
134
+ error_data = None
135
+ if "data" in err:
136
+ error_data = err["data"]
137
+ raise ClientError(
138
+ status_code,
139
+ err["code"],
140
+ err["msg"],
141
+ response.headers,
142
+ error_data,
143
+ )
144
+ raise ServerError(status_code, response.text)
@@ -0,0 +1,56 @@
1
+ from typing import Any, List, Union
2
+ import pandas as pd
3
+ from datamaxi.api import API
4
+ from datamaxi.lib.utils import check_required_parameters
5
+ from datamaxi.lib.utils import postprocess
6
+ from datamaxi.lib.constants import BASE_URL
7
+
8
+
9
+ class Binance(API):
10
+ """Client to fetch Binance data from DataMaxi+ API."""
11
+
12
+ def __init__(self, api_key=None, **kwargs: Any):
13
+ """Initialize the object.
14
+
15
+ Args:
16
+ api_key (str): The DataMaxi+ API key
17
+ **kwargs: Keyword arguments used by `datamaxi.api.API`.
18
+ """
19
+ if "base_url" not in kwargs:
20
+ kwargs["base_url"] = BASE_URL
21
+ super().__init__(api_key, **kwargs)
22
+
23
+ def symbols(self) -> List[str]:
24
+ """Supported Binance supported symbols
25
+
26
+ `GET /v1/raw/binance/symbols`
27
+
28
+ <https://docs.neverest.finance/cex/binance/symbols>
29
+
30
+ Returns:
31
+ List of supported Binance symbols
32
+ """
33
+ url_path = "/v1/raw/binance/symbols"
34
+ return self.query(url_path)
35
+
36
+ @postprocess()
37
+ def kline(
38
+ self, symbol: str, interval: str = "1d", pandas: bool = True
39
+ ) -> Union[List, pd.DataFrame]:
40
+ """Get Binance k-line data
41
+
42
+ `GET /v1/raw/binance/kline`
43
+
44
+ <https://docs.neverest.finance/cex/binance/kline>
45
+
46
+ Args:
47
+ symbol (str): Binance symbol
48
+ interval (str): Kline interval
49
+ pandas (bool): Return data as pandas DataFrame
50
+
51
+ Returns:
52
+ Binance kline data for a given symbol and interval in pandas DataFrame
53
+ """
54
+ check_required_parameters([[symbol, "symbol"], [interval, "interval"]])
55
+ params = {"symbol": symbol, "interval": interval}
56
+ return self.query("/v1/raw/binance/kline", params)