crypticorn 2.4.6__py3-none-any.whl → 2.4.7__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/common/auth.py +7 -9
- crypticorn/common/errors.py +5 -0
- crypticorn/common/utils.py +15 -5
- crypticorn/klines/main.py +10 -5
- crypticorn/metrics/main.py +5 -4
- crypticorn/trade/client/__init__.py +6 -8
- crypticorn/trade/client/api/__init__.py +1 -0
- crypticorn/trade/client/api/api_keys_api.py +273 -167
- crypticorn/trade/client/api/bots_api.py +226 -140
- crypticorn/trade/client/api/exchanges_api.py +51 -31
- crypticorn/trade/client/api/futures_trading_panel_api.py +272 -169
- crypticorn/trade/client/api/notifications_api.py +323 -200
- crypticorn/trade/client/api/orders_api.py +60 -40
- crypticorn/trade/client/api/status_api.py +49 -31
- crypticorn/trade/client/api/strategies_api.py +223 -137
- crypticorn/trade/client/api/trading_actions_api.py +170 -106
- crypticorn/trade/client/api_client.py +153 -111
- crypticorn/trade/client/api_response.py +3 -2
- crypticorn/trade/client/configuration.py +115 -128
- crypticorn/trade/client/exceptions.py +21 -25
- crypticorn/trade/client/models/__init__.py +6 -8
- crypticorn/trade/client/models/action_model.py +54 -108
- crypticorn/trade/client/models/api_error_identifier.py +72 -76
- crypticorn/trade/client/models/api_error_level.py +11 -9
- crypticorn/trade/client/models/api_error_type.py +11 -9
- crypticorn/trade/client/models/bot_model.py +36 -57
- crypticorn/trade/client/models/bot_status.py +11 -9
- crypticorn/trade/client/models/exchange.py +9 -7
- crypticorn/trade/client/models/exchange_key_model.py +34 -44
- crypticorn/trade/client/models/execution_ids.py +18 -18
- crypticorn/trade/client/models/futures_balance.py +27 -43
- crypticorn/trade/client/models/futures_trading_action.py +50 -102
- crypticorn/trade/client/models/http_validation_error.py +15 -19
- crypticorn/trade/client/models/margin_mode.py +9 -7
- crypticorn/trade/client/models/market_type.py +9 -7
- crypticorn/trade/client/models/notification_model.py +32 -52
- crypticorn/trade/client/models/order_model.py +72 -112
- crypticorn/trade/client/models/order_status.py +12 -10
- crypticorn/trade/client/models/post_futures_action.py +16 -20
- crypticorn/trade/client/models/strategy_exchange_info.py +16 -15
- crypticorn/trade/client/models/strategy_model_input.py +33 -61
- crypticorn/trade/client/models/strategy_model_output.py +33 -61
- crypticorn/trade/client/models/tpsl.py +25 -39
- crypticorn/trade/client/models/trading_action_type.py +11 -9
- crypticorn/trade/client/models/validation_error.py +18 -24
- crypticorn/trade/client/models/validation_error_loc_inner.py +16 -37
- crypticorn/trade/client/rest.py +38 -23
- {crypticorn-2.4.6.dist-info → crypticorn-2.4.7.dist-info}/METADATA +8 -2
- {crypticorn-2.4.6.dist-info → crypticorn-2.4.7.dist-info}/RECORD +52 -52
- {crypticorn-2.4.6.dist-info → crypticorn-2.4.7.dist-info}/WHEEL +0 -0
- {crypticorn-2.4.6.dist-info → crypticorn-2.4.7.dist-info}/entry_points.txt +0 -0
- {crypticorn-2.4.6.dist-info → crypticorn-2.4.7.dist-info}/top_level.txt +0 -0
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.
|
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
|
-
|
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,7 @@ class AuthHandler:
|
|
216
211
|
if bearer
|
217
212
|
else None
|
218
213
|
)
|
219
|
-
|
214
|
+
response = await self.combined_auth(bearer=credentials, api_key=api_key, sec=sec)
|
215
|
+
if isinstance(response, HTTPException):
|
216
|
+
raise WebSocketException(code=status.WS_1008_POLICY_VIOLATION, reason=response.detail)
|
217
|
+
return response
|
crypticorn/common/errors.py
CHANGED
@@ -100,6 +100,11 @@ class ApiErrorIdentifier(StrEnum):
|
|
100
100
|
UNKNOWN_ERROR = "unknown_error_occurred"
|
101
101
|
URL_NOT_FOUND = "requested_resource_not_found"
|
102
102
|
|
103
|
+
@property
|
104
|
+
def get_error_code(self) -> str:
|
105
|
+
"""Get the corresponding ApiError."""
|
106
|
+
return ApiError[self.value]
|
107
|
+
|
103
108
|
|
104
109
|
class ApiErrorLevel(StrEnum):
|
105
110
|
"""API error levels"""
|
crypticorn/common/utils.py
CHANGED
@@ -1,4 +1,4 @@
|
|
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
|
@@ -9,19 +9,19 @@ from fastapi import status
|
|
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, detail=message.identifier if isinstance(message, ApiError) else message
|
17
17
|
)
|
18
18
|
|
19
19
|
|
20
|
-
def throw_if_falsy(value: Any, message: ApiError) -> None:
|
20
|
+
def throw_if_falsy(value: Any, message: Union[ApiError, str]) -> None:
|
21
21
|
"""Throws an FastAPI HTTPException if the value is False."""
|
22
22
|
if not value:
|
23
23
|
raise HTTPException(
|
24
|
-
status_code=status.HTTP_400_BAD_REQUEST, detail=message.identifier
|
24
|
+
status_code=status.HTTP_400_BAD_REQUEST, detail=message.identifier if isinstance(message, ApiError) else message
|
25
25
|
)
|
26
26
|
|
27
27
|
|
@@ -50,3 +50,13 @@ def is_equal(
|
|
50
50
|
return Decimal(abs(a - b)) <= max(
|
51
51
|
Decimal(str(rel_tol)) * max(abs(a), abs(b)), Decimal(str(abs_tol))
|
52
52
|
)
|
53
|
+
|
54
|
+
def optional_import(module_name: str, extra_name: str):
|
55
|
+
try:
|
56
|
+
return __import__(module_name)
|
57
|
+
except ImportError as e:
|
58
|
+
extra = f"[{extra_name}]"
|
59
|
+
raise ImportError(
|
60
|
+
f"Optional dependency '{module_name}' is required for this feature. "
|
61
|
+
f"Install it with: pip install crypticorn{extra}"
|
62
|
+
) from e
|
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,6 +8,7 @@ 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):
|
@@ -15,7 +16,8 @@ class FundingRatesApiWrapper(FundingRatesApi):
|
|
15
16
|
A wrapper for the FundingRatesApi class.
|
16
17
|
"""
|
17
18
|
|
18
|
-
def get_funding_rates_fmt(self):
|
19
|
+
def get_funding_rates_fmt(self) -> pd.DataFrame:
|
20
|
+
pd = optional_import("pandas", "extra")
|
19
21
|
response = self.funding_rate_funding_rates_symbol_get()
|
20
22
|
return pd.DataFrame(response.json())
|
21
23
|
|
@@ -25,7 +27,8 @@ class OHLCVDataApiWrapper(OHLCVDataApi):
|
|
25
27
|
A wrapper for the OHLCVDataApi class.
|
26
28
|
"""
|
27
29
|
|
28
|
-
def get_ohlcv_data_fmt(self):
|
30
|
+
def get_ohlcv_data_fmt(self) -> pd.DataFrame:
|
31
|
+
pd = optional_import("pandas", "extra")
|
29
32
|
response = self.get_ohlcv_market_timeframe_symbol_get()
|
30
33
|
return pd.DataFrame(response.json())
|
31
34
|
|
@@ -35,7 +38,8 @@ class SymbolsApiWrapper(SymbolsApi):
|
|
35
38
|
A wrapper for the SymbolsApi class.
|
36
39
|
"""
|
37
40
|
|
38
|
-
def get_symbols_fmt(self):
|
41
|
+
def get_symbols_fmt(self) -> pd.DataFrame:
|
42
|
+
pd = optional_import("pandas", "extra")
|
39
43
|
response = self.symbols_symbols_market_get()
|
40
44
|
return pd.DataFrame(response.json())
|
41
45
|
|
@@ -45,7 +49,8 @@ class UDFApiWrapper(UDFApi):
|
|
45
49
|
A wrapper for the UDFApi class.
|
46
50
|
"""
|
47
51
|
|
48
|
-
def get_udf_fmt(self):
|
52
|
+
def get_udf_fmt(self) -> pd.DataFrame:
|
53
|
+
pd = optional_import("pandas", "extra")
|
49
54
|
response = self.get_history_udf_history_get()
|
50
55
|
return pd.DataFrame(response.json())
|
51
56
|
|
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,13 +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
|
-
|
20
19
|
class MetricsClient:
|
21
20
|
"""
|
22
21
|
A client for interacting with the Crypticorn Metrics API.
|
@@ -67,7 +66,8 @@ class MarketcapApiWrapper(MarketcapApi):
|
|
67
66
|
"""
|
68
67
|
Get the marketcap symbols in a pandas dataframe
|
69
68
|
"""
|
70
|
-
|
69
|
+
pd = optional_import("pandas", "extra")
|
70
|
+
response = await self.get_marketcap_symbols(
|
71
71
|
start_timestamp=start_timestamp,
|
72
72
|
end_timestamp=end_timestamp,
|
73
73
|
interval=interval,
|
@@ -96,6 +96,7 @@ class TokensApiWrapper(TokensApi):
|
|
96
96
|
"""
|
97
97
|
Get the tokens in a pandas dataframe
|
98
98
|
"""
|
99
|
+
pd = optional_import("pandas", "extra")
|
99
100
|
response = await self.get_stable_and_wrapped_tokens_without_preload_content(
|
100
101
|
token_type=token_type
|
101
102
|
)
|
@@ -3,14 +3,14 @@
|
|
3
3
|
# flake8: noqa
|
4
4
|
|
5
5
|
"""
|
6
|
-
Trading API
|
6
|
+
Trading API
|
7
7
|
|
8
|
-
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
8
|
+
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
9
9
|
|
10
|
-
The version of the OpenAPI document: 0.1.0
|
11
|
-
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
10
|
+
The version of the OpenAPI document: 0.1.0
|
11
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
12
12
|
|
13
|
-
Do not edit the class manually.
|
13
|
+
Do not edit the class manually.
|
14
14
|
""" # noqa: E501
|
15
15
|
|
16
16
|
|
@@ -63,6 +63,4 @@ from crypticorn.trade.client.models.strategy_model_output import StrategyModelOu
|
|
63
63
|
from crypticorn.trade.client.models.tpsl import TPSL
|
64
64
|
from crypticorn.trade.client.models.trading_action_type import TradingActionType
|
65
65
|
from crypticorn.trade.client.models.validation_error import ValidationError
|
66
|
-
from crypticorn.trade.client.models.validation_error_loc_inner import
|
67
|
-
ValidationErrorLocInner,
|
68
|
-
)
|
66
|
+
from crypticorn.trade.client.models.validation_error_loc_inner import ValidationErrorLocInner
|
@@ -10,3 +10,4 @@ from crypticorn.trade.client.api.orders_api import OrdersApi
|
|
10
10
|
from crypticorn.trade.client.api.status_api import StatusApi
|
11
11
|
from crypticorn.trade.client.api.strategies_api import StrategiesApi
|
12
12
|
from crypticorn.trade.client.api.trading_actions_api import TradingActionsApi
|
13
|
+
|