byteforge-coinmarketcap 2.1__tar.gz → 2.2__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-2.1 → byteforge_coinmarketcap-2.2}/PKG-INFO +1 -1
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/__init__.py +1 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/core.py +34 -18
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/quote_factory.py +6 -1
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/token_info_factory.py +1 -1
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/pyproject.toml +1 -1
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/.github/FUNDING.yml +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/.gitignore +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/ALL_EXCHANGES.OUT +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/LICENSE +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/MANIFEST +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/README.md +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/__init__.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/dex_info.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/dex_info_factory.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/token_state_factory.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v1/cryptocurrency/listings/common.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v1/cryptocurrency/listings/latest.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v1/cryptocurrency/map.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v1/key/__init__.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v1/key/info.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v2/cryptocurrency/quotes/historical.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v3/cryptocurrency/quotes/historical_v3.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v3/fear_and_greed/historical.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v4/dex/listings/info.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/doc/coinmarketcap.png +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/doc/coinmarketcap_original.png +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/requirements.txt +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/tests/__init__.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/tests/test_coinmarketcap.py +0 -0
- {byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/tests/test_dex.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: byteforge-coinmarketcap
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2
|
|
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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
3
|
import json
|
|
4
|
+
import logging
|
|
4
5
|
import requests
|
|
5
6
|
import tempfile
|
|
6
7
|
import time
|
|
@@ -24,12 +25,19 @@ from .v4.dex.listings.info import _dex_listings_info, DexAuxFields
|
|
|
24
25
|
from .types.dex_info import DexInfo, DexUrls
|
|
25
26
|
|
|
26
27
|
class ServerException(Exception):
|
|
27
|
-
def __init__(self, status_code, message):
|
|
28
|
+
def __init__(self, status_code: int, message: str):
|
|
28
29
|
self.status_code = status_code
|
|
29
30
|
self.message = message
|
|
30
31
|
super().__init__(f"Server returned {status_code} - {message}")
|
|
31
32
|
|
|
32
33
|
|
|
34
|
+
class MalformedResponseError(Exception):
|
|
35
|
+
def __init__(self, endpoint: str, message: str, raw_body: str = ""):
|
|
36
|
+
self.endpoint = endpoint
|
|
37
|
+
self.raw_body = raw_body
|
|
38
|
+
super().__init__(f"Malformed response from {endpoint}: {message}")
|
|
39
|
+
|
|
40
|
+
|
|
33
41
|
class Market(object):
|
|
34
42
|
|
|
35
43
|
_session = None
|
|
@@ -104,24 +112,32 @@ class Market(object):
|
|
|
104
112
|
if params:
|
|
105
113
|
print("Request Payload:\n" + json.dumps(params, indent=4))
|
|
106
114
|
|
|
115
|
+
if no_cache:
|
|
116
|
+
response_object = self.session.get(self.base_url + endpoint, params=params, timeout=self.request_timeout)
|
|
117
|
+
else:
|
|
118
|
+
response_object = self.caching_session.get(self.base_url + endpoint, params=params, timeout=self.request_timeout)
|
|
119
|
+
|
|
120
|
+
if self._debug_mode:
|
|
121
|
+
print('Response Code: ' + str(response_object.status_code))
|
|
122
|
+
if hasattr(response_object, 'from_cache'):
|
|
123
|
+
print('From Cache?: ' + str(response_object.from_cache))
|
|
124
|
+
|
|
125
|
+
if response_object.status_code != requests.codes.ok:
|
|
126
|
+
raise ServerException(response_object.status_code, response_object.text)
|
|
127
|
+
|
|
107
128
|
try:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return response_object.json()
|
|
121
|
-
else:
|
|
122
|
-
raise ServerException(response_object.status_code, response_object.text)
|
|
123
|
-
except Exception as e:
|
|
124
|
-
raise e
|
|
129
|
+
response_json = response_object.json()
|
|
130
|
+
except (json.JSONDecodeError, ValueError):
|
|
131
|
+
logging.error("Non-JSON response from %s: %s", endpoint, response_object.text[:500])
|
|
132
|
+
raise MalformedResponseError(endpoint, "Response is not valid JSON", response_object.text[:500])
|
|
133
|
+
|
|
134
|
+
if self._debug_mode:
|
|
135
|
+
print("Response Payload:\n" + json.dumps(response_json, indent=4))
|
|
136
|
+
|
|
137
|
+
if 'data' not in response_json:
|
|
138
|
+
logging.warning("Response from %s missing 'data' key: %s", endpoint, json.dumps(response_json)[:500])
|
|
139
|
+
|
|
140
|
+
return response_json
|
|
125
141
|
|
|
126
142
|
def fear_and_greed_historical(self, start: int, limit: int) -> List[Dict[str, Union[str, int]]]:
|
|
127
143
|
"""
|
{byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/quote_factory.py
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from typing import Dict
|
|
2
|
+
import dataclasses
|
|
2
3
|
import json
|
|
3
4
|
import logging
|
|
4
5
|
from dateutil import parser
|
|
@@ -35,4 +36,8 @@ class QuoteFactory:
|
|
|
35
36
|
|
|
36
37
|
last_updated = parser.parse(last_updated_str)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
# Filter out unknown fields to prevent crashes when CoinMarketCap adds new response fields
|
|
40
|
+
known_fields = {f.name for f in dataclasses.fields(Quote)}
|
|
41
|
+
filtered = {k: v for k, v in dct_quote_data.items() if k in known_fields}
|
|
42
|
+
|
|
43
|
+
return Quote(base_currency=currency, last_updated=last_updated, **filtered)
|
|
@@ -13,7 +13,7 @@ class TokenInfoFactory:
|
|
|
13
13
|
symbol=data['symbol'],
|
|
14
14
|
slug=data['slug'],
|
|
15
15
|
is_active=data.get('is_active'),
|
|
16
|
-
status=data
|
|
16
|
+
status=data.get('status'),
|
|
17
17
|
first_historical_data=datetime.fromisoformat(data['first_historical_data'].replace('Z', '+00:00')) if 'first_historical_data' in data else None,
|
|
18
18
|
last_historical_data=datetime.fromisoformat(data['last_historical_data'].replace('Z', '+00:00')) if 'last_historical_data' in data else None,
|
|
19
19
|
platform=data.get('platform')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/types/dex_info_factory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v1/cryptocurrency/map.py
RENAMED
|
File without changes
|
{byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v1/key/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{byteforge_coinmarketcap-2.1 → byteforge_coinmarketcap-2.2}/coinmarketcap/v4/dex/listings/info.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|