byteforge-coinmarketcap 2.2__tar.gz → 4.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.
- byteforge_coinmarketcap-4.0/.gitignore +141 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/PKG-INFO +3 -3
- byteforge_coinmarketcap-4.0/coinmarketcap/__init__.py +22 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/core.py +369 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/types/cryptocurrency_info_factory.py +61 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/coinmarketcap/types/dex_info.py +5 -2
- byteforge_coinmarketcap-4.0/coinmarketcap/types/dex_info_factory.py +52 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/types/quote_factory.py +52 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/types/token_info_factory.py +27 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/types/token_state_factory.py +86 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/coinmarketcap/v1/cryptocurrency/listings/common.py +34 -11
- byteforge_coinmarketcap-4.0/coinmarketcap/v1/cryptocurrency/listings/latest.py +72 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/coinmarketcap/v1/cryptocurrency/map.py +21 -17
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/coinmarketcap/v1/key/info.py +15 -8
- byteforge_coinmarketcap-4.0/coinmarketcap/v2/cryptocurrency/info.py +52 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/v2/cryptocurrency/quotes/historical.py +152 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/v3/cryptocurrency/quotes/historical_v3.py +142 -0
- byteforge_coinmarketcap-4.0/coinmarketcap/v3/fear_and_greed/historical.py +19 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/coinmarketcap/v4/dex/listings/info.py +10 -10
- byteforge_coinmarketcap-4.0/dev-requirements.txt +4 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/pyproject.toml +3 -3
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/requirements.txt +1 -4
- byteforge_coinmarketcap-4.0/tests/conftest.py +19 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/tests/test_coinmarketcap.py +106 -30
- byteforge_coinmarketcap-2.2/.gitignore +0 -13
- byteforge_coinmarketcap-2.2/ALL_EXCHANGES.OUT +0 -23142
- byteforge_coinmarketcap-2.2/MANIFEST +0 -6
- byteforge_coinmarketcap-2.2/coinmarketcap/__init__.py +0 -16
- byteforge_coinmarketcap-2.2/coinmarketcap/core.py +0 -285
- byteforge_coinmarketcap-2.2/coinmarketcap/types/dex_info_factory.py +0 -37
- byteforge_coinmarketcap-2.2/coinmarketcap/types/quote_factory.py +0 -43
- byteforge_coinmarketcap-2.2/coinmarketcap/types/token_info_factory.py +0 -20
- byteforge_coinmarketcap-2.2/coinmarketcap/types/token_state_factory.py +0 -49
- byteforge_coinmarketcap-2.2/coinmarketcap/v1/cryptocurrency/listings/latest.py +0 -68
- byteforge_coinmarketcap-2.2/coinmarketcap/v2/cryptocurrency/quotes/historical.py +0 -137
- byteforge_coinmarketcap-2.2/coinmarketcap/v3/cryptocurrency/quotes/historical_v3.py +0 -128
- byteforge_coinmarketcap-2.2/coinmarketcap/v3/fear_and_greed/historical.py +0 -25
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/.github/FUNDING.yml +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/LICENSE +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/README.md +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/coinmarketcap/types/__init__.py +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/coinmarketcap/v1/key/__init__.py +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/doc/coinmarketcap.png +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/doc/coinmarketcap_original.png +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/tests/__init__.py +0 -0
- {byteforge_coinmarketcap-2.2 → byteforge_coinmarketcap-4.0}/tests/test_dex.py +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Project-specific (kept local to each developer)
|
|
2
|
+
CLAUDE.md
|
|
3
|
+
.claude
|
|
4
|
+
.mcp.json
|
|
5
|
+
main.py
|
|
6
|
+
build_publish.sh
|
|
7
|
+
dev_scripts
|
|
8
|
+
|
|
9
|
+
# Byte-compiled / optimized / DLL files
|
|
10
|
+
__pycache__/
|
|
11
|
+
*.py[cod]
|
|
12
|
+
*$py.class
|
|
13
|
+
|
|
14
|
+
# C extensions
|
|
15
|
+
*.so
|
|
16
|
+
|
|
17
|
+
# Distribution / packaging
|
|
18
|
+
.Python
|
|
19
|
+
build/
|
|
20
|
+
develop-eggs/
|
|
21
|
+
dist/
|
|
22
|
+
downloads/
|
|
23
|
+
eggs/
|
|
24
|
+
.eggs/
|
|
25
|
+
lib/
|
|
26
|
+
lib64/
|
|
27
|
+
parts/
|
|
28
|
+
sdist/
|
|
29
|
+
var/
|
|
30
|
+
wheels/
|
|
31
|
+
pip-wheel-metadata/
|
|
32
|
+
share/python-wheels/
|
|
33
|
+
*.egg-info/
|
|
34
|
+
.installed.cfg
|
|
35
|
+
*.egg
|
|
36
|
+
MANIFEST
|
|
37
|
+
|
|
38
|
+
# PyInstaller
|
|
39
|
+
*.manifest
|
|
40
|
+
*.spec
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py,cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
|
|
56
|
+
# Translations
|
|
57
|
+
*.mo
|
|
58
|
+
*.pot
|
|
59
|
+
|
|
60
|
+
# Django stuff:
|
|
61
|
+
*.log
|
|
62
|
+
local_settings.py
|
|
63
|
+
db.sqlite3
|
|
64
|
+
db.sqlite3-journal
|
|
65
|
+
|
|
66
|
+
# Flask stuff:
|
|
67
|
+
instance/
|
|
68
|
+
.webassets-cache
|
|
69
|
+
|
|
70
|
+
# Scrapy stuff:
|
|
71
|
+
.scrapy
|
|
72
|
+
|
|
73
|
+
# Sphinx documentation
|
|
74
|
+
docs/_build/
|
|
75
|
+
|
|
76
|
+
# PyBuilder
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
.python-version
|
|
88
|
+
|
|
89
|
+
# pipenv
|
|
90
|
+
Pipfile.lock
|
|
91
|
+
|
|
92
|
+
# PEP 582
|
|
93
|
+
__pypackages__/
|
|
94
|
+
|
|
95
|
+
# Celery stuff
|
|
96
|
+
celerybeat-schedule
|
|
97
|
+
celerybeat.pid
|
|
98
|
+
|
|
99
|
+
# SageMath parsed files
|
|
100
|
+
*.sage.py
|
|
101
|
+
|
|
102
|
+
# Environments
|
|
103
|
+
.env
|
|
104
|
+
.venv
|
|
105
|
+
env/
|
|
106
|
+
venv/
|
|
107
|
+
ENV/
|
|
108
|
+
env.bak/
|
|
109
|
+
venv.bak/
|
|
110
|
+
bin/
|
|
111
|
+
include/
|
|
112
|
+
pyvenv.cfg
|
|
113
|
+
|
|
114
|
+
# requests-cache / sqlite
|
|
115
|
+
*.sqlite
|
|
116
|
+
|
|
117
|
+
# Spyder project settings
|
|
118
|
+
.spyderproject
|
|
119
|
+
.spyproject
|
|
120
|
+
|
|
121
|
+
# Rope project settings
|
|
122
|
+
.ropeproject
|
|
123
|
+
|
|
124
|
+
# mkdocs documentation
|
|
125
|
+
/site
|
|
126
|
+
|
|
127
|
+
# mypy
|
|
128
|
+
.mypy_cache/
|
|
129
|
+
.dmypy.json
|
|
130
|
+
dmypy.json
|
|
131
|
+
|
|
132
|
+
# Pyre type checker
|
|
133
|
+
.pyre/
|
|
134
|
+
|
|
135
|
+
# IDEs
|
|
136
|
+
.vscode/
|
|
137
|
+
.idea/
|
|
138
|
+
*.swp
|
|
139
|
+
*.swo
|
|
140
|
+
*~
|
|
141
|
+
.DS_Store
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: byteforge-coinmarketcap
|
|
3
|
-
Version:
|
|
3
|
+
Version: 4.0
|
|
4
4
|
Summary: Python SDK for the coinmarketcap.com API.
|
|
5
5
|
Project-URL: Homepage, https://github.com/jmazzahacks/byteforge-coinmarketcap/
|
|
6
6
|
Project-URL: Issues, https://github.com/jmazzahacks/byteforge-coinmarketcap/issues
|
|
@@ -208,11 +208,11 @@ License: Apache License
|
|
|
208
208
|
limitations under the License.
|
|
209
209
|
License-File: LICENSE
|
|
210
210
|
Keywords: API,BTC,Bitcoin,ETH,Ethereum,LTC,Litecoin,Ripple,XRP,coinmarketcap,cryptocurrency
|
|
211
|
-
Classifier: License :: OSI Approved ::
|
|
211
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
212
212
|
Classifier: Operating System :: OS Independent
|
|
213
213
|
Classifier: Programming Language :: Python :: 3
|
|
214
214
|
Requires-Python: >=3.8
|
|
215
|
-
Requires-Dist: byteforge-crypto-commons>=0.
|
|
215
|
+
Requires-Dist: byteforge-crypto-commons>=0.5
|
|
216
216
|
Requires-Dist: python-dateutil
|
|
217
217
|
Requires-Dist: requests
|
|
218
218
|
Requires-Dist: requests-cache
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
5
|
+
|
|
6
|
+
__title__ = "coinmarketcap"
|
|
7
|
+
__author__ = "Jason Byteforge"
|
|
8
|
+
__repo__ = "https://github.com/jmazzahacks/byteforge-coinmarketcap"
|
|
9
|
+
__license__ = "Apache License 2.0"
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
__version__ = version("byteforge-coinmarketcap")
|
|
13
|
+
except PackageNotFoundError:
|
|
14
|
+
__version__ = "unknown"
|
|
15
|
+
|
|
16
|
+
from .core import Market
|
|
17
|
+
from .core import ServerException
|
|
18
|
+
from .core import MalformedResponseError
|
|
19
|
+
from .core import SortOption
|
|
20
|
+
from .core import SortDir
|
|
21
|
+
from .core import FilterOptions
|
|
22
|
+
from .core import AuxFields
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import json
|
|
3
|
+
import logging
|
|
4
|
+
import requests
|
|
5
|
+
import tempfile
|
|
6
|
+
import time
|
|
7
|
+
import requests_cache
|
|
8
|
+
from typing import Optional, List, Dict, Union
|
|
9
|
+
|
|
10
|
+
from requests_ratelimiter import LimiterAdapter
|
|
11
|
+
|
|
12
|
+
from .v1.cryptocurrency.map import ListingStatus
|
|
13
|
+
from crypto_commons.types.token_state import TokenState
|
|
14
|
+
from crypto_commons.types.token_info import TokenInfo
|
|
15
|
+
from crypto_commons.types.cryptocurrency_info import CryptocurrencyInfo
|
|
16
|
+
from .v2.cryptocurrency.quotes.historical import _quotes_historical_v2
|
|
17
|
+
from .v2.cryptocurrency.info import _cryptocurrency_info
|
|
18
|
+
from .v3.cryptocurrency.quotes.historical_v3 import _quotes_historical_v3
|
|
19
|
+
from .v1.cryptocurrency.listings.latest import _listings_latest
|
|
20
|
+
from .v1.cryptocurrency.listings.common import (
|
|
21
|
+
SortOption,
|
|
22
|
+
AuxFields,
|
|
23
|
+
SortDir,
|
|
24
|
+
FilterOptions,
|
|
25
|
+
)
|
|
26
|
+
from .v1.key.info import _key_info
|
|
27
|
+
from .v1.key.info import _safe_daily_call_limit
|
|
28
|
+
from .v1.cryptocurrency.map import _map, MapSortOption, MapAuxFields
|
|
29
|
+
from .v3.fear_and_greed.historical import _fear_and_greed_historical
|
|
30
|
+
from .v4.dex.listings.info import _dex_listings_info, DexAuxFields
|
|
31
|
+
from .types.dex_info import DexInfo, DexUrls
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ServerException(Exception):
|
|
35
|
+
def __init__(self, status_code: int, message: str):
|
|
36
|
+
self.status_code = status_code
|
|
37
|
+
self.message = message
|
|
38
|
+
super().__init__(f"Server returned {status_code} - {message}")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class MalformedResponseError(Exception):
|
|
42
|
+
def __init__(self, endpoint: str, message: str, raw_body: str = ""):
|
|
43
|
+
self.endpoint = endpoint
|
|
44
|
+
self.raw_body = raw_body
|
|
45
|
+
super().__init__(f"Malformed response from {endpoint}: {message}")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Market(object):
|
|
49
|
+
|
|
50
|
+
_session = None
|
|
51
|
+
_caching_session = None
|
|
52
|
+
_debug_mode = False
|
|
53
|
+
_api_key = None
|
|
54
|
+
_limiter = None
|
|
55
|
+
__DEFAULT_BASE_URL = "https://pro-api.coinmarketcap.com/"
|
|
56
|
+
__DEFAULT_TIMEOUT = 30
|
|
57
|
+
__TEMPDIR_CACHE = True
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
api_key=None,
|
|
62
|
+
base_url=__DEFAULT_BASE_URL,
|
|
63
|
+
request_timeout=__DEFAULT_TIMEOUT,
|
|
64
|
+
tempdir_cache=__TEMPDIR_CACHE,
|
|
65
|
+
rate_limit_per_minute=-1,
|
|
66
|
+
debug_mode=False,
|
|
67
|
+
):
|
|
68
|
+
|
|
69
|
+
self._api_key = api_key
|
|
70
|
+
self.base_url = base_url
|
|
71
|
+
self.request_timeout = request_timeout
|
|
72
|
+
self._debug_mode = debug_mode
|
|
73
|
+
self.cache_filename = "coinmarketcap_cache"
|
|
74
|
+
self.cache_name = (
|
|
75
|
+
os.path.join(tempfile.gettempdir(), self.cache_filename)
|
|
76
|
+
if tempdir_cache
|
|
77
|
+
else self.cache_filename
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
if not self._api_key:
|
|
81
|
+
raise ValueError(
|
|
82
|
+
"An API key is required for using the coinmarketcap API. Please visit https://pro.coinmarketcap.com/signup/ for more information."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
if rate_limit_per_minute > 0:
|
|
86
|
+
self._limiter = LimiterAdapter(per_minute=rate_limit_per_minute)
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def caching_session(self):
|
|
90
|
+
if not self._caching_session:
|
|
91
|
+
# define a a session with caching
|
|
92
|
+
self._caching_session = requests_cache.CachedSession(
|
|
93
|
+
cache_name=self.cache_name, backend="sqlite", expire_after=120
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
if self._limiter:
|
|
97
|
+
self._caching_session.mount("https://", self._limiter)
|
|
98
|
+
|
|
99
|
+
self._caching_session.headers.update(
|
|
100
|
+
{
|
|
101
|
+
"Accept": "application/json",
|
|
102
|
+
"X-CMC_PRO_API_KEY": self._api_key,
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
return self._caching_session
|
|
107
|
+
|
|
108
|
+
@property
|
|
109
|
+
def session(self):
|
|
110
|
+
if not self._session:
|
|
111
|
+
|
|
112
|
+
# and a normal (non-caching) session
|
|
113
|
+
self._session = requests.Session()
|
|
114
|
+
|
|
115
|
+
self._session.headers.update(
|
|
116
|
+
{
|
|
117
|
+
"Accept": "application/json",
|
|
118
|
+
"X-CMC_PRO_API_KEY": self._api_key,
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
if self._limiter:
|
|
123
|
+
self._session.mount("https://", self._limiter)
|
|
124
|
+
|
|
125
|
+
return self._session
|
|
126
|
+
|
|
127
|
+
def _request(self, endpoint, params=None, no_cache=False):
|
|
128
|
+
if params is None:
|
|
129
|
+
params = {}
|
|
130
|
+
url = self.base_url.rstrip("/") + "/" + endpoint.lstrip("/")
|
|
131
|
+
|
|
132
|
+
if self._debug_mode:
|
|
133
|
+
print("Request URL: " + url)
|
|
134
|
+
if params:
|
|
135
|
+
print("Request Payload:\n" + json.dumps(params, indent=4))
|
|
136
|
+
|
|
137
|
+
if no_cache:
|
|
138
|
+
response_object = self.session.get(
|
|
139
|
+
url, params=params, timeout=self.request_timeout
|
|
140
|
+
)
|
|
141
|
+
else:
|
|
142
|
+
response_object = self.caching_session.get(
|
|
143
|
+
url, params=params, timeout=self.request_timeout
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
if self._debug_mode:
|
|
147
|
+
print("Response Code: " + str(response_object.status_code))
|
|
148
|
+
if hasattr(response_object, "from_cache"):
|
|
149
|
+
print("From Cache?: " + str(response_object.from_cache))
|
|
150
|
+
|
|
151
|
+
if response_object.status_code != requests.codes.ok:
|
|
152
|
+
raise ServerException(response_object.status_code, response_object.text)
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
response_json = response_object.json()
|
|
156
|
+
except (json.JSONDecodeError, ValueError):
|
|
157
|
+
logging.error(
|
|
158
|
+
"Non-JSON response from %s: %s", endpoint, response_object.text[:500]
|
|
159
|
+
)
|
|
160
|
+
raise MalformedResponseError(
|
|
161
|
+
endpoint, "Response is not valid JSON", response_object.text[:500]
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
if self._debug_mode:
|
|
165
|
+
print("Response Payload:\n" + json.dumps(response_json, indent=4))
|
|
166
|
+
|
|
167
|
+
if "data" not in response_json:
|
|
168
|
+
logging.warning(
|
|
169
|
+
"Response from %s missing 'data' key: %s",
|
|
170
|
+
endpoint,
|
|
171
|
+
json.dumps(response_json)[:500],
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
return response_json
|
|
175
|
+
|
|
176
|
+
def fear_and_greed_historical(
|
|
177
|
+
self, start: int, limit: int
|
|
178
|
+
) -> List[Dict[str, Union[str, int]]]:
|
|
179
|
+
"""
|
|
180
|
+
Retrieves historical fear and greed index data from the CoinMarketCap API.
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
List[Dict[str, Union[str, int]]]: A list of dictionaries containing:
|
|
184
|
+
- timestamp (str): Unix timestamp of the measurement
|
|
185
|
+
- value (int): The fear and greed index value (0-100)
|
|
186
|
+
- value_classification (str): Classification of the value (e.g., 'Greed', 'Fear', etc.)
|
|
187
|
+
"""
|
|
188
|
+
return _fear_and_greed_historical(self, start, limit)
|
|
189
|
+
|
|
190
|
+
def map(
|
|
191
|
+
self,
|
|
192
|
+
listing_status: ListingStatus = ListingStatus.ACTIVE,
|
|
193
|
+
start: int = 1,
|
|
194
|
+
limit: int = 100,
|
|
195
|
+
symbols: List[str] = None,
|
|
196
|
+
sort: MapSortOption = MapSortOption.ID,
|
|
197
|
+
aux_fields: List[MapAuxFields] = None,
|
|
198
|
+
) -> List[TokenInfo]:
|
|
199
|
+
"""Returns a mapping of all cryptocurrencies to their CoinMarketCap IDs.
|
|
200
|
+
|
|
201
|
+
This method provides a mapping of all cryptocurrencies to their CoinMarketCap IDs,
|
|
202
|
+
which can be used to make other API calls. The mapping includes basic information
|
|
203
|
+
about each cryptocurrency.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
listing_status (ListingStatus, optional): Filter by listing status.
|
|
207
|
+
Can be ACTIVE, INACTIVE, or UNTRACKED. Defaults to ACTIVE.
|
|
208
|
+
start (int, optional): Starting point for pagination. Defaults to 1.
|
|
209
|
+
limit (int, optional): Number of results to return. Defaults to 100.
|
|
210
|
+
symbols (List[str], optional): List of cryptocurrency symbols to filter by.
|
|
211
|
+
If None, returns all cryptocurrencies. Defaults to None.
|
|
212
|
+
sort (MapSortOption, optional): Field to sort results by. Can be ID or CMC_RANK.
|
|
213
|
+
Defaults to ID.
|
|
214
|
+
aux_fields (List[MapAuxFields], optional): Additional fields to include in response.
|
|
215
|
+
Can include PLATFORM, FIRST_HISTORICAL_DATA, LAST_HISTORICAL_DATA, IS_ACTIVE.
|
|
216
|
+
Defaults to None.
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
List[TokenInfo]: List of TokenInfo objects containing cryptocurrency mapping data.
|
|
220
|
+
|
|
221
|
+
Raises:
|
|
222
|
+
ServerException: If the API request fails.
|
|
223
|
+
"""
|
|
224
|
+
|
|
225
|
+
return _map(self, listing_status, start, limit, symbols, sort, aux_fields)
|
|
226
|
+
|
|
227
|
+
def quotes_historical(
|
|
228
|
+
self,
|
|
229
|
+
id: Optional[str] = None,
|
|
230
|
+
ticker: Optional[str] = None,
|
|
231
|
+
timestamp_start: Optional[int] = None,
|
|
232
|
+
timestamp_end: Optional[int] = None,
|
|
233
|
+
interval: str = "hourly",
|
|
234
|
+
convert: Optional[List[str]] = None,
|
|
235
|
+
) -> List[TokenState]:
|
|
236
|
+
# Resolve time-window defaults at call time, not import time.
|
|
237
|
+
now = int(time.time())
|
|
238
|
+
if timestamp_end is None:
|
|
239
|
+
timestamp_end = now
|
|
240
|
+
if timestamp_start is None:
|
|
241
|
+
timestamp_start = timestamp_end - 60 * 60 * 24
|
|
242
|
+
if convert is None:
|
|
243
|
+
convert = ["USD"]
|
|
244
|
+
|
|
245
|
+
return _quotes_historical_v2(
|
|
246
|
+
self,
|
|
247
|
+
id=id,
|
|
248
|
+
ticker=ticker,
|
|
249
|
+
timestamp_start=timestamp_start,
|
|
250
|
+
timestamp_end=timestamp_end,
|
|
251
|
+
interval=interval,
|
|
252
|
+
convert=convert,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
def quotes_historical_v3(
|
|
256
|
+
self,
|
|
257
|
+
id: Optional[str] = None,
|
|
258
|
+
ticker: Optional[str] = None,
|
|
259
|
+
timestamp_start: Optional[int] = None,
|
|
260
|
+
timestamp_end: Optional[int] = None,
|
|
261
|
+
interval: str = "hourly",
|
|
262
|
+
convert: Optional[List[str]] = None,
|
|
263
|
+
) -> List[TokenState]:
|
|
264
|
+
# Resolve time-window defaults at call time, not import time.
|
|
265
|
+
now = int(time.time())
|
|
266
|
+
if timestamp_end is None:
|
|
267
|
+
timestamp_end = now
|
|
268
|
+
if timestamp_start is None:
|
|
269
|
+
timestamp_start = timestamp_end - 60 * 60 * 24
|
|
270
|
+
if convert is None:
|
|
271
|
+
convert = ["USD"]
|
|
272
|
+
|
|
273
|
+
return _quotes_historical_v3(
|
|
274
|
+
self,
|
|
275
|
+
id=id,
|
|
276
|
+
ticker=ticker,
|
|
277
|
+
timestamp_start=timestamp_start,
|
|
278
|
+
timestamp_end=timestamp_end,
|
|
279
|
+
interval=interval,
|
|
280
|
+
convert=convert,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
def listings_latest(
|
|
284
|
+
self,
|
|
285
|
+
sort_by: SortOption = SortOption.MARKET_CAP,
|
|
286
|
+
sort_dir: SortDir = SortDir.DESC,
|
|
287
|
+
start: int = 1,
|
|
288
|
+
limit: int = 100,
|
|
289
|
+
convert: Optional[List[str]] = None,
|
|
290
|
+
aux_fields: AuxFields = None,
|
|
291
|
+
filters: FilterOptions = None,
|
|
292
|
+
) -> List[TokenState]:
|
|
293
|
+
if convert is None:
|
|
294
|
+
convert = ["USD"]
|
|
295
|
+
return _listings_latest(
|
|
296
|
+
self, sort_by, sort_dir, start, limit, convert, aux_fields, filters
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
def safe_daily_call_limit(self):
|
|
300
|
+
"""
|
|
301
|
+
Calculates how many API calls are left for today, based on the service plan's monthly call limit.
|
|
302
|
+
|
|
303
|
+
This function takes the user's API call limit and subtracts the number of calls used to date,
|
|
304
|
+
providing a simple ratio to estimate daily available calls until the reset date. Note that
|
|
305
|
+
this is an approximation based on equal usage each day until the reset.
|
|
306
|
+
|
|
307
|
+
Parameters:
|
|
308
|
+
market (Market): An instance of the Market class, which handles the API communications.
|
|
309
|
+
|
|
310
|
+
Returns:
|
|
311
|
+
int: Approximate number of API calls left for the current day, based on daily usage
|
|
312
|
+
till the reset date and a monthly limit.
|
|
313
|
+
"""
|
|
314
|
+
return _safe_daily_call_limit(self)
|
|
315
|
+
|
|
316
|
+
def cryptocurrency_info(
|
|
317
|
+
self,
|
|
318
|
+
ids: Optional[List[int]] = None,
|
|
319
|
+
slugs: Optional[List[str]] = None,
|
|
320
|
+
aux: Optional[List[str]] = None,
|
|
321
|
+
) -> Dict[int, CryptocurrencyInfo]:
|
|
322
|
+
"""Fetch rich token metadata from CMC's /v2/cryptocurrency/info endpoint.
|
|
323
|
+
|
|
324
|
+
Returns a dict keyed by CMC ID, with CryptocurrencyInfo values containing
|
|
325
|
+
name, symbol, slug, description, logo, tags, platform (with on-chain
|
|
326
|
+
contract address for cross-chain tokens), and URLs. Exactly one of
|
|
327
|
+
(ids, slugs) must be provided; both batch up to 100 items per call.
|
|
328
|
+
See _cryptocurrency_info for full docs.
|
|
329
|
+
"""
|
|
330
|
+
return _cryptocurrency_info(self, ids=ids, slugs=slugs, aux=aux)
|
|
331
|
+
|
|
332
|
+
def dex_listings_info(
|
|
333
|
+
self,
|
|
334
|
+
ids: Union[int, List[int]],
|
|
335
|
+
aux_fields: Optional[List[DexAuxFields]] = None,
|
|
336
|
+
) -> List[DexInfo]:
|
|
337
|
+
"""
|
|
338
|
+
Get information about specific DEX (Decentralized Exchanges) by their IDs.
|
|
339
|
+
|
|
340
|
+
This method retrieves detailed information about specific decentralized exchanges
|
|
341
|
+
from the CoinMarketCap API. Unlike other listings endpoints, this requires specific
|
|
342
|
+
DEX IDs and does not support pagination, sorting, or filtering.
|
|
343
|
+
|
|
344
|
+
Args:
|
|
345
|
+
ids (Union[int, List[int]]): Single DEX ID or list of DEX IDs to retrieve
|
|
346
|
+
information for. At least one ID is required.
|
|
347
|
+
aux_fields (List[DexAuxFields], optional): Additional fields to include in response.
|
|
348
|
+
Can include URLS, LOGO, DESCRIPTION, DATE_LAUNCHED, NOTICE.
|
|
349
|
+
Defaults to None (returns only basic fields: id, name, slug, status).
|
|
350
|
+
|
|
351
|
+
Returns:
|
|
352
|
+
List[DexInfo]: List of DexInfo objects containing DEX information including
|
|
353
|
+
ID, name, slug, status, and any requested auxiliary fields.
|
|
354
|
+
|
|
355
|
+
Raises:
|
|
356
|
+
ValueError: If no IDs are provided.
|
|
357
|
+
ServerException: If the API request fails.
|
|
358
|
+
|
|
359
|
+
Example:
|
|
360
|
+
# Get info for a single DEX with all auxiliary fields
|
|
361
|
+
dex_info = market.dex_listings_info(
|
|
362
|
+
ids=11955,
|
|
363
|
+
aux_fields=[DexAuxFields.URLS, DexAuxFields.LOGO, DexAuxFields.DESCRIPTION]
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
# Get info for multiple DEXs
|
|
367
|
+
dex_info = market.dex_listings_info(ids=[11955, 12345])
|
|
368
|
+
"""
|
|
369
|
+
return _dex_listings_info(self, ids, aux_fields)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from typing import Any, Dict, Optional
|
|
2
|
+
from dateutil import parser
|
|
3
|
+
|
|
4
|
+
from crypto_commons.types.cryptocurrency_info import CryptocurrencyInfo
|
|
5
|
+
from crypto_commons.types.cryptocurrency_platform import CryptocurrencyPlatform
|
|
6
|
+
from crypto_commons.types.cryptocurrency_urls import CryptocurrencyUrls
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _iso_to_unix(value: Optional[str]) -> Optional[int]:
|
|
10
|
+
if value is None:
|
|
11
|
+
return None
|
|
12
|
+
return int(parser.parse(value).timestamp())
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CryptocurrencyInfoFactory:
|
|
16
|
+
"""Builds CryptocurrencyInfo dataclasses from raw CMC API payloads."""
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def from_dict(data: Dict[str, Any]) -> CryptocurrencyInfo:
|
|
20
|
+
platform = None
|
|
21
|
+
platform_data = data.get("platform")
|
|
22
|
+
if platform_data is not None:
|
|
23
|
+
platform = CryptocurrencyPlatform(
|
|
24
|
+
id=int(platform_data["id"]),
|
|
25
|
+
name=platform_data["name"],
|
|
26
|
+
symbol=platform_data["symbol"],
|
|
27
|
+
slug=platform_data["slug"],
|
|
28
|
+
token_address=platform_data["token_address"],
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
urls = None
|
|
32
|
+
urls_data = data.get("urls")
|
|
33
|
+
if urls_data is not None:
|
|
34
|
+
urls = CryptocurrencyUrls(
|
|
35
|
+
website=urls_data.get("website") or [],
|
|
36
|
+
technical_doc=urls_data.get("technical_doc") or [],
|
|
37
|
+
explorer=urls_data.get("explorer") or [],
|
|
38
|
+
source_code=urls_data.get("source_code") or [],
|
|
39
|
+
message_board=urls_data.get("message_board") or [],
|
|
40
|
+
chat=urls_data.get("chat") or [],
|
|
41
|
+
announcement=urls_data.get("announcement") or [],
|
|
42
|
+
reddit=urls_data.get("reddit") or [],
|
|
43
|
+
twitter=urls_data.get("twitter") or [],
|
|
44
|
+
facebook=urls_data.get("facebook") or [],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
return CryptocurrencyInfo(
|
|
48
|
+
id=int(data["id"]),
|
|
49
|
+
name=data["name"],
|
|
50
|
+
symbol=data["symbol"],
|
|
51
|
+
slug=data["slug"],
|
|
52
|
+
description=data.get("description"),
|
|
53
|
+
category=data.get("category"),
|
|
54
|
+
logo=data.get("logo"),
|
|
55
|
+
date_added=_iso_to_unix(data.get("date_added")),
|
|
56
|
+
date_launched=_iso_to_unix(data.get("date_launched")),
|
|
57
|
+
notice=data.get("notice"),
|
|
58
|
+
tags=data.get("tags") or [],
|
|
59
|
+
platform=platform,
|
|
60
|
+
urls=urls,
|
|
61
|
+
)
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
2
|
from typing import Optional, Dict, List
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@dataclass
|
|
5
6
|
class DexUrls:
|
|
6
7
|
"""URLs associated with a DEX"""
|
|
8
|
+
|
|
7
9
|
website: Optional[List[str]] = None
|
|
8
10
|
twitter: Optional[List[str]] = None
|
|
9
11
|
blog: Optional[List[str]] = None
|
|
@@ -18,6 +20,7 @@ class DexUrls:
|
|
|
18
20
|
self.chat = self.chat or []
|
|
19
21
|
self.fee = self.fee or []
|
|
20
22
|
|
|
23
|
+
|
|
21
24
|
@dataclass
|
|
22
25
|
class DexInfo:
|
|
23
26
|
"""Data model for DEX (Decentralized Exchange) information"""
|
|
@@ -27,7 +30,7 @@ class DexInfo:
|
|
|
27
30
|
slug: str
|
|
28
31
|
logo: Optional[str] = None
|
|
29
32
|
description: Optional[str] = None
|
|
30
|
-
date_launched: Optional[
|
|
33
|
+
date_launched: Optional[int] = None # unix timestamp
|
|
31
34
|
notice: Optional[str] = None
|
|
32
35
|
status: Optional[str] = None
|
|
33
36
|
urls: Optional[DexUrls] = None
|
|
@@ -36,4 +39,4 @@ class DexInfo:
|
|
|
36
39
|
def __post_init__(self):
|
|
37
40
|
"""Post-initialization processing"""
|
|
38
41
|
if self.urls is None:
|
|
39
|
-
self.urls = DexUrls()
|
|
42
|
+
self.urls = DexUrls()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
import time
|
|
3
|
+
from dateutil import parser
|
|
4
|
+
from .dex_info import DexInfo, DexUrls
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DexInfoFactory:
|
|
8
|
+
@staticmethod
|
|
9
|
+
def from_dict(data: Dict) -> DexInfo:
|
|
10
|
+
"""
|
|
11
|
+
Create a DexInfo instance from API response dictionary
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
data: Dictionary containing DEX information from API response
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
DexInfo instance
|
|
18
|
+
"""
|
|
19
|
+
data = data.copy()
|
|
20
|
+
|
|
21
|
+
# Add timestamp if not present
|
|
22
|
+
if "timestamp" not in data:
|
|
23
|
+
data["timestamp"] = int(time.time())
|
|
24
|
+
|
|
25
|
+
# Convert date_launched from ISO 8601 string to unix int, matching
|
|
26
|
+
# the rest of the SDK's date-field convention.
|
|
27
|
+
if "date_launched" in data and isinstance(data["date_launched"], str):
|
|
28
|
+
data["date_launched"] = int(parser.parse(data["date_launched"]).timestamp())
|
|
29
|
+
|
|
30
|
+
# Process URLs if present
|
|
31
|
+
if "urls" in data and isinstance(data["urls"], dict):
|
|
32
|
+
urls_dict = data.pop("urls")
|
|
33
|
+
data["urls"] = DexUrls(**urls_dict)
|
|
34
|
+
|
|
35
|
+
# Remove any fields not in the DexInfo model
|
|
36
|
+
valid_fields = {
|
|
37
|
+
"id",
|
|
38
|
+
"name",
|
|
39
|
+
"slug",
|
|
40
|
+
"logo",
|
|
41
|
+
"description",
|
|
42
|
+
"date_launched",
|
|
43
|
+
"notice",
|
|
44
|
+
"status",
|
|
45
|
+
"urls",
|
|
46
|
+
"timestamp",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
# Filter out any extra fields from API response
|
|
50
|
+
filtered_data = {k: v for k, v in data.items() if k in valid_fields}
|
|
51
|
+
|
|
52
|
+
return DexInfo(**filtered_data)
|