crypticorn 2.4.6__py3-none-any.whl → 2.5.0__py3-none-any.whl
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.
- crypticorn/cli/init.py +7 -4
- crypticorn/common/__init__.py +1 -0
- crypticorn/common/auth.py +11 -9
- crypticorn/common/errors.py +26 -0
- crypticorn/common/exceptions.py +83 -0
- crypticorn/common/utils.py +23 -6
- crypticorn/klines/client/__init__.py +10 -3
- crypticorn/klines/client/api/__init__.py +1 -0
- crypticorn/klines/client/api/change_in_timeframe_api.py +331 -0
- crypticorn/klines/client/api/funding_rates_api.py +13 -13
- crypticorn/klines/client/api/health_check_api.py +8 -8
- crypticorn/klines/client/api/ohlcv_data_api.py +38 -26
- crypticorn/klines/client/api/symbols_api.py +26 -20
- crypticorn/klines/client/api/udf_api.py +229 -229
- crypticorn/klines/client/api_client.py +8 -5
- crypticorn/klines/client/configuration.py +80 -37
- crypticorn/klines/client/models/__init__.py +9 -3
- crypticorn/klines/client/models/base_response_list_change_in_timeframe_response.py +123 -0
- crypticorn/klines/client/models/change_in_timeframe_response.py +86 -0
- crypticorn/klines/client/models/market_type.py +35 -0
- crypticorn/klines/client/models/response_get_udf_history.py +198 -0
- crypticorn/klines/client/rest.py +111 -159
- crypticorn/klines/main.py +37 -22
- crypticorn/metrics/main.py +42 -42
- crypticorn/pay/client/__init__.py +0 -3
- crypticorn/pay/client/api/now_payments_api.py +1 -53
- crypticorn/pay/client/models/__init__.py +0 -3
- crypticorn/pay/client/models/payment.py +3 -3
- crypticorn/pay/client/models/scope.py +6 -1
- crypticorn/trade/client/models/exchange_key_model.py +2 -1
- {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/METADATA +8 -2
- {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/RECORD +35 -29
- {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/WHEEL +1 -1
- {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/entry_points.txt +0 -0
- {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/top_level.txt +0 -0
crypticorn/klines/client/rest.py
CHANGED
@@ -16,23 +16,16 @@ import io
|
|
16
16
|
import json
|
17
17
|
import re
|
18
18
|
import ssl
|
19
|
+
from typing import Optional, Union
|
19
20
|
|
20
|
-
import
|
21
|
+
import aiohttp
|
22
|
+
import aiohttp_retry
|
21
23
|
|
22
24
|
from crypticorn.klines.client.exceptions import ApiException, ApiValueError
|
23
25
|
|
24
|
-
|
25
|
-
RESTResponseType = urllib3.HTTPResponse
|
26
|
+
RESTResponseType = aiohttp.ClientResponse
|
26
27
|
|
27
|
-
|
28
|
-
def is_socks_proxy_url(url):
|
29
|
-
if url is None:
|
30
|
-
return False
|
31
|
-
split_section = url.split("://")
|
32
|
-
if len(split_section) < 2:
|
33
|
-
return False
|
34
|
-
else:
|
35
|
-
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
28
|
+
ALLOW_RETRY_METHODS = frozenset({"DELETE", "GET", "HEAD", "OPTIONS", "PUT", "TRACE"})
|
36
29
|
|
37
30
|
|
38
31
|
class RESTResponse(io.IOBase):
|
@@ -43,13 +36,13 @@ class RESTResponse(io.IOBase):
|
|
43
36
|
self.reason = resp.reason
|
44
37
|
self.data = None
|
45
38
|
|
46
|
-
def read(self):
|
39
|
+
async def read(self):
|
47
40
|
if self.data is None:
|
48
|
-
self.data = self.response.
|
41
|
+
self.data = await self.response.read()
|
49
42
|
return self.data
|
50
43
|
|
51
44
|
def getheaders(self):
|
52
|
-
"""Returns a
|
45
|
+
"""Returns a CIMultiDictProxy of the response headers."""
|
53
46
|
return self.response.headers
|
54
47
|
|
55
48
|
def getheader(self, name, default=None):
|
@@ -60,56 +53,38 @@ class RESTResponse(io.IOBase):
|
|
60
53
|
class RESTClientObject:
|
61
54
|
|
62
55
|
def __init__(self, configuration) -> None:
|
63
|
-
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
64
|
-
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
|
65
|
-
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
|
66
|
-
# Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
|
67
|
-
|
68
|
-
# cert_reqs
|
69
|
-
if configuration.verify_ssl:
|
70
|
-
cert_reqs = ssl.CERT_REQUIRED
|
71
|
-
else:
|
72
|
-
cert_reqs = ssl.CERT_NONE
|
73
|
-
|
74
|
-
pool_args = {
|
75
|
-
"cert_reqs": cert_reqs,
|
76
|
-
"ca_certs": configuration.ssl_ca_cert,
|
77
|
-
"cert_file": configuration.cert_file,
|
78
|
-
"key_file": configuration.key_file,
|
79
|
-
}
|
80
|
-
if configuration.assert_hostname is not None:
|
81
|
-
pool_args["assert_hostname"] = configuration.assert_hostname
|
82
|
-
|
83
|
-
if configuration.retries is not None:
|
84
|
-
pool_args["retries"] = configuration.retries
|
85
|
-
|
86
|
-
if configuration.tls_server_name:
|
87
|
-
pool_args["server_hostname"] = configuration.tls_server_name
|
88
|
-
|
89
|
-
if configuration.socket_options is not None:
|
90
|
-
pool_args["socket_options"] = configuration.socket_options
|
91
|
-
|
92
|
-
if configuration.connection_pool_maxsize is not None:
|
93
|
-
pool_args["maxsize"] = configuration.connection_pool_maxsize
|
94
56
|
|
95
|
-
#
|
96
|
-
self.
|
57
|
+
# maxsize is number of requests to host that are allowed in parallel
|
58
|
+
self.maxsize = configuration.connection_pool_maxsize
|
97
59
|
|
98
|
-
|
99
|
-
|
100
|
-
|
60
|
+
self.ssl_context = ssl.create_default_context(
|
61
|
+
cafile=configuration.ssl_ca_cert,
|
62
|
+
cadata=configuration.ca_cert_data,
|
63
|
+
)
|
64
|
+
if configuration.cert_file:
|
65
|
+
self.ssl_context.load_cert_chain(
|
66
|
+
configuration.cert_file, keyfile=configuration.key_file
|
67
|
+
)
|
101
68
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
69
|
+
if not configuration.verify_ssl:
|
70
|
+
self.ssl_context.check_hostname = False
|
71
|
+
self.ssl_context.verify_mode = ssl.CERT_NONE
|
72
|
+
|
73
|
+
self.proxy = configuration.proxy
|
74
|
+
self.proxy_headers = configuration.proxy_headers
|
75
|
+
|
76
|
+
self.retries = configuration.retries
|
77
|
+
|
78
|
+
self.pool_manager: Optional[aiohttp.ClientSession] = None
|
79
|
+
self.retry_client: Optional[aiohttp_retry.RetryClient] = None
|
111
80
|
|
112
|
-
def
|
81
|
+
async def close(self) -> None:
|
82
|
+
if self.pool_manager:
|
83
|
+
await self.pool_manager.close()
|
84
|
+
if self.retry_client is not None:
|
85
|
+
await self.retry_client.close()
|
86
|
+
|
87
|
+
async def request(
|
113
88
|
self,
|
114
89
|
method,
|
115
90
|
url,
|
@@ -118,7 +93,7 @@ class RESTClientObject:
|
|
118
93
|
post_params=None,
|
119
94
|
_request_timeout=None,
|
120
95
|
):
|
121
|
-
"""
|
96
|
+
"""Execute request
|
122
97
|
|
123
98
|
:param method: http request method
|
124
99
|
:param url: http request url
|
@@ -142,105 +117,82 @@ class RESTClientObject:
|
|
142
117
|
|
143
118
|
post_params = post_params or {}
|
144
119
|
headers = headers or {}
|
120
|
+
# url already contains the URL query string
|
121
|
+
timeout = _request_timeout or 5 * 60
|
122
|
+
|
123
|
+
if "Content-Type" not in headers:
|
124
|
+
headers["Content-Type"] = "application/json"
|
125
|
+
|
126
|
+
args = {"method": method, "url": url, "timeout": timeout, "headers": headers}
|
127
|
+
|
128
|
+
if self.proxy:
|
129
|
+
args["proxy"] = self.proxy
|
130
|
+
if self.proxy_headers:
|
131
|
+
args["proxy_headers"] = self.proxy_headers
|
132
|
+
|
133
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
134
|
+
if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
|
135
|
+
if re.search("json", headers["Content-Type"], re.IGNORECASE):
|
136
|
+
if body is not None:
|
137
|
+
body = json.dumps(body)
|
138
|
+
args["data"] = body
|
139
|
+
elif headers["Content-Type"] == "application/x-www-form-urlencoded":
|
140
|
+
args["data"] = aiohttp.FormData(post_params)
|
141
|
+
elif headers["Content-Type"] == "multipart/form-data":
|
142
|
+
# must del headers['Content-Type'], or the correct
|
143
|
+
# Content-Type which generated by aiohttp
|
144
|
+
del headers["Content-Type"]
|
145
|
+
data = aiohttp.FormData()
|
146
|
+
for param in post_params:
|
147
|
+
k, v = param
|
148
|
+
if isinstance(v, tuple) and len(v) == 3:
|
149
|
+
data.add_field(k, value=v[1], filename=v[0], content_type=v[2])
|
150
|
+
else:
|
151
|
+
# Ensures that dict objects are serialized
|
152
|
+
if isinstance(v, dict):
|
153
|
+
v = json.dumps(v)
|
154
|
+
elif isinstance(v, int):
|
155
|
+
v = str(v)
|
156
|
+
data.add_field(k, v)
|
157
|
+
args["data"] = data
|
158
|
+
|
159
|
+
# Pass a `bytes` or `str` parameter directly in the body to support
|
160
|
+
# other content types than Json when `body` argument is provided
|
161
|
+
# in serialized form
|
162
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
163
|
+
args["data"] = body
|
164
|
+
else:
|
165
|
+
# Cannot generate the request from given parameters
|
166
|
+
msg = """Cannot prepare a request message for provided
|
167
|
+
arguments. Please check that your arguments match
|
168
|
+
declared content type."""
|
169
|
+
raise ApiException(status=0, reason=msg)
|
145
170
|
|
146
|
-
|
147
|
-
if _request_timeout:
|
148
|
-
if isinstance(_request_timeout, (int, float)):
|
149
|
-
timeout = urllib3.Timeout(total=_request_timeout)
|
150
|
-
elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
|
151
|
-
timeout = urllib3.Timeout(
|
152
|
-
connect=_request_timeout[0], read=_request_timeout[1]
|
153
|
-
)
|
171
|
+
pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
|
154
172
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
method,
|
176
|
-
url,
|
177
|
-
fields=post_params,
|
178
|
-
encode_multipart=False,
|
179
|
-
timeout=timeout,
|
180
|
-
headers=headers,
|
181
|
-
preload_content=False,
|
182
|
-
)
|
183
|
-
elif content_type == "multipart/form-data":
|
184
|
-
# must del headers['Content-Type'], or the correct
|
185
|
-
# Content-Type which generated by urllib3 will be
|
186
|
-
# overwritten.
|
187
|
-
del headers["Content-Type"]
|
188
|
-
# Ensures that dict objects are serialized
|
189
|
-
post_params = [
|
190
|
-
(a, json.dumps(b)) if isinstance(b, dict) else (a, b)
|
191
|
-
for a, b in post_params
|
192
|
-
]
|
193
|
-
r = self.pool_manager.request(
|
194
|
-
method,
|
195
|
-
url,
|
196
|
-
fields=post_params,
|
197
|
-
encode_multipart=True,
|
198
|
-
timeout=timeout,
|
199
|
-
headers=headers,
|
200
|
-
preload_content=False,
|
201
|
-
)
|
202
|
-
# Pass a `string` parameter directly in the body to support
|
203
|
-
# other content types than JSON when `body` argument is
|
204
|
-
# provided in serialized form.
|
205
|
-
elif isinstance(body, str) or isinstance(body, bytes):
|
206
|
-
r = self.pool_manager.request(
|
207
|
-
method,
|
208
|
-
url,
|
209
|
-
body=body,
|
210
|
-
timeout=timeout,
|
211
|
-
headers=headers,
|
212
|
-
preload_content=False,
|
213
|
-
)
|
214
|
-
elif headers["Content-Type"].startswith("text/") and isinstance(
|
215
|
-
body, bool
|
216
|
-
):
|
217
|
-
request_body = "true" if body else "false"
|
218
|
-
r = self.pool_manager.request(
|
219
|
-
method,
|
220
|
-
url,
|
221
|
-
body=request_body,
|
222
|
-
preload_content=False,
|
223
|
-
timeout=timeout,
|
224
|
-
headers=headers,
|
225
|
-
)
|
226
|
-
else:
|
227
|
-
# Cannot generate the request from given parameters
|
228
|
-
msg = """Cannot prepare a request message for provided
|
229
|
-
arguments. Please check that your arguments match
|
230
|
-
declared content type."""
|
231
|
-
raise ApiException(status=0, reason=msg)
|
232
|
-
# For `GET`, `HEAD`
|
233
|
-
else:
|
234
|
-
r = self.pool_manager.request(
|
235
|
-
method,
|
236
|
-
url,
|
237
|
-
fields={},
|
238
|
-
timeout=timeout,
|
239
|
-
headers=headers,
|
240
|
-
preload_content=False,
|
173
|
+
# https pool manager
|
174
|
+
if self.pool_manager is None:
|
175
|
+
self.pool_manager = aiohttp.ClientSession(
|
176
|
+
connector=aiohttp.TCPConnector(
|
177
|
+
limit=self.maxsize, ssl=self.ssl_context
|
178
|
+
),
|
179
|
+
trust_env=True,
|
180
|
+
)
|
181
|
+
pool_manager = self.pool_manager
|
182
|
+
|
183
|
+
if self.retries is not None and method in ALLOW_RETRY_METHODS:
|
184
|
+
if self.retry_client is None:
|
185
|
+
self.retry_client = aiohttp_retry.RetryClient(
|
186
|
+
client_session=self.pool_manager,
|
187
|
+
retry_options=aiohttp_retry.ExponentialRetry(
|
188
|
+
attempts=self.retries,
|
189
|
+
factor=2.0,
|
190
|
+
start_timeout=0.1,
|
191
|
+
max_timeout=120.0,
|
192
|
+
),
|
241
193
|
)
|
242
|
-
|
243
|
-
|
244
|
-
|
194
|
+
pool_manager = self.retry_client
|
195
|
+
|
196
|
+
r = await pool_manager.request(**args)
|
245
197
|
|
246
198
|
return RESTResponse(r)
|
crypticorn/klines/main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
from __future__ import annotations
|
2
2
|
from crypticorn.klines import (
|
3
3
|
ApiClient,
|
4
4
|
Configuration,
|
@@ -8,16 +8,22 @@ from crypticorn.klines import (
|
|
8
8
|
SymbolsApi,
|
9
9
|
UDFApi,
|
10
10
|
)
|
11
|
+
from crypticorn.common import optional_import
|
11
12
|
|
12
13
|
|
13
14
|
class FundingRatesApiWrapper(FundingRatesApi):
|
14
15
|
"""
|
15
16
|
A wrapper for the FundingRatesApi class.
|
16
17
|
"""
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
async def get_funding_rates_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
|
19
|
+
"""
|
20
|
+
Get the funding rates in a pandas DataFrame.
|
21
|
+
"""
|
22
|
+
pd = optional_import("pandas", "extra")
|
23
|
+
response = await self.get_funding_rates_without_preload_content(*args, **kwargs)
|
24
|
+
response.raise_for_status()
|
25
|
+
json_data = await response.json()
|
26
|
+
return pd.DataFrame(json_data)
|
21
27
|
|
22
28
|
|
23
29
|
class OHLCVDataApiWrapper(OHLCVDataApi):
|
@@ -25,9 +31,22 @@ class OHLCVDataApiWrapper(OHLCVDataApi):
|
|
25
31
|
A wrapper for the OHLCVDataApi class.
|
26
32
|
"""
|
27
33
|
|
28
|
-
def get_ohlcv_data_fmt(self):
|
29
|
-
|
30
|
-
|
34
|
+
async def get_ohlcv_data_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
|
35
|
+
"""
|
36
|
+
Get the OHLCV data in a pandas DataFrame.
|
37
|
+
"""
|
38
|
+
pd = optional_import("pandas", "extra")
|
39
|
+
response = await self.get_ohlcv_without_preload_content(*args, **kwargs)
|
40
|
+
response.raise_for_status()
|
41
|
+
json_data = await response.json()
|
42
|
+
return pd.DataFrame({
|
43
|
+
"timestamp": json_data["timestamp"],
|
44
|
+
"open": json_data["open"],
|
45
|
+
"high": json_data["high"],
|
46
|
+
"low": json_data["low"],
|
47
|
+
"close": json_data["close"],
|
48
|
+
"volume": json_data["volume"]
|
49
|
+
})
|
31
50
|
|
32
51
|
|
33
52
|
class SymbolsApiWrapper(SymbolsApi):
|
@@ -35,19 +54,15 @@ class SymbolsApiWrapper(SymbolsApi):
|
|
35
54
|
A wrapper for the SymbolsApi class.
|
36
55
|
"""
|
37
56
|
|
38
|
-
def get_symbols_fmt(self):
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def get_udf_fmt(self):
|
49
|
-
response = self.get_history_udf_history_get()
|
50
|
-
return pd.DataFrame(response.json())
|
57
|
+
async def get_symbols_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
|
58
|
+
"""
|
59
|
+
Get the symbols in a pandas DataFrame.
|
60
|
+
"""
|
61
|
+
pd = optional_import("pandas", "extra")
|
62
|
+
response = await self.get_klines_symbols_without_preload_content(*args, **kwargs)
|
63
|
+
response.raise_for_status()
|
64
|
+
json_data = await response.json()
|
65
|
+
return pd.DataFrame(json_data["data"], columns=["symbol"])
|
51
66
|
|
52
67
|
|
53
68
|
class KlinesClient:
|
@@ -65,5 +80,5 @@ class KlinesClient:
|
|
65
80
|
self.funding = FundingRatesApiWrapper(self.base_client)
|
66
81
|
self.ohlcv = OHLCVDataApiWrapper(self.base_client)
|
67
82
|
self.symbols = SymbolsApiWrapper(self.base_client)
|
68
|
-
self.udf =
|
83
|
+
self.udf = UDFApi(self.base_client)
|
69
84
|
self.health = HealthCheckApi(self.base_client)
|
crypticorn/metrics/main.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
from crypticorn.metrics import (
|
2
3
|
ApiClient,
|
3
4
|
Configuration,
|
@@ -10,12 +11,11 @@ from crypticorn.metrics import (
|
|
10
11
|
TokensApi,
|
11
12
|
MarketType,
|
12
13
|
)
|
14
|
+
from crypticorn.common import optional_import
|
13
15
|
from pydantic import StrictStr, StrictInt, Field
|
14
16
|
from typing_extensions import Annotated
|
15
17
|
from typing import Optional
|
16
18
|
|
17
|
-
import pandas as pd
|
18
|
-
|
19
19
|
|
20
20
|
class MetricsClient:
|
21
21
|
"""
|
@@ -43,41 +43,16 @@ class MarketcapApiWrapper(MarketcapApi):
|
|
43
43
|
A wrapper for the MarketcapApi class.
|
44
44
|
"""
|
45
45
|
|
46
|
-
async def get_marketcap_symbols_fmt(
|
47
|
-
self,
|
48
|
-
start_timestamp: Annotated[
|
49
|
-
Optional[StrictInt], Field(description="Start timestamp")
|
50
|
-
] = None,
|
51
|
-
end_timestamp: Annotated[
|
52
|
-
Optional[StrictInt], Field(description="End timestamp")
|
53
|
-
] = None,
|
54
|
-
interval: Annotated[
|
55
|
-
Optional[StrictStr],
|
56
|
-
Field(description="Interval for which to fetch symbols and marketcap data"),
|
57
|
-
] = None,
|
58
|
-
market: Annotated[
|
59
|
-
Optional[MarketType],
|
60
|
-
Field(description="Market for which to fetch symbols and marketcap data"),
|
61
|
-
] = None,
|
62
|
-
exchange: Annotated[
|
63
|
-
Optional[StrictStr],
|
64
|
-
Field(description="Exchange for which to fetch symbols and marketcap data"),
|
65
|
-
] = None,
|
66
|
-
) -> pd.DataFrame:
|
46
|
+
async def get_marketcap_symbols_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
|
67
47
|
"""
|
68
48
|
Get the marketcap symbols in a pandas dataframe
|
69
49
|
"""
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
interval=interval,
|
74
|
-
market=market,
|
75
|
-
exchange=exchange,
|
76
|
-
)
|
50
|
+
pd = optional_import("pandas", "extra")
|
51
|
+
response = await self.get_marketcap_symbols_without_preload_content(*args, **kwargs)
|
52
|
+
response.raise_for_status()
|
77
53
|
json_response = await response.json()
|
78
54
|
df = pd.DataFrame(json_response["data"])
|
79
55
|
df.rename(columns={df.columns[0]: "timestamp"}, inplace=True)
|
80
|
-
df["timestamp"] = pd.to_datetime(df["timestamp"]).astype("int64") // 10**9
|
81
56
|
return df
|
82
57
|
|
83
58
|
|
@@ -86,18 +61,43 @@ class TokensApiWrapper(TokensApi):
|
|
86
61
|
A wrapper for the TokensApi class.
|
87
62
|
"""
|
88
63
|
|
89
|
-
async def
|
90
|
-
self,
|
91
|
-
token_type: Annotated[
|
92
|
-
StrictStr,
|
93
|
-
Field(description="Type of tokens to fetch"),
|
94
|
-
],
|
95
|
-
) -> pd.DataFrame:
|
64
|
+
async def get_stable_and_wrapped_tokens_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
|
96
65
|
"""
|
97
66
|
Get the tokens in a pandas dataframe
|
98
67
|
"""
|
99
|
-
|
100
|
-
|
101
|
-
)
|
68
|
+
pd = optional_import("pandas", "extra")
|
69
|
+
response = await self.get_stable_and_wrapped_tokens_without_preload_content(*args, **kwargs)
|
70
|
+
response.raise_for_status()
|
71
|
+
json_data = await response.json()
|
72
|
+
return pd.DataFrame(json_data)
|
73
|
+
|
74
|
+
class ExchangesApiWrapper(ExchangesApi):
|
75
|
+
"""
|
76
|
+
A wrapper for the ExchangesApi class.
|
77
|
+
"""
|
78
|
+
|
79
|
+
async def get_exchanges_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
|
80
|
+
"""
|
81
|
+
Get the exchanges in a pandas dataframe
|
82
|
+
"""
|
83
|
+
pd = optional_import("pandas", "extra")
|
84
|
+
response = await self.get_available_exchanges_without_preload_content(*args, **kwargs)
|
85
|
+
response.raise_for_status()
|
102
86
|
json_data = await response.json()
|
103
|
-
|
87
|
+
processed_results = []
|
88
|
+
for row in json_data:
|
89
|
+
data = {'timestamp': row['timestamp']}
|
90
|
+
data.update(row['exchanges'])
|
91
|
+
processed_results.append(data)
|
92
|
+
|
93
|
+
# Create DataFrame and sort columns
|
94
|
+
df = pd.DataFrame(processed_results)
|
95
|
+
cols = ['timestamp'] + sorted([col for col in df.columns if col != 'timestamp'])
|
96
|
+
df = df[cols]
|
97
|
+
|
98
|
+
# Convert timestamp to unix timestamp
|
99
|
+
df['timestamp'] = pd.to_datetime(df['timestamp']).astype("int64") // 10 ** 9
|
100
|
+
|
101
|
+
# Convert exchange availability to boolean integers (0/1)
|
102
|
+
df = df.astype({'timestamp': 'int64', **{col: 'int8' for col in df.columns if col != 'timestamp'}})
|
103
|
+
return df
|
@@ -38,9 +38,6 @@ from crypticorn.pay.client.models.http_validation_error import HTTPValidationErr
|
|
38
38
|
from crypticorn.pay.client.models.now_api_status_res import NowAPIStatusRes
|
39
39
|
from crypticorn.pay.client.models.now_create_invoice_req import NowCreateInvoiceReq
|
40
40
|
from crypticorn.pay.client.models.now_create_invoice_res import NowCreateInvoiceRes
|
41
|
-
from crypticorn.pay.client.models.now_fee_structure import NowFeeStructure
|
42
|
-
from crypticorn.pay.client.models.now_payment_status import NowPaymentStatus
|
43
|
-
from crypticorn.pay.client.models.now_webhook_payload import NowWebhookPayload
|
44
41
|
from crypticorn.pay.client.models.payment import Payment
|
45
42
|
from crypticorn.pay.client.models.payment_status import PaymentStatus
|
46
43
|
from crypticorn.pay.client.models.product_create import ProductCreate
|