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.
Files changed (35) hide show
  1. crypticorn/cli/init.py +7 -4
  2. crypticorn/common/__init__.py +1 -0
  3. crypticorn/common/auth.py +11 -9
  4. crypticorn/common/errors.py +26 -0
  5. crypticorn/common/exceptions.py +83 -0
  6. crypticorn/common/utils.py +23 -6
  7. crypticorn/klines/client/__init__.py +10 -3
  8. crypticorn/klines/client/api/__init__.py +1 -0
  9. crypticorn/klines/client/api/change_in_timeframe_api.py +331 -0
  10. crypticorn/klines/client/api/funding_rates_api.py +13 -13
  11. crypticorn/klines/client/api/health_check_api.py +8 -8
  12. crypticorn/klines/client/api/ohlcv_data_api.py +38 -26
  13. crypticorn/klines/client/api/symbols_api.py +26 -20
  14. crypticorn/klines/client/api/udf_api.py +229 -229
  15. crypticorn/klines/client/api_client.py +8 -5
  16. crypticorn/klines/client/configuration.py +80 -37
  17. crypticorn/klines/client/models/__init__.py +9 -3
  18. crypticorn/klines/client/models/base_response_list_change_in_timeframe_response.py +123 -0
  19. crypticorn/klines/client/models/change_in_timeframe_response.py +86 -0
  20. crypticorn/klines/client/models/market_type.py +35 -0
  21. crypticorn/klines/client/models/response_get_udf_history.py +198 -0
  22. crypticorn/klines/client/rest.py +111 -159
  23. crypticorn/klines/main.py +37 -22
  24. crypticorn/metrics/main.py +42 -42
  25. crypticorn/pay/client/__init__.py +0 -3
  26. crypticorn/pay/client/api/now_payments_api.py +1 -53
  27. crypticorn/pay/client/models/__init__.py +0 -3
  28. crypticorn/pay/client/models/payment.py +3 -3
  29. crypticorn/pay/client/models/scope.py +6 -1
  30. crypticorn/trade/client/models/exchange_key_model.py +2 -1
  31. {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/METADATA +8 -2
  32. {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/RECORD +35 -29
  33. {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/WHEEL +1 -1
  34. {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/entry_points.txt +0 -0
  35. {crypticorn-2.4.6.dist-info → crypticorn-2.5.0.dist-info}/top_level.txt +0 -0
crypticorn/cli/init.py CHANGED
@@ -57,7 +57,10 @@ def init_ruff(force):
57
57
  def init_docker(output, force):
58
58
  """Add Dockerfile"""
59
59
  root = get_git_root()
60
- target = Path(output) if output else root / "Dockerfile"
60
+ if output and Path(output).is_file():
61
+ click.secho("Output path is a file, please provide a directory path", fg="red")
62
+ return
63
+ target = (Path(output) if output else root) / "Dockerfile"
61
64
  if target.exists() and not force:
62
65
  click.secho("File already exists, use --force / -f to overwrite", fg="red")
63
66
  return
@@ -73,10 +76,10 @@ def init_docker(output, force):
73
76
  def init_auth(output, force):
74
77
  """Add auth.py with auth handler. Everything you need to start using the auth service."""
75
78
  root = get_git_root()
76
- if Path(output).is_dir():
77
- click.secho("Output path is a directory, please provide a file path", fg="red")
79
+ if output and Path(output).is_file():
80
+ click.secho("Output path is a file, please provide a directory path", fg="red")
78
81
  return
79
- target = Path(output) if output else root / "src/auth.py"
82
+ target = (Path(output) if output else root) / "auth.py"
80
83
  if target.exists() and not force:
81
84
  click.secho("File already exists, use --force / -f to overwrite", fg="red")
82
85
  return
@@ -5,3 +5,4 @@ from crypticorn.common.pydantic import *
5
5
  from crypticorn.common.auth import *
6
6
  from crypticorn.common.enums import *
7
7
  from crypticorn.common.utils import *
8
+ from crypticorn.common.exceptions import *
crypticorn/common/auth.py CHANGED
@@ -9,7 +9,7 @@ from crypticorn.common import (
9
9
  Scope,
10
10
  Service,
11
11
  )
12
- from fastapi import Depends, HTTPException, Query, status
12
+ from fastapi import Depends, HTTPException, Query, status, WebSocketException
13
13
  from fastapi.security import (
14
14
  HTTPAuthorizationCredentials,
15
15
  SecurityScopes,
@@ -183,7 +183,7 @@ class AuthHandler:
183
183
  Verifies the API key and checks if the user scopes are a subset of the API scopes.
184
184
  Use this function if you only want to allow access via the API key.
185
185
  """
186
- return await self.api_key_auth(api_key=api_key, sec=sec)
186
+ return await self.ws_combined_auth(bearer=None, api_key=api_key, sec=sec)
187
187
 
188
188
  async def ws_bearer_auth(
189
189
  self,
@@ -194,12 +194,7 @@ class AuthHandler:
194
194
  Verifies the bearer token and checks if the user scopes are a subset of the API scopes.
195
195
  Use this function if you only want to allow access via the bearer token.
196
196
  """
197
- credentials = (
198
- HTTPAuthorizationCredentials(scheme="Bearer", credentials=bearer)
199
- if bearer
200
- else None
201
- )
202
- return await self.bearer_auth(bearer=credentials, sec=sec)
197
+ return await self.ws_combined_auth(bearer=bearer, api_key=None, sec=sec)
203
198
 
204
199
  async def ws_combined_auth(
205
200
  self,
@@ -216,4 +211,11 @@ class AuthHandler:
216
211
  if bearer
217
212
  else None
218
213
  )
219
- return await self.combined_auth(bearer=credentials, api_key=api_key, sec=sec)
214
+ response = await self.combined_auth(
215
+ bearer=credentials, api_key=api_key, sec=sec
216
+ )
217
+ if isinstance(response, HTTPException):
218
+ raise WebSocketException(
219
+ code=status.WS_1008_POLICY_VIOLATION, reason=response.detail
220
+ )
221
+ return response
@@ -36,6 +36,7 @@ class ApiErrorIdentifier(StrEnum):
36
36
 
37
37
  ALLOCATION_BELOW_EXPOSURE = "allocation_below_current_exposure"
38
38
  ALLOCATION_BELOW_MINIMUM = "allocation_below_min_amount"
39
+ ALPHANUMERIC_CHARACTERS_ONLY = "alphanumeric_characters_only"
39
40
  BLACK_SWAN = "black_swan"
40
41
  BOT_ALREADY_DELETED = "bot_already_deleted"
41
42
  BOT_DISABLED = "bot_disabled"
@@ -56,6 +57,7 @@ class ApiErrorIdentifier(StrEnum):
56
57
  EXCHANGE_SYSTEM_CONFIG_ERROR = "exchange_system_configuration_error"
57
58
  EXCHANGE_SYSTEM_ERROR = "exchange_internal_system_error"
58
59
  EXCHANGE_USER_FROZEN = "exchange_user_account_is_frozen"
60
+ FORBIDDEN = "forbidden"
59
61
  HEDGE_MODE_NOT_ACTIVE = "hedge_mode_not_active"
60
62
  HTTP_ERROR = "http_request_error"
61
63
  INSUFFICIENT_BALANCE = "insufficient_balance"
@@ -63,6 +65,8 @@ class ApiErrorIdentifier(StrEnum):
63
65
  INSUFFICIENT_SCOPES = "insufficient_scopes"
64
66
  INVALID_API_KEY = "invalid_api_key"
65
67
  INVALID_BEARER = "invalid_bearer"
68
+ INVALID_DATA_REQUEST = "invalid_data"
69
+ INVALID_DATA_RESPONSE = "invalid_data_response"
66
70
  INVALID_EXCHANGE_KEY = "invalid_exchange_key"
67
71
  INVALID_MARGIN_MODE = "invalid_margin_mode"
68
72
  INVALID_PARAMETER = "invalid_parameter_provided"
@@ -100,6 +104,11 @@ class ApiErrorIdentifier(StrEnum):
100
104
  UNKNOWN_ERROR = "unknown_error_occurred"
101
105
  URL_NOT_FOUND = "requested_resource_not_found"
102
106
 
107
+ @property
108
+ def get_error_code(self) -> str:
109
+ """Get the corresponding ApiError."""
110
+ return ApiError[self.value]
111
+
103
112
 
104
113
  class ApiErrorLevel(StrEnum):
105
114
  """API error levels"""
@@ -123,6 +132,11 @@ class ApiError(Enum, metaclass=Fallback):
123
132
  ApiErrorType.USER_ERROR,
124
133
  ApiErrorLevel.ERROR,
125
134
  )
135
+ ALPHANUMERIC_CHARACTERS_ONLY = (
136
+ ApiErrorIdentifier.ALPHANUMERIC_CHARACTERS_ONLY,
137
+ ApiErrorType.USER_ERROR,
138
+ ApiErrorLevel.ERROR,
139
+ )
126
140
  BLACK_SWAN = (
127
141
  ApiErrorIdentifier.BLACK_SWAN,
128
142
  ApiErrorType.USER_ERROR,
@@ -258,6 +272,16 @@ class ApiError(Enum, metaclass=Fallback):
258
272
  ApiErrorType.USER_ERROR,
259
273
  ApiErrorLevel.ERROR,
260
274
  )
275
+ INVALID_DATA_REQUEST = (
276
+ ApiErrorIdentifier.INVALID_DATA_REQUEST,
277
+ ApiErrorType.USER_ERROR,
278
+ ApiErrorLevel.ERROR,
279
+ )
280
+ INVALID_DATA_RESPONSE = (
281
+ ApiErrorIdentifier.INVALID_DATA_RESPONSE,
282
+ ApiErrorType.USER_ERROR,
283
+ ApiErrorLevel.ERROR,
284
+ )
261
285
  INVALID_EXCHANGE_KEY = (
262
286
  ApiErrorIdentifier.INVALID_EXCHANGE_KEY,
263
287
  ApiErrorType.SERVER_ERROR,
@@ -484,6 +508,8 @@ class HttpStatusMapper:
484
508
  ApiError.BOT_ALREADY_DELETED: status.HTTP_409_CONFLICT,
485
509
  # Invalid Content
486
510
  ApiError.CONTENT_TYPE_ERROR: status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
511
+ ApiError.INVALID_DATA_REQUEST: status.HTTP_422_UNPROCESSABLE_ENTITY,
512
+ ApiError.INVALID_DATA_RESPONSE: status.HTTP_422_UNPROCESSABLE_ENTITY,
487
513
  # Rate Limits
488
514
  ApiError.EXCHANGE_RATE_LIMIT: status.HTTP_429_TOO_MANY_REQUESTS,
489
515
  ApiError.REQUEST_SCOPE_EXCEEDED: status.HTTP_429_TOO_MANY_REQUESTS,
@@ -0,0 +1,83 @@
1
+ from enum import Enum
2
+ from typing import Optional, Dict, Type, Any
3
+ from pydantic import BaseModel, Field
4
+ from fastapi import HTTPException as FastAPIHTTPException, Request, FastAPI
5
+ from fastapi.exceptions import RequestValidationError, ResponseValidationError
6
+ from fastapi.openapi.utils import get_openapi
7
+ from fastapi.responses import JSONResponse
8
+ from crypticorn.common import ApiError, ApiErrorIdentifier, ApiErrorType, ApiErrorLevel
9
+
10
+ class ExceptionDetail(BaseModel):
11
+ '''This is the detail of the exception. It is used to enrich the exception with additional information by unwrapping the ApiError into its components.'''
12
+ message: Optional[str] = Field(None, description="An additional error message")
13
+ code: ApiErrorIdentifier = Field(..., description="The unique error code")
14
+ type: ApiErrorType = Field(..., description="The type of error")
15
+ level: ApiErrorLevel = Field(..., description="The level of the error")
16
+ status_code: int = Field(..., description="The HTTP status code")
17
+ details: Any = Field(None, description="Additional details about the error")
18
+
19
+
20
+ class ExceptionContent(BaseModel):
21
+ '''This is the detail of the exception. Pass an ApiError to the constructor and an optional human readable message.'''
22
+ error: ApiError = Field(..., description="The unique error code")
23
+ message: Optional[str] = Field(None, description="An additional error message")
24
+ details: Any = Field(None, description="Additional details about the error")
25
+
26
+ def enrich(self) -> ExceptionDetail:
27
+ return ExceptionDetail(
28
+ message=self.message,
29
+ code=self.error.identifier,
30
+ type=self.error.type,
31
+ level=self.error.level,
32
+ status_code=self.error.status_code,
33
+ details=self.details,
34
+ )
35
+
36
+ class HTTPException(FastAPIHTTPException):
37
+ """A custom HTTP exception wrapper around FastAPI's HTTPException.
38
+ It allows for a more structured way to handle errors, with a message and an error code. The status code is being derived from the detail's error.
39
+ The ApiError class is the source of truth for everything. If the error is not yet implemented, there are fallbacks to avoid errors while testing.
40
+ """
41
+
42
+ def __init__(
43
+ self,
44
+ content: ExceptionContent,
45
+ headers: Optional[Dict[str, str]] = None,
46
+ ):
47
+ assert isinstance(content, ExceptionContent)
48
+ body = content.enrich()
49
+ super().__init__(
50
+ status_code=body.status_code,
51
+ detail=body.model_dump(mode="json"),
52
+ headers=headers,
53
+ )
54
+
55
+ async def general_handler(request: Request, exc: Exception):
56
+ '''This is the default exception handler for all exceptions.'''
57
+ body = ExceptionContent(message=str(exc), error=ApiError.UNKNOWN_ERROR)
58
+ return JSONResponse(status_code=body.error.status_code, content=HTTPException(content=body).detail)
59
+
60
+ async def request_validation_handler(request: Request, exc: RequestValidationError):
61
+ '''This is the exception handler for all request validation errors.'''
62
+ body = ExceptionContent(message=str(exc), error=ApiError.INVALID_DATA_REQUEST)
63
+ return JSONResponse(status_code=body.error.status_code, content=HTTPException(content=body).detail)
64
+
65
+ async def response_validation_handler(request: Request, exc: ResponseValidationError):
66
+ '''This is the exception handler for all response validation errors.'''
67
+ body = ExceptionContent(message=str(exc), error=ApiError.INVALID_DATA_RESPONSE)
68
+ return JSONResponse(status_code=body.error.status_code, content=HTTPException(content=body).detail)
69
+
70
+ async def http_handler(request: Request, exc: HTTPException):
71
+ '''This is the exception handler for HTTPExceptions. It unwraps the HTTPException and returns the detail in a flat JSON response.'''
72
+ return JSONResponse(status_code=exc.status_code, content=exc.detail)
73
+
74
+ def register_exception_handlers(app: FastAPI):
75
+ '''Utility to register serveral exception handlers in one go. Catches Exception, HTTPException and Data Validation errors and responds with a unified json body.'''
76
+ app.add_exception_handler(Exception, general_handler)
77
+ app.add_exception_handler(FastAPIHTTPException, http_handler)
78
+ app.add_exception_handler(RequestValidationError, request_validation_handler)
79
+ app.add_exception_handler(ResponseValidationError, response_validation_handler)
80
+
81
+ exception_response = {
82
+ "default": {"model": ExceptionDetail, "description": "Error response"}
83
+ }
@@ -1,27 +1,29 @@
1
- from typing import Any
1
+ from typing import Any, Union
2
2
  from decimal import Decimal
3
3
  import string
4
4
  import random
5
-
6
5
  from fastapi import HTTPException
7
6
  from fastapi import status
7
+ from typing_extensions import deprecated
8
8
 
9
9
  from crypticorn.common import ApiError
10
10
 
11
11
 
12
- def throw_if_none(value: Any, message: ApiError) -> None:
12
+ def throw_if_none(value: Any, message: Union[ApiError, str]) -> None:
13
13
  """Throws an FastAPI HTTPException if the value is None."""
14
14
  if value is None:
15
15
  raise HTTPException(
16
- status_code=status.HTTP_404_NOT_FOUND, detail=message.identifier
16
+ status_code=status.HTTP_404_NOT_FOUND,
17
+ detail=message.identifier if isinstance(message, ApiError) else message,
17
18
  )
18
19
 
19
20
 
20
- def throw_if_falsy(value: Any, message: ApiError) -> None:
21
+ def throw_if_falsy(value: Any, message: Union[ApiError, str]) -> None:
21
22
  """Throws an FastAPI HTTPException if the value is False."""
22
23
  if not value:
23
24
  raise HTTPException(
24
- status_code=status.HTTP_400_BAD_REQUEST, detail=message.identifier
25
+ status_code=status.HTTP_400_BAD_REQUEST,
26
+ detail=message.identifier if isinstance(message, ApiError) else message,
25
27
  )
26
28
 
27
29
 
@@ -32,6 +34,7 @@ def gen_random_id(length: int = 20) -> str:
32
34
  return "".join(random.choice(charset) for _ in range(length))
33
35
 
34
36
 
37
+ @deprecated("Use math.isclose instead. Will be removed in a future version.")
35
38
  def is_equal(
36
39
  a: float | Decimal,
37
40
  b: float | Decimal,
@@ -50,3 +53,17 @@ def is_equal(
50
53
  return Decimal(abs(a - b)) <= max(
51
54
  Decimal(str(rel_tol)) * max(abs(a), abs(b)), Decimal(str(abs_tol))
52
55
  )
56
+
57
+
58
+ def optional_import(module_name: str, extra_name: str) -> Any:
59
+ """
60
+ Import a module optionally.
61
+ """
62
+ try:
63
+ return __import__(module_name)
64
+ except ImportError as e:
65
+ extra = f"[{extra_name}]"
66
+ raise ImportError(
67
+ f"Optional dependency '{module_name}' is required for this feature. "
68
+ f"Install it with: pip install crypticorn{extra}"
69
+ ) from e
@@ -17,6 +17,7 @@ Do not edit the class manually.
17
17
  __version__ = "1.0.0"
18
18
 
19
19
  # import apis into sdk package
20
+ from crypticorn.klines.client.api.change_in_timeframe_api import ChangeInTimeframeApi
20
21
  from crypticorn.klines.client.api.funding_rates_api import FundingRatesApi
21
22
  from crypticorn.klines.client.api.health_check_api import HealthCheckApi
22
23
  from crypticorn.klines.client.api.ohlcv_data_api import OHLCVDataApi
@@ -38,6 +39,9 @@ from crypticorn.klines.client.exceptions import ApiException
38
39
  from crypticorn.klines.client.models.base_response_health_check_response import (
39
40
  BaseResponseHealthCheckResponse,
40
41
  )
42
+ from crypticorn.klines.client.models.base_response_list_change_in_timeframe_response import (
43
+ BaseResponseListChangeInTimeframeResponse,
44
+ )
41
45
  from crypticorn.klines.client.models.base_response_list_funding_rate_response import (
42
46
  BaseResponseListFundingRateResponse,
43
47
  )
@@ -45,6 +49,9 @@ from crypticorn.klines.client.models.base_response_list_str import BaseResponseL
45
49
  from crypticorn.klines.client.models.base_response_ohlcv_response import (
46
50
  BaseResponseOHLCVResponse,
47
51
  )
52
+ from crypticorn.klines.client.models.change_in_timeframe_response import (
53
+ ChangeInTimeframeResponse,
54
+ )
48
55
  from crypticorn.klines.client.models.error_response import ErrorResponse
49
56
  from crypticorn.klines.client.models.exchange import Exchange
50
57
  from crypticorn.klines.client.models.funding_rate_response import FundingRateResponse
@@ -57,11 +64,11 @@ from crypticorn.klines.client.models.history_no_data_response import (
57
64
  from crypticorn.klines.client.models.history_success_response import (
58
65
  HistorySuccessResponse,
59
66
  )
60
- from crypticorn.klines.client.models.market import Market
67
+ from crypticorn.klines.client.models.market_type import MarketType
61
68
  from crypticorn.klines.client.models.ohlcv_response import OHLCVResponse
62
69
  from crypticorn.klines.client.models.resolution import Resolution
63
- from crypticorn.klines.client.models.response_get_history_udf_history_get import (
64
- ResponseGetHistoryUdfHistoryGet,
70
+ from crypticorn.klines.client.models.response_get_udf_history import (
71
+ ResponseGetUdfHistory,
65
72
  )
66
73
  from crypticorn.klines.client.models.search_symbol_response import SearchSymbolResponse
67
74
  from crypticorn.klines.client.models.sort_direction import SortDirection
@@ -1,6 +1,7 @@
1
1
  # flake8: noqa
2
2
 
3
3
  # import apis into api package
4
+ from crypticorn.klines.client.api.change_in_timeframe_api import ChangeInTimeframeApi
4
5
  from crypticorn.klines.client.api.funding_rates_api import FundingRatesApi
5
6
  from crypticorn.klines.client.api.health_check_api import HealthCheckApi
6
7
  from crypticorn.klines.client.api.ohlcv_data_api import OHLCVDataApi
@@ -0,0 +1,331 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Klines Service API
5
+
6
+ API for retrieving OHLCV data, funding rates, and symbol information from Binance. ## WebSocket Support Connect to `/ws` to receive real-time OHLCV updates. Example subscription message: ```json { \"action\": \"subscribe\", \"market\": \"spot\", \"symbol\": \"BTCUSDT\", \"timeframe\": \"15m\" } ```
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
+ import warnings
15
+ from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
16
+ from typing import Any, Dict, List, Optional, Tuple, Union
17
+ from typing_extensions import Annotated
18
+
19
+ from pydantic import Field
20
+ from typing import Optional
21
+ from typing_extensions import Annotated
22
+ from crypticorn.klines.client.models.base_response_list_change_in_timeframe_response import (
23
+ BaseResponseListChangeInTimeframeResponse,
24
+ )
25
+ from crypticorn.klines.client.models.market_type import MarketType
26
+ from crypticorn.klines.client.models.timeframe import Timeframe
27
+
28
+ from crypticorn.klines.client.api_client import ApiClient, RequestSerialized
29
+ from crypticorn.klines.client.api_response import ApiResponse
30
+ from crypticorn.klines.client.rest import RESTResponseType
31
+
32
+
33
+ class ChangeInTimeframeApi:
34
+ """NOTE: This class is auto generated by OpenAPI Generator
35
+ Ref: https://openapi-generator.tech
36
+
37
+ Do not edit the class manually.
38
+ """
39
+
40
+ def __init__(self, api_client=None) -> None:
41
+ if api_client is None:
42
+ api_client = ApiClient.get_default()
43
+ self.api_client = api_client
44
+
45
+ @validate_call
46
+ async def get_change_in_timeframe(
47
+ self,
48
+ market: Annotated[
49
+ Optional[MarketType], Field(description="Market type: 'spot' or 'futures'")
50
+ ] = None,
51
+ timeframe: Annotated[
52
+ Optional[Timeframe],
53
+ Field(description="Timeframe: '15m', '30m', '1h', '4h', '1d'"),
54
+ ] = None,
55
+ _request_timeout: Union[
56
+ None,
57
+ Annotated[StrictFloat, Field(gt=0)],
58
+ Tuple[
59
+ Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
60
+ ],
61
+ ] = None,
62
+ _request_auth: Optional[Dict[StrictStr, Any]] = None,
63
+ _content_type: Optional[StrictStr] = None,
64
+ _headers: Optional[Dict[StrictStr, Any]] = None,
65
+ _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
66
+ ) -> BaseResponseListChangeInTimeframeResponse:
67
+ """Get Change In Timeframe
68
+
69
+ Retrieve price change percentage between last two completed timestamps for all pairs. Valid markets: spot, futures Valid timeframes: 15m, 30m, 1h, 4h, 1d
70
+
71
+ :param market: Market type: 'spot' or 'futures'
72
+ :type market: MarketType
73
+ :param timeframe: Timeframe: '15m', '30m', '1h', '4h', '1d'
74
+ :type timeframe: Timeframe
75
+ :param _request_timeout: timeout setting for this request. If one
76
+ number provided, it will be total request
77
+ timeout. It can also be a pair (tuple) of
78
+ (connection, read) timeouts.
79
+ :type _request_timeout: int, tuple(int, int), optional
80
+ :param _request_auth: set to override the auth_settings for an a single
81
+ request; this effectively ignores the
82
+ authentication in the spec for a single request.
83
+ :type _request_auth: dict, optional
84
+ :param _content_type: force content-type for the request.
85
+ :type _content_type: str, Optional
86
+ :param _headers: set to override the headers for a single
87
+ request; this effectively ignores the headers
88
+ in the spec for a single request.
89
+ :type _headers: dict, optional
90
+ :param _host_index: set to override the host_index for a single
91
+ request; this effectively ignores the host_index
92
+ in the spec for a single request.
93
+ :type _host_index: int, optional
94
+ :return: Returns the result object.
95
+ """ # noqa: E501
96
+
97
+ _param = self._get_change_in_timeframe_serialize(
98
+ market=market,
99
+ timeframe=timeframe,
100
+ _request_auth=_request_auth,
101
+ _content_type=_content_type,
102
+ _headers=_headers,
103
+ _host_index=_host_index,
104
+ )
105
+
106
+ _response_types_map: Dict[str, Optional[str]] = {
107
+ "200": "BaseResponseListChangeInTimeframeResponse",
108
+ "400": "ErrorResponse",
109
+ "404": "ErrorResponse",
110
+ "500": "ErrorResponse",
111
+ "422": "HTTPValidationError",
112
+ }
113
+ response_data = await self.api_client.call_api(
114
+ *_param, _request_timeout=_request_timeout
115
+ )
116
+ await response_data.read()
117
+ return self.api_client.response_deserialize(
118
+ response_data=response_data,
119
+ response_types_map=_response_types_map,
120
+ ).data
121
+
122
+ @validate_call
123
+ async def get_change_in_timeframe_with_http_info(
124
+ self,
125
+ market: Annotated[
126
+ Optional[MarketType], Field(description="Market type: 'spot' or 'futures'")
127
+ ] = None,
128
+ timeframe: Annotated[
129
+ Optional[Timeframe],
130
+ Field(description="Timeframe: '15m', '30m', '1h', '4h', '1d'"),
131
+ ] = None,
132
+ _request_timeout: Union[
133
+ None,
134
+ Annotated[StrictFloat, Field(gt=0)],
135
+ Tuple[
136
+ Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
137
+ ],
138
+ ] = None,
139
+ _request_auth: Optional[Dict[StrictStr, Any]] = None,
140
+ _content_type: Optional[StrictStr] = None,
141
+ _headers: Optional[Dict[StrictStr, Any]] = None,
142
+ _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
143
+ ) -> ApiResponse[BaseResponseListChangeInTimeframeResponse]:
144
+ """Get Change In Timeframe
145
+
146
+ Retrieve price change percentage between last two completed timestamps for all pairs. Valid markets: spot, futures Valid timeframes: 15m, 30m, 1h, 4h, 1d
147
+
148
+ :param market: Market type: 'spot' or 'futures'
149
+ :type market: MarketType
150
+ :param timeframe: Timeframe: '15m', '30m', '1h', '4h', '1d'
151
+ :type timeframe: Timeframe
152
+ :param _request_timeout: timeout setting for this request. If one
153
+ number provided, it will be total request
154
+ timeout. It can also be a pair (tuple) of
155
+ (connection, read) timeouts.
156
+ :type _request_timeout: int, tuple(int, int), optional
157
+ :param _request_auth: set to override the auth_settings for an a single
158
+ request; this effectively ignores the
159
+ authentication in the spec for a single request.
160
+ :type _request_auth: dict, optional
161
+ :param _content_type: force content-type for the request.
162
+ :type _content_type: str, Optional
163
+ :param _headers: set to override the headers for a single
164
+ request; this effectively ignores the headers
165
+ in the spec for a single request.
166
+ :type _headers: dict, optional
167
+ :param _host_index: set to override the host_index for a single
168
+ request; this effectively ignores the host_index
169
+ in the spec for a single request.
170
+ :type _host_index: int, optional
171
+ :return: Returns the result object.
172
+ """ # noqa: E501
173
+
174
+ _param = self._get_change_in_timeframe_serialize(
175
+ market=market,
176
+ timeframe=timeframe,
177
+ _request_auth=_request_auth,
178
+ _content_type=_content_type,
179
+ _headers=_headers,
180
+ _host_index=_host_index,
181
+ )
182
+
183
+ _response_types_map: Dict[str, Optional[str]] = {
184
+ "200": "BaseResponseListChangeInTimeframeResponse",
185
+ "400": "ErrorResponse",
186
+ "404": "ErrorResponse",
187
+ "500": "ErrorResponse",
188
+ "422": "HTTPValidationError",
189
+ }
190
+ response_data = await self.api_client.call_api(
191
+ *_param, _request_timeout=_request_timeout
192
+ )
193
+ await response_data.read()
194
+ return self.api_client.response_deserialize(
195
+ response_data=response_data,
196
+ response_types_map=_response_types_map,
197
+ )
198
+
199
+ @validate_call
200
+ async def get_change_in_timeframe_without_preload_content(
201
+ self,
202
+ market: Annotated[
203
+ Optional[MarketType], Field(description="Market type: 'spot' or 'futures'")
204
+ ] = None,
205
+ timeframe: Annotated[
206
+ Optional[Timeframe],
207
+ Field(description="Timeframe: '15m', '30m', '1h', '4h', '1d'"),
208
+ ] = None,
209
+ _request_timeout: Union[
210
+ None,
211
+ Annotated[StrictFloat, Field(gt=0)],
212
+ Tuple[
213
+ Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)]
214
+ ],
215
+ ] = None,
216
+ _request_auth: Optional[Dict[StrictStr, Any]] = None,
217
+ _content_type: Optional[StrictStr] = None,
218
+ _headers: Optional[Dict[StrictStr, Any]] = None,
219
+ _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
220
+ ) -> RESTResponseType:
221
+ """Get Change In Timeframe
222
+
223
+ Retrieve price change percentage between last two completed timestamps for all pairs. Valid markets: spot, futures Valid timeframes: 15m, 30m, 1h, 4h, 1d
224
+
225
+ :param market: Market type: 'spot' or 'futures'
226
+ :type market: MarketType
227
+ :param timeframe: Timeframe: '15m', '30m', '1h', '4h', '1d'
228
+ :type timeframe: Timeframe
229
+ :param _request_timeout: timeout setting for this request. If one
230
+ number provided, it will be total request
231
+ timeout. It can also be a pair (tuple) of
232
+ (connection, read) timeouts.
233
+ :type _request_timeout: int, tuple(int, int), optional
234
+ :param _request_auth: set to override the auth_settings for an a single
235
+ request; this effectively ignores the
236
+ authentication in the spec for a single request.
237
+ :type _request_auth: dict, optional
238
+ :param _content_type: force content-type for the request.
239
+ :type _content_type: str, Optional
240
+ :param _headers: set to override the headers for a single
241
+ request; this effectively ignores the headers
242
+ in the spec for a single request.
243
+ :type _headers: dict, optional
244
+ :param _host_index: set to override the host_index for a single
245
+ request; this effectively ignores the host_index
246
+ in the spec for a single request.
247
+ :type _host_index: int, optional
248
+ :return: Returns the result object.
249
+ """ # noqa: E501
250
+
251
+ _param = self._get_change_in_timeframe_serialize(
252
+ market=market,
253
+ timeframe=timeframe,
254
+ _request_auth=_request_auth,
255
+ _content_type=_content_type,
256
+ _headers=_headers,
257
+ _host_index=_host_index,
258
+ )
259
+
260
+ _response_types_map: Dict[str, Optional[str]] = {
261
+ "200": "BaseResponseListChangeInTimeframeResponse",
262
+ "400": "ErrorResponse",
263
+ "404": "ErrorResponse",
264
+ "500": "ErrorResponse",
265
+ "422": "HTTPValidationError",
266
+ }
267
+ response_data = await self.api_client.call_api(
268
+ *_param, _request_timeout=_request_timeout
269
+ )
270
+ return response_data.response
271
+
272
+ def _get_change_in_timeframe_serialize(
273
+ self,
274
+ market,
275
+ timeframe,
276
+ _request_auth,
277
+ _content_type,
278
+ _headers,
279
+ _host_index,
280
+ ) -> RequestSerialized:
281
+
282
+ _host = None
283
+
284
+ _collection_formats: Dict[str, str] = {}
285
+
286
+ _path_params: Dict[str, str] = {}
287
+ _query_params: List[Tuple[str, str]] = []
288
+ _header_params: Dict[str, Optional[str]] = _headers or {}
289
+ _form_params: List[Tuple[str, str]] = []
290
+ _files: Dict[
291
+ str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]]
292
+ ] = {}
293
+ _body_params: Optional[bytes] = None
294
+
295
+ # process the path parameters
296
+ # process the query parameters
297
+ if market is not None:
298
+
299
+ _query_params.append(("market", market.value))
300
+
301
+ if timeframe is not None:
302
+
303
+ _query_params.append(("timeframe", timeframe.value))
304
+
305
+ # process the header parameters
306
+ # process the form parameters
307
+ # process the body parameter
308
+
309
+ # set the HTTP header `Accept`
310
+ if "Accept" not in _header_params:
311
+ _header_params["Accept"] = self.api_client.select_header_accept(
312
+ ["application/json"]
313
+ )
314
+
315
+ # authentication setting
316
+ _auth_settings: List[str] = ["APIKeyHeader", "HTTPBearer"]
317
+
318
+ return self.api_client.param_serialize(
319
+ method="GET",
320
+ resource_path="/change",
321
+ path_params=_path_params,
322
+ query_params=_query_params,
323
+ header_params=_header_params,
324
+ body=_body_params,
325
+ post_params=_form_params,
326
+ files=_files,
327
+ auth_settings=_auth_settings,
328
+ collection_formats=_collection_formats,
329
+ _host=_host,
330
+ _request_auth=_request_auth,
331
+ )