crypticorn 2.1.5__py3-none-any.whl → 2.2.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.
Files changed (48) hide show
  1. crypticorn/auth/main.py +2 -19
  2. crypticorn/client.py +75 -22
  3. crypticorn/common/__init__.py +1 -2
  4. crypticorn/common/auth.py +205 -1
  5. crypticorn/common/scopes.py +2 -2
  6. crypticorn/common/urls.py +21 -9
  7. crypticorn/hive/main.py +4 -12
  8. crypticorn/klines/client/configuration.py +2 -2
  9. crypticorn/klines/main.py +2 -12
  10. crypticorn/metrics/__init__.py +4 -0
  11. crypticorn/metrics/client/__init__.py +60 -0
  12. crypticorn/metrics/client/api/__init__.py +10 -0
  13. crypticorn/metrics/client/api/exchanges_api.py +1003 -0
  14. crypticorn/metrics/client/api/health_check_api.py +265 -0
  15. crypticorn/metrics/client/api/indicators_api.py +680 -0
  16. crypticorn/metrics/client/api/logs_api.py +356 -0
  17. crypticorn/metrics/client/api/marketcap_api.py +1315 -0
  18. crypticorn/metrics/client/api/markets_api.py +618 -0
  19. crypticorn/metrics/client/api/tokens_api.py +300 -0
  20. crypticorn/metrics/client/api_client.py +758 -0
  21. crypticorn/metrics/client/api_response.py +20 -0
  22. crypticorn/metrics/client/configuration.py +575 -0
  23. crypticorn/metrics/client/exceptions.py +220 -0
  24. crypticorn/metrics/client/models/__init__.py +37 -0
  25. crypticorn/metrics/client/models/base_response_dict.py +106 -0
  26. crypticorn/metrics/client/models/base_response_health_check_response.py +114 -0
  27. crypticorn/metrics/client/models/base_response_list_dict.py +106 -0
  28. crypticorn/metrics/client/models/base_response_list_exchange_mapping.py +118 -0
  29. crypticorn/metrics/client/models/base_response_list_str.py +106 -0
  30. crypticorn/metrics/client/models/error_response.py +109 -0
  31. crypticorn/metrics/client/models/exchange_mapping.py +132 -0
  32. crypticorn/metrics/client/models/health_check_response.py +91 -0
  33. crypticorn/metrics/client/models/http_validation_error.py +99 -0
  34. crypticorn/metrics/client/models/market.py +35 -0
  35. crypticorn/metrics/client/models/severity.py +36 -0
  36. crypticorn/metrics/client/models/validation_error.py +105 -0
  37. crypticorn/metrics/client/models/validation_error_loc_inner.py +159 -0
  38. crypticorn/metrics/client/py.typed +0 -0
  39. crypticorn/metrics/client/rest.py +195 -0
  40. crypticorn/metrics/main.py +102 -0
  41. crypticorn/pay/main.py +2 -12
  42. crypticorn/trade/main.py +2 -12
  43. crypticorn-2.2.0.dist-info/METADATA +146 -0
  44. {crypticorn-2.1.5.dist-info → crypticorn-2.2.0.dist-info}/RECORD +46 -16
  45. crypticorn/common/auth_client.py +0 -213
  46. crypticorn-2.1.5.dist-info/METADATA +0 -92
  47. {crypticorn-2.1.5.dist-info → crypticorn-2.2.0.dist-info}/WHEEL +0 -0
  48. {crypticorn-2.1.5.dist-info → crypticorn-2.2.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,20 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Optional, Generic, Mapping, TypeVar
5
+ from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+
10
+ class ApiResponse(BaseModel, Generic[T]):
11
+ """
12
+ API response object
13
+ """
14
+
15
+ status_code: StrictInt = Field(description="HTTP status code")
16
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
17
+ data: T = Field(description="Deserialized data given the data type")
18
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
19
+
20
+ model_config = {"arbitrary_types_allowed": True}
@@ -0,0 +1,575 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Marketcap Service API
5
+
6
+ API for retrieving historical marketcap data, available exchanges, and indicators. ## Features - Historical marketcap data - OHLCV data with marketcap - Technical indicators (KER, SMA) - Exchange and symbol mappings - Error logs
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ import copy
16
+ import http.client as httplib
17
+ import logging
18
+ from logging import FileHandler
19
+ import sys
20
+ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
21
+ from typing_extensions import NotRequired, Self
22
+
23
+ import urllib3
24
+
25
+
26
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
27
+ "multipleOf",
28
+ "maximum",
29
+ "exclusiveMaximum",
30
+ "minimum",
31
+ "exclusiveMinimum",
32
+ "maxLength",
33
+ "minLength",
34
+ "pattern",
35
+ "maxItems",
36
+ "minItems",
37
+ }
38
+
39
+ ServerVariablesT = Dict[str, str]
40
+
41
+ GenericAuthSetting = TypedDict(
42
+ "GenericAuthSetting",
43
+ {
44
+ "type": str,
45
+ "in": str,
46
+ "key": str,
47
+ "value": str,
48
+ },
49
+ )
50
+
51
+
52
+ OAuth2AuthSetting = TypedDict(
53
+ "OAuth2AuthSetting",
54
+ {
55
+ "type": Literal["oauth2"],
56
+ "in": Literal["header"],
57
+ "key": Literal["Authorization"],
58
+ "value": str,
59
+ },
60
+ )
61
+
62
+
63
+ APIKeyAuthSetting = TypedDict(
64
+ "APIKeyAuthSetting",
65
+ {
66
+ "type": Literal["api_key"],
67
+ "in": str,
68
+ "key": str,
69
+ "value": Optional[str],
70
+ },
71
+ )
72
+
73
+
74
+ BasicAuthSetting = TypedDict(
75
+ "BasicAuthSetting",
76
+ {
77
+ "type": Literal["basic"],
78
+ "in": Literal["header"],
79
+ "key": Literal["Authorization"],
80
+ "value": Optional[str],
81
+ },
82
+ )
83
+
84
+
85
+ BearerFormatAuthSetting = TypedDict(
86
+ "BearerFormatAuthSetting",
87
+ {
88
+ "type": Literal["bearer"],
89
+ "in": Literal["header"],
90
+ "format": Literal["JWT"],
91
+ "key": Literal["Authorization"],
92
+ "value": str,
93
+ },
94
+ )
95
+
96
+
97
+ BearerAuthSetting = TypedDict(
98
+ "BearerAuthSetting",
99
+ {
100
+ "type": Literal["bearer"],
101
+ "in": Literal["header"],
102
+ "key": Literal["Authorization"],
103
+ "value": str,
104
+ },
105
+ )
106
+
107
+
108
+ HTTPSignatureAuthSetting = TypedDict(
109
+ "HTTPSignatureAuthSetting",
110
+ {
111
+ "type": Literal["http-signature"],
112
+ "in": Literal["header"],
113
+ "key": Literal["Authorization"],
114
+ "value": None,
115
+ },
116
+ )
117
+
118
+
119
+ AuthSettings = TypedDict(
120
+ "AuthSettings",
121
+ {},
122
+ total=False,
123
+ )
124
+
125
+
126
+ class HostSettingVariable(TypedDict):
127
+ description: str
128
+ default_value: str
129
+ enum_values: List[str]
130
+
131
+
132
+ class HostSetting(TypedDict):
133
+ url: str
134
+ description: str
135
+ variables: NotRequired[Dict[str, HostSettingVariable]]
136
+
137
+
138
+ class Configuration:
139
+ """This class contains various settings of the API client.
140
+
141
+ :param host: Base url.
142
+ :param ignore_operation_servers
143
+ Boolean to ignore operation servers for the API client.
144
+ Config will use `host` as the base url regardless of the operation servers.
145
+ :param api_key: Dict to store API key(s).
146
+ Each entry in the dict specifies an API key.
147
+ The dict key is the name of the security scheme in the OAS specification.
148
+ The dict value is the API key secret.
149
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
150
+ The dict key is the name of the security scheme in the OAS specification.
151
+ The dict value is an API key prefix when generating the auth data.
152
+ :param username: Username for HTTP basic authentication.
153
+ :param password: Password for HTTP basic authentication.
154
+ :param access_token: Access token.
155
+ :param server_index: Index to servers configuration.
156
+ :param server_variables: Mapping with string values to replace variables in
157
+ templated server configuration. The validation of enums is performed for
158
+ variables with defined enum values before.
159
+ :param server_operation_index: Mapping from operation ID to an index to server
160
+ configuration.
161
+ :param server_operation_variables: Mapping from operation ID to a mapping with
162
+ string values to replace variables in templated server configuration.
163
+ The validation of enums is performed for variables with defined enum
164
+ values before.
165
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
166
+ in PEM format.
167
+ :param retries: Number of retries for API requests.
168
+
169
+ """
170
+
171
+ _default: ClassVar[Optional[Self]] = None
172
+
173
+ def __init__(
174
+ self,
175
+ host: Optional[str] = None,
176
+ api_key: Optional[Dict[str, str]] = None,
177
+ api_key_prefix: Optional[Dict[str, str]] = None,
178
+ username: Optional[str] = None,
179
+ password: Optional[str] = None,
180
+ access_token: Optional[str] = None,
181
+ server_index: Optional[int] = None,
182
+ server_variables: Optional[ServerVariablesT] = None,
183
+ server_operation_index: Optional[Dict[int, int]] = None,
184
+ server_operation_variables: Optional[Dict[int, ServerVariablesT]] = None,
185
+ ignore_operation_servers: bool = False,
186
+ ssl_ca_cert: Optional[str] = None,
187
+ retries: Optional[int] = None,
188
+ *,
189
+ debug: Optional[bool] = None,
190
+ ) -> None:
191
+ """Constructor"""
192
+ self._base_path = (
193
+ "https://api.crypticorn.dev/v1/metrics" if host is None else host
194
+ )
195
+ """Default Base url
196
+ """
197
+ self.server_index = 0 if server_index is None and host is None else server_index
198
+ self.server_operation_index = server_operation_index or {}
199
+ """Default server index
200
+ """
201
+ self.server_variables = server_variables or {}
202
+ self.server_operation_variables = server_operation_variables or {}
203
+ """Default server variables
204
+ """
205
+ self.ignore_operation_servers = ignore_operation_servers
206
+ """Ignore operation servers
207
+ """
208
+ self.temp_folder_path = None
209
+ """Temp file folder for downloading files
210
+ """
211
+ # Authentication Settings
212
+ self.api_key = {}
213
+ if api_key:
214
+ self.api_key = api_key
215
+ """dict to store API key(s)
216
+ """
217
+ self.api_key_prefix = {}
218
+ if api_key_prefix:
219
+ self.api_key_prefix = api_key_prefix
220
+ """dict to store API prefix (e.g. Bearer)
221
+ """
222
+ self.refresh_api_key_hook = None
223
+ """function hook to refresh API key if expired
224
+ """
225
+ self.username = username
226
+ """Username for HTTP basic authentication
227
+ """
228
+ self.password = password
229
+ """Password for HTTP basic authentication
230
+ """
231
+ self.access_token = access_token
232
+ """Access token
233
+ """
234
+ self.logger = {}
235
+ """Logging Settings
236
+ """
237
+ self.logger["package_logger"] = logging.getLogger("client")
238
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
239
+ self.logger_format = "%(asctime)s %(levelname)s %(message)s"
240
+ """Log format
241
+ """
242
+ self.logger_stream_handler = None
243
+ """Log stream handler
244
+ """
245
+ self.logger_file_handler: Optional[FileHandler] = None
246
+ """Log file handler
247
+ """
248
+ self.logger_file = None
249
+ """Debug file location
250
+ """
251
+ if debug is not None:
252
+ self.debug = debug
253
+ else:
254
+ self.__debug = False
255
+ """Debug switch
256
+ """
257
+
258
+ self.verify_ssl = True
259
+ """SSL/TLS verification
260
+ Set this to false to skip verifying SSL certificate when calling API
261
+ from https server.
262
+ """
263
+ self.ssl_ca_cert = ssl_ca_cert
264
+ """Set this to customize the certificate file to verify the peer.
265
+ """
266
+ self.cert_file = None
267
+ """client certificate file
268
+ """
269
+ self.key_file = None
270
+ """client key file
271
+ """
272
+ self.assert_hostname = None
273
+ """Set this to True/False to enable/disable SSL hostname verification.
274
+ """
275
+ self.tls_server_name = None
276
+ """SSL/TLS Server Name Indication (SNI)
277
+ Set this to the SNI value expected by the server.
278
+ """
279
+
280
+ self.connection_pool_maxsize = 100
281
+ """This value is passed to the aiohttp to limit simultaneous connections.
282
+ Default values is 100, None means no-limit.
283
+ """
284
+
285
+ self.proxy: Optional[str] = None
286
+ """Proxy URL
287
+ """
288
+ self.proxy_headers = None
289
+ """Proxy headers
290
+ """
291
+ self.safe_chars_for_path_param = ""
292
+ """Safe chars for path_param
293
+ """
294
+ self.retries = retries
295
+ """Adding retries to override urllib3 default value 3
296
+ """
297
+ # Enable client side validation
298
+ self.client_side_validation = True
299
+
300
+ self.socket_options = None
301
+ """Options to pass down to the underlying urllib3 socket
302
+ """
303
+
304
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
305
+ """datetime format
306
+ """
307
+
308
+ self.date_format = "%Y-%m-%d"
309
+ """date format
310
+ """
311
+
312
+ def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
313
+ cls = self.__class__
314
+ result = cls.__new__(cls)
315
+ memo[id(self)] = result
316
+ for k, v in self.__dict__.items():
317
+ if k not in ("logger", "logger_file_handler"):
318
+ setattr(result, k, copy.deepcopy(v, memo))
319
+ # shallow copy of loggers
320
+ result.logger = copy.copy(self.logger)
321
+ # use setters to configure loggers
322
+ result.logger_file = self.logger_file
323
+ result.debug = self.debug
324
+ return result
325
+
326
+ def __setattr__(self, name: str, value: Any) -> None:
327
+ object.__setattr__(self, name, value)
328
+
329
+ @classmethod
330
+ def set_default(cls, default: Optional[Self]) -> None:
331
+ """Set default instance of configuration.
332
+
333
+ It stores default configuration, which can be
334
+ returned by get_default_copy method.
335
+
336
+ :param default: object of Configuration
337
+ """
338
+ cls._default = default
339
+
340
+ @classmethod
341
+ def get_default_copy(cls) -> Self:
342
+ """Deprecated. Please use `get_default` instead.
343
+
344
+ Deprecated. Please use `get_default` instead.
345
+
346
+ :return: The configuration object.
347
+ """
348
+ return cls.get_default()
349
+
350
+ @classmethod
351
+ def get_default(cls) -> Self:
352
+ """Return the default configuration.
353
+
354
+ This method returns newly created, based on default constructor,
355
+ object of Configuration class or returns a copy of default
356
+ configuration.
357
+
358
+ :return: The configuration object.
359
+ """
360
+ if cls._default is None:
361
+ cls._default = cls()
362
+ return cls._default
363
+
364
+ @property
365
+ def logger_file(self) -> Optional[str]:
366
+ """The logger file.
367
+
368
+ If the logger_file is None, then add stream handler and remove file
369
+ handler. Otherwise, add file handler and remove stream handler.
370
+
371
+ :param value: The logger_file path.
372
+ :type: str
373
+ """
374
+ return self.__logger_file
375
+
376
+ @logger_file.setter
377
+ def logger_file(self, value: Optional[str]) -> None:
378
+ """The logger file.
379
+
380
+ If the logger_file is None, then add stream handler and remove file
381
+ handler. Otherwise, add file handler and remove stream handler.
382
+
383
+ :param value: The logger_file path.
384
+ :type: str
385
+ """
386
+ self.__logger_file = value
387
+ if self.__logger_file:
388
+ # If set logging file,
389
+ # then add file handler and remove stream handler.
390
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
391
+ self.logger_file_handler.setFormatter(self.logger_formatter)
392
+ for _, logger in self.logger.items():
393
+ logger.addHandler(self.logger_file_handler)
394
+
395
+ @property
396
+ def debug(self) -> bool:
397
+ """Debug status
398
+
399
+ :param value: The debug status, True or False.
400
+ :type: bool
401
+ """
402
+ return self.__debug
403
+
404
+ @debug.setter
405
+ def debug(self, value: bool) -> None:
406
+ """Debug status
407
+
408
+ :param value: The debug status, True or False.
409
+ :type: bool
410
+ """
411
+ self.__debug = value
412
+ if self.__debug:
413
+ # if debug status is True, turn on debug logging
414
+ for _, logger in self.logger.items():
415
+ logger.setLevel(logging.DEBUG)
416
+ # turn on httplib debug
417
+ httplib.HTTPConnection.debuglevel = 1
418
+ else:
419
+ # if debug status is False, turn off debug logging,
420
+ # setting log level to default `logging.WARNING`
421
+ for _, logger in self.logger.items():
422
+ logger.setLevel(logging.WARNING)
423
+ # turn off httplib debug
424
+ httplib.HTTPConnection.debuglevel = 0
425
+
426
+ @property
427
+ def logger_format(self) -> str:
428
+ """The logger format.
429
+
430
+ The logger_formatter will be updated when sets logger_format.
431
+
432
+ :param value: The format string.
433
+ :type: str
434
+ """
435
+ return self.__logger_format
436
+
437
+ @logger_format.setter
438
+ def logger_format(self, value: str) -> None:
439
+ """The logger format.
440
+
441
+ The logger_formatter will be updated when sets logger_format.
442
+
443
+ :param value: The format string.
444
+ :type: str
445
+ """
446
+ self.__logger_format = value
447
+ self.logger_formatter = logging.Formatter(self.__logger_format)
448
+
449
+ def get_api_key_with_prefix(
450
+ self, identifier: str, alias: Optional[str] = None
451
+ ) -> Optional[str]:
452
+ """Gets API key (with prefix if set).
453
+
454
+ :param identifier: The identifier of apiKey.
455
+ :param alias: The alternative identifier of apiKey.
456
+ :return: The token for api key authentication.
457
+ """
458
+ if self.refresh_api_key_hook is not None:
459
+ self.refresh_api_key_hook(self)
460
+ key = self.api_key.get(
461
+ identifier, self.api_key.get(alias) if alias is not None else None
462
+ )
463
+ if key:
464
+ prefix = self.api_key_prefix.get(identifier)
465
+ if prefix:
466
+ return "%s %s" % (prefix, key)
467
+ else:
468
+ return key
469
+
470
+ return None
471
+
472
+ def get_basic_auth_token(self) -> Optional[str]:
473
+ """Gets HTTP basic authentication header (string).
474
+
475
+ :return: The token for basic HTTP authentication.
476
+ """
477
+ username = ""
478
+ if self.username is not None:
479
+ username = self.username
480
+ password = ""
481
+ if self.password is not None:
482
+ password = self.password
483
+ return urllib3.util.make_headers(basic_auth=username + ":" + password).get(
484
+ "authorization"
485
+ )
486
+
487
+ def auth_settings(self) -> AuthSettings:
488
+ """Gets Auth Settings dict for api client.
489
+
490
+ :return: The Auth Settings information dict.
491
+ """
492
+ auth: AuthSettings = {}
493
+ return auth
494
+
495
+ def to_debug_report(self) -> str:
496
+ """Gets the essential information for debugging.
497
+
498
+ :return: The report for debugging.
499
+ """
500
+ return (
501
+ "Python SDK Debug Report:\n"
502
+ "OS: {env}\n"
503
+ "Python Version: {pyversion}\n"
504
+ "Version of the API: 1.0.0\n"
505
+ "SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version)
506
+ )
507
+
508
+ def get_host_settings(self) -> List[HostSetting]:
509
+ """Gets an array of host settings
510
+
511
+ :return: An array of host settings
512
+ """
513
+ return [
514
+ {
515
+ "url": "https://api.crypticorn.dev/v1/metrics",
516
+ "description": "No description provided",
517
+ }
518
+ ]
519
+
520
+ def get_host_from_settings(
521
+ self,
522
+ index: Optional[int],
523
+ variables: Optional[ServerVariablesT] = None,
524
+ servers: Optional[List[HostSetting]] = None,
525
+ ) -> str:
526
+ """Gets host URL based on the index and variables
527
+ :param index: array index of the host settings
528
+ :param variables: hash of variable and the corresponding value
529
+ :param servers: an array of host settings or None
530
+ :return: URL based on host settings
531
+ """
532
+ if index is None:
533
+ return self._base_path
534
+
535
+ variables = {} if variables is None else variables
536
+ servers = self.get_host_settings() if servers is None else servers
537
+
538
+ try:
539
+ server = servers[index]
540
+ except IndexError:
541
+ raise ValueError(
542
+ "Invalid index {0} when selecting the host settings. "
543
+ "Must be less than {1}".format(index, len(servers))
544
+ )
545
+
546
+ url = server["url"]
547
+
548
+ # go through variables and replace placeholders
549
+ for variable_name, variable in server.get("variables", {}).items():
550
+ used_value = variables.get(variable_name, variable["default_value"])
551
+
552
+ if "enum_values" in variable and used_value not in variable["enum_values"]:
553
+ raise ValueError(
554
+ "The variable `{0}` in the host URL has invalid value "
555
+ "{1}. Must be {2}.".format(
556
+ variable_name, variables[variable_name], variable["enum_values"]
557
+ )
558
+ )
559
+
560
+ url = url.replace("{" + variable_name + "}", used_value)
561
+
562
+ return url
563
+
564
+ @property
565
+ def host(self) -> str:
566
+ """Return generated host."""
567
+ return self.get_host_from_settings(
568
+ self.server_index, variables=self.server_variables
569
+ )
570
+
571
+ @host.setter
572
+ def host(self, value: str) -> None:
573
+ """Fix base path."""
574
+ self._base_path = value
575
+ self.server_index = None