crypticorn 2.16.0__py3-none-any.whl → 2.17.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 (164) hide show
  1. crypticorn/__init__.py +2 -2
  2. crypticorn/auth/client/api/admin_api.py +397 -13
  3. crypticorn/auth/client/api/auth_api.py +3610 -341
  4. crypticorn/auth/client/api/service_api.py +249 -7
  5. crypticorn/auth/client/api/user_api.py +2295 -179
  6. crypticorn/auth/client/api/wallet_api.py +1468 -81
  7. crypticorn/auth/client/configuration.py +2 -2
  8. crypticorn/auth/client/models/create_api_key_request.py +2 -1
  9. crypticorn/auth/client/models/get_api_keys200_response_inner.py +2 -1
  10. crypticorn/auth/client/rest.py +23 -4
  11. crypticorn/auth/main.py +8 -5
  12. crypticorn/cli/init.py +1 -1
  13. crypticorn/cli/templates/.env.docker.temp +3 -0
  14. crypticorn/cli/templates/.env.example.temp +4 -0
  15. crypticorn/cli/templates/Dockerfile +5 -2
  16. crypticorn/client.py +226 -59
  17. crypticorn/common/__init__.py +1 -0
  18. crypticorn/common/auth.py +45 -14
  19. crypticorn/common/decorators.py +1 -2
  20. crypticorn/common/enums.py +0 -2
  21. crypticorn/common/errors.py +10 -0
  22. crypticorn/common/metrics.py +30 -0
  23. crypticorn/common/middleware.py +94 -1
  24. crypticorn/common/pagination.py +252 -20
  25. crypticorn/common/router/admin_router.py +2 -2
  26. crypticorn/common/router/status_router.py +40 -2
  27. crypticorn/common/scopes.py +2 -2
  28. crypticorn/common/warnings.py +7 -0
  29. crypticorn/dex/__init__.py +6 -0
  30. crypticorn/dex/client/__init__.py +49 -0
  31. crypticorn/dex/client/api/__init__.py +6 -0
  32. crypticorn/dex/client/api/admin_api.py +2986 -0
  33. crypticorn/dex/client/api/signals_api.py +1798 -0
  34. crypticorn/dex/client/api/status_api.py +892 -0
  35. crypticorn/dex/client/api_client.py +758 -0
  36. crypticorn/dex/client/api_response.py +20 -0
  37. crypticorn/dex/client/configuration.py +620 -0
  38. crypticorn/dex/client/exceptions.py +220 -0
  39. crypticorn/dex/client/models/__init__.py +30 -0
  40. crypticorn/dex/client/models/api_error_identifier.py +121 -0
  41. crypticorn/dex/client/models/api_error_level.py +37 -0
  42. crypticorn/dex/client/models/api_error_type.py +37 -0
  43. crypticorn/dex/client/models/exception_detail.py +117 -0
  44. crypticorn/dex/client/models/log_level.py +38 -0
  45. crypticorn/dex/client/models/paginated_response_signal_with_token.py +134 -0
  46. crypticorn/dex/client/models/risk.py +86 -0
  47. crypticorn/dex/client/models/signal_overview_stats.py +158 -0
  48. crypticorn/dex/client/models/signal_volume.py +84 -0
  49. crypticorn/dex/client/models/signal_with_token.py +163 -0
  50. crypticorn/dex/client/models/token_data.py +127 -0
  51. crypticorn/dex/client/models/token_detail.py +116 -0
  52. crypticorn/dex/client/py.typed +0 -0
  53. crypticorn/dex/client/rest.py +217 -0
  54. crypticorn/dex/main.py +1 -0
  55. crypticorn/hive/client/api/admin_api.py +1173 -47
  56. crypticorn/hive/client/api/data_api.py +499 -17
  57. crypticorn/hive/client/api/models_api.py +1595 -87
  58. crypticorn/hive/client/api/status_api.py +397 -16
  59. crypticorn/hive/client/api_client.py +0 -5
  60. crypticorn/hive/client/models/api_error_identifier.py +1 -1
  61. crypticorn/hive/client/models/coin_info.py +1 -1
  62. crypticorn/hive/client/models/exception_detail.py +1 -1
  63. crypticorn/hive/client/models/target_info.py +1 -1
  64. crypticorn/hive/client/rest.py +23 -4
  65. crypticorn/hive/main.py +99 -25
  66. crypticorn/hive/utils.py +2 -2
  67. crypticorn/klines/client/api/admin_api.py +1173 -47
  68. crypticorn/klines/client/api/change_in_timeframe_api.py +269 -11
  69. crypticorn/klines/client/api/funding_rates_api.py +315 -11
  70. crypticorn/klines/client/api/ohlcv_data_api.py +390 -11
  71. crypticorn/klines/client/api/status_api.py +397 -16
  72. crypticorn/klines/client/api/symbols_api.py +216 -11
  73. crypticorn/klines/client/api/udf_api.py +1268 -51
  74. crypticorn/klines/client/api_client.py +0 -5
  75. crypticorn/klines/client/models/api_error_identifier.py +3 -1
  76. crypticorn/klines/client/models/exception_detail.py +1 -1
  77. crypticorn/klines/client/models/ohlcv.py +1 -1
  78. crypticorn/klines/client/models/symbol_group.py +1 -1
  79. crypticorn/klines/client/models/udf_config.py +1 -1
  80. crypticorn/klines/client/rest.py +23 -4
  81. crypticorn/klines/main.py +89 -12
  82. crypticorn/metrics/client/api/admin_api.py +1173 -47
  83. crypticorn/metrics/client/api/exchanges_api.py +1370 -145
  84. crypticorn/metrics/client/api/indicators_api.py +622 -17
  85. crypticorn/metrics/client/api/logs_api.py +296 -11
  86. crypticorn/metrics/client/api/marketcap_api.py +1207 -67
  87. crypticorn/metrics/client/api/markets_api.py +343 -11
  88. crypticorn/metrics/client/api/quote_currencies_api.py +228 -11
  89. crypticorn/metrics/client/api/status_api.py +397 -16
  90. crypticorn/metrics/client/api/tokens_api.py +382 -15
  91. crypticorn/metrics/client/api_client.py +0 -5
  92. crypticorn/metrics/client/configuration.py +4 -2
  93. crypticorn/metrics/client/models/exception_detail.py +1 -1
  94. crypticorn/metrics/client/models/exchange_mapping.py +1 -1
  95. crypticorn/metrics/client/models/marketcap_ranking.py +1 -1
  96. crypticorn/metrics/client/models/marketcap_symbol_ranking.py +1 -1
  97. crypticorn/metrics/client/models/ohlcv.py +1 -1
  98. crypticorn/metrics/client/rest.py +23 -4
  99. crypticorn/metrics/main.py +113 -19
  100. crypticorn/pay/client/api/admin_api.py +1585 -57
  101. crypticorn/pay/client/api/now_payments_api.py +961 -39
  102. crypticorn/pay/client/api/payments_api.py +562 -17
  103. crypticorn/pay/client/api/products_api.py +880 -30
  104. crypticorn/pay/client/api/status_api.py +397 -16
  105. crypticorn/pay/client/api_client.py +0 -5
  106. crypticorn/pay/client/configuration.py +2 -2
  107. crypticorn/pay/client/models/api_error_identifier.py +7 -7
  108. crypticorn/pay/client/models/exception_detail.py +1 -1
  109. crypticorn/pay/client/models/now_create_invoice_req.py +1 -1
  110. crypticorn/pay/client/models/now_create_invoice_res.py +1 -1
  111. crypticorn/pay/client/models/product.py +1 -1
  112. crypticorn/pay/client/models/product_create.py +1 -1
  113. crypticorn/pay/client/models/product_update.py +1 -1
  114. crypticorn/pay/client/models/scope.py +1 -0
  115. crypticorn/pay/client/rest.py +23 -4
  116. crypticorn/pay/main.py +10 -6
  117. crypticorn/trade/client/__init__.py +11 -1
  118. crypticorn/trade/client/api/__init__.py +0 -1
  119. crypticorn/trade/client/api/admin_api.py +1184 -55
  120. crypticorn/trade/client/api/api_keys_api.py +1678 -162
  121. crypticorn/trade/client/api/bots_api.py +7563 -187
  122. crypticorn/trade/client/api/exchanges_api.py +565 -19
  123. crypticorn/trade/client/api/notifications_api.py +1290 -116
  124. crypticorn/trade/client/api/orders_api.py +393 -55
  125. crypticorn/trade/client/api/status_api.py +397 -13
  126. crypticorn/trade/client/api/strategies_api.py +1133 -77
  127. crypticorn/trade/client/api/trading_actions_api.py +786 -65
  128. crypticorn/trade/client/models/__init__.py +11 -0
  129. crypticorn/trade/client/models/actions_count.py +88 -0
  130. crypticorn/trade/client/models/api_error_identifier.py +1 -0
  131. crypticorn/trade/client/models/bot.py +7 -18
  132. crypticorn/trade/client/models/bot_create.py +17 -1
  133. crypticorn/trade/client/models/bot_update.py +17 -1
  134. crypticorn/trade/client/models/exchange.py +6 -1
  135. crypticorn/trade/client/models/exchange_key.py +1 -1
  136. crypticorn/trade/client/models/exchange_key_balance.py +111 -0
  137. crypticorn/trade/client/models/exchange_key_create.py +17 -1
  138. crypticorn/trade/client/models/exchange_key_update.py +17 -1
  139. crypticorn/trade/client/models/execution_ids.py +1 -1
  140. crypticorn/trade/client/models/futures_balance.py +27 -25
  141. crypticorn/trade/client/models/notification.py +17 -1
  142. crypticorn/trade/client/models/notification_create.py +18 -2
  143. crypticorn/trade/client/models/notification_update.py +17 -1
  144. crypticorn/trade/client/models/orders_count.py +88 -0
  145. crypticorn/trade/client/models/paginated_response_futures_trading_action.py +134 -0
  146. crypticorn/trade/client/models/paginated_response_order.py +134 -0
  147. crypticorn/trade/client/models/pn_l.py +95 -0
  148. crypticorn/trade/client/models/post_futures_action.py +1 -1
  149. crypticorn/trade/client/models/spot_balance.py +109 -0
  150. crypticorn/trade/client/models/strategy.py +22 -4
  151. crypticorn/trade/client/models/strategy_create.py +23 -5
  152. crypticorn/trade/client/models/strategy_exchange_info.py +16 -4
  153. crypticorn/trade/client/models/strategy_update.py +19 -3
  154. crypticorn/trade/client/models/tpsl.py +4 -19
  155. crypticorn/trade/client/models/tpsl_create.py +6 -19
  156. crypticorn/trade/client/rest.py +23 -4
  157. crypticorn/trade/main.py +15 -12
  158. {crypticorn-2.16.0.dist-info → crypticorn-2.17.0.dist-info}/METADATA +65 -20
  159. {crypticorn-2.16.0.dist-info → crypticorn-2.17.0.dist-info}/RECORD +163 -128
  160. crypticorn/trade/client/api/futures_trading_panel_api.py +0 -1285
  161. {crypticorn-2.16.0.dist-info → crypticorn-2.17.0.dist-info}/WHEEL +0 -0
  162. {crypticorn-2.16.0.dist-info → crypticorn-2.17.0.dist-info}/entry_points.txt +0 -0
  163. {crypticorn-2.16.0.dist-info → crypticorn-2.17.0.dist-info}/licenses/LICENSE +0 -0
  164. {crypticorn-2.16.0.dist-info → crypticorn-2.17.0.dist-info}/top_level.txt +0 -0
@@ -33,11 +33,6 @@ from crypticorn.klines.client import rest
33
33
  from crypticorn.klines.client.exceptions import (
34
34
  ApiValueError,
35
35
  ApiException,
36
- BadRequestException,
37
- UnauthorizedException,
38
- ForbiddenException,
39
- NotFoundException,
40
- ServiceException,
41
36
  )
42
37
 
43
38
  RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
@@ -68,17 +68,19 @@ class ApiErrorIdentifier(str, Enum):
68
68
  INVALID_EXCHANGE_KEY = "invalid_exchange_key"
69
69
  INVALID_MARGIN_MODE = "invalid_margin_mode"
70
70
  INVALID_MODEL_NAME = "invalid_model_name"
71
- INVALID_PARAMETER_PROVIDED = "exchange_invalid_parameter"
71
+ INVALID_PARAMETER_PROVIDED = "invalid_parameter_provided"
72
72
  LEVERAGE_LIMIT_EXCEEDED = "leverage_limit_exceeded"
73
73
  ORDER_VIOLATES_LIQUIDATION_PRICE_CONSTRAINTS = (
74
74
  "order_violates_liquidation_price_constraints"
75
75
  )
76
+ MARGIN_MODE_CLASH = "margin_mode_clash"
76
77
  MODEL_NAME_NOT_UNIQUE = "model_name_not_unique"
77
78
  NO_CREDENTIALS = "no_credentials"
78
79
  NOW_API_DOWN = "now_api_down"
79
80
  OBJECT_ALREADY_EXISTS = "object_already_exists"
80
81
  OBJECT_CREATED = "object_created"
81
82
  OBJECT_DELETED = "object_deleted"
83
+ OBJECT_LOCKED = "object_locked"
82
84
  OBJECT_NOT_FOUND = "object_not_found"
83
85
  OBJECT_UPDATED = "object_updated"
84
86
  ORDER_IS_ALREADY_FILLED = "order_is_already_filled"
@@ -22,7 +22,7 @@ from typing import Any, ClassVar, Dict, List, Optional
22
22
  from crypticorn.klines.client.models.api_error_identifier import ApiErrorIdentifier
23
23
  from crypticorn.klines.client.models.api_error_level import ApiErrorLevel
24
24
  from crypticorn.klines.client.models.api_error_type import ApiErrorType
25
- from typing import Optional, Set
25
+ from typing import Set
26
26
  from typing_extensions import Self
27
27
 
28
28
 
@@ -19,7 +19,7 @@ import json
19
19
 
20
20
  from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt
21
21
  from typing import Any, ClassVar, Dict, List, Optional, Union
22
- from typing import Optional, Set
22
+ from typing import Set
23
23
  from typing_extensions import Self
24
24
 
25
25
 
@@ -19,7 +19,7 @@ import json
19
19
 
20
20
  from pydantic import BaseModel, ConfigDict, StrictStr
21
21
  from typing import Any, ClassVar, Dict, List, Optional
22
- from typing import Optional, Set
22
+ from typing import Set
23
23
  from typing_extensions import Self
24
24
 
25
25
 
@@ -21,7 +21,7 @@ from pydantic import BaseModel, ConfigDict, StrictBool, StrictStr
21
21
  from typing import Any, ClassVar, Dict, List, Optional
22
22
  from crypticorn.klines.client.models.internal_exchange import InternalExchange
23
23
  from crypticorn.klines.client.models.symbol_type import SymbolType
24
- from typing import Optional, Set
24
+ from typing import Set
25
25
  from typing_extensions import Self
26
26
 
27
27
 
@@ -77,6 +77,7 @@ class RESTClientObject:
77
77
 
78
78
  self.pool_manager: Optional[aiohttp.ClientSession] = None
79
79
  self.retry_client: Optional[aiohttp_retry.RetryClient] = None
80
+ self.is_sync: bool = False # Track whether this is sync or async mode
80
81
 
81
82
  async def close(self) -> None:
82
83
  if self.pool_manager:
@@ -170,7 +171,9 @@ class RESTClientObject:
170
171
 
171
172
  pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
172
173
 
173
- # https pool manager
174
+ # For sync operations, always use a fresh session
175
+ should_close_session = False
176
+
174
177
  if self.pool_manager is None:
175
178
  self.pool_manager = aiohttp.ClientSession(
176
179
  connector=aiohttp.TCPConnector(
@@ -178,6 +181,9 @@ class RESTClientObject:
178
181
  ),
179
182
  trust_env=True,
180
183
  )
184
+ # Only close session automatically in sync mode
185
+ should_close_session = self.is_sync
186
+
181
187
  pool_manager = self.pool_manager
182
188
 
183
189
  if self.retries is not None and method in ALLOW_RETRY_METHODS:
@@ -193,6 +199,19 @@ class RESTClientObject:
193
199
  )
194
200
  pool_manager = self.retry_client
195
201
 
196
- r = await pool_manager.request(**args)
197
-
198
- return RESTResponse(r)
202
+ try:
203
+ r = await pool_manager.request(**args)
204
+ # For sessions we're about to close, read the data immediately
205
+ if should_close_session:
206
+ response = RESTResponse(r)
207
+ await response.read() # Read data before closing session
208
+ return response
209
+ else:
210
+ return RESTResponse(r)
211
+ finally:
212
+ if should_close_session:
213
+ if self.retry_client is not None:
214
+ await self.retry_client.close()
215
+ self.retry_client = None
216
+ await self.pool_manager.close()
217
+ self.pool_manager = None
crypticorn/klines/main.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from __future__ import annotations
2
- from typing import TYPE_CHECKING, Optional
2
+ from typing import TYPE_CHECKING, Optional, Union, Coroutine, Any
3
3
  from crypticorn.klines import (
4
4
  ApiClient,
5
5
  Configuration,
@@ -26,17 +26,20 @@ class KlinesClient:
26
26
  self,
27
27
  config: Configuration,
28
28
  http_client: Optional[ClientSession] = None,
29
+ is_sync: bool = False,
29
30
  ):
30
31
  self.config = config
31
32
  self.base_client = ApiClient(configuration=self.config)
32
33
  if http_client is not None:
33
34
  self.base_client.rest_client.pool_manager = http_client
35
+ # Pass sync context to REST client for proper session management
36
+ self.base_client.rest_client.is_sync = is_sync
34
37
  # Instantiate all the endpoint clients
35
- self.funding = FundingRatesApiWrapper(self.base_client)
36
- self.ohlcv = OHLCVDataApiWrapper(self.base_client)
37
- self.symbols = SymbolsApiWrapper(self.base_client)
38
- self.udf = UDFApi(self.base_client)
39
- self.status = StatusApi(self.base_client)
38
+ self.funding = FundingRatesApiWrapper(self.base_client, is_sync=is_sync)
39
+ self.ohlcv = OHLCVDataApiWrapper(self.base_client, is_sync=is_sync)
40
+ self.symbols = SymbolsApiWrapper(self.base_client, is_sync=is_sync)
41
+ self.udf = UDFApi(self.base_client, is_sync=is_sync)
42
+ self.status = StatusApi(self.base_client, is_sync=is_sync)
40
43
 
41
44
 
42
45
  class FundingRatesApiWrapper(FundingRatesApi):
@@ -44,12 +47,38 @@ class FundingRatesApiWrapper(FundingRatesApi):
44
47
  A wrapper for the FundingRatesApi class.
45
48
  """
46
49
 
47
- async def get_funding_rates_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
50
+ def get_funding_rates_fmt(self, *args, **kwargs) -> Union[pd.DataFrame, Coroutine[Any, Any, pd.DataFrame]]: # type: ignore
48
51
  """
49
52
  Get the funding rates in a pandas DataFrame.
53
+ Works in both sync and async contexts.
54
+ """
55
+ if self.is_sync:
56
+ return self._get_funding_rates_fmt_sync(*args, **kwargs)
57
+ else:
58
+ return self._get_funding_rates_fmt_async(*args, **kwargs)
59
+
60
+ def _get_funding_rates_fmt_sync(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
61
+ """
62
+ Get the funding rates in a pandas DataFrame (sync version).
63
+ """
64
+ pd = optional_import("pandas", "extra")
65
+ response = self._get_funding_rates_sync(*args, **kwargs)
66
+ response = [
67
+ {
68
+ "timestamp": int(m.timestamp.timestamp()),
69
+ "symbol": m.symbol,
70
+ "funding_rate": m.funding_rate,
71
+ }
72
+ for m in response
73
+ ]
74
+ return pd.DataFrame(response)
75
+
76
+ async def _get_funding_rates_fmt_async(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
77
+ """
78
+ Get the funding rates in a pandas DataFrame (async version).
50
79
  """
51
80
  pd = optional_import("pandas", "extra")
52
- response = await self.get_funding_rates(*args, **kwargs)
81
+ response = await self._get_funding_rates_async(*args, **kwargs)
53
82
  response = [
54
83
  {
55
84
  "timestamp": int(m.timestamp.timestamp()),
@@ -66,12 +95,42 @@ class OHLCVDataApiWrapper(OHLCVDataApi):
66
95
  A wrapper for the OHLCVDataApi class.
67
96
  """
68
97
 
69
- async def get_ohlcv_data_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
98
+ def get_ohlcv_data_fmt(self, *args, **kwargs) -> Union[pd.DataFrame, Coroutine[Any, Any, pd.DataFrame]]: # type: ignore
70
99
  """
71
100
  Get the OHLCV data in a pandas DataFrame.
101
+ Works in both sync and async contexts.
102
+ """
103
+ if self.is_sync:
104
+ return self._get_ohlcv_data_fmt_sync(*args, **kwargs)
105
+ else:
106
+ return self._get_ohlcv_data_fmt_async(*args, **kwargs)
107
+
108
+ def _get_ohlcv_data_fmt_sync(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
109
+ """
110
+ Get the OHLCV data in a pandas DataFrame (sync version).
111
+ """
112
+ pd = optional_import("pandas", "extra")
113
+ response = self._get_ohlcv_sync(*args, **kwargs)
114
+ rows = []
115
+ for item in response:
116
+ row = {
117
+ "timestamp": item.timestamp,
118
+ "open": item.open,
119
+ "high": item.high,
120
+ "low": item.low,
121
+ "close": item.close,
122
+ "volume": item.volume,
123
+ }
124
+ rows.append(row)
125
+ df = pd.DataFrame(rows)
126
+ return df
127
+
128
+ async def _get_ohlcv_data_fmt_async(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
129
+ """
130
+ Get the OHLCV data in a pandas DataFrame (async version).
72
131
  """
73
132
  pd = optional_import("pandas", "extra")
74
- response = await self.get_ohlcv(*args, **kwargs)
133
+ response = await self._get_ohlcv_async(*args, **kwargs)
75
134
  rows = []
76
135
  for item in response:
77
136
  row = {
@@ -92,10 +151,28 @@ class SymbolsApiWrapper(SymbolsApi):
92
151
  A wrapper for the SymbolsApi class.
93
152
  """
94
153
 
95
- async def get_symbols_fmt(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
154
+ def get_symbols_fmt(self, *args, **kwargs) -> Union[pd.DataFrame, Coroutine[Any, Any, pd.DataFrame]]: # type: ignore
96
155
  """
97
156
  Get the symbols in a pandas DataFrame.
157
+ Works in both sync and async contexts.
158
+ """
159
+ if self.is_sync:
160
+ return self._get_symbols_fmt_sync(*args, **kwargs)
161
+ else:
162
+ return self._get_symbols_fmt_async(*args, **kwargs)
163
+
164
+ def _get_symbols_fmt_sync(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
165
+ """
166
+ Get the symbols in a pandas DataFrame (sync version).
167
+ """
168
+ pd = optional_import("pandas", "extra")
169
+ response = self._get_klines_symbols_sync(*args, **kwargs)
170
+ return pd.DataFrame(response, columns=["symbol"])
171
+
172
+ async def _get_symbols_fmt_async(self, *args, **kwargs) -> pd.DataFrame: # type: ignore
173
+ """
174
+ Get the symbols in a pandas DataFrame (async version).
98
175
  """
99
176
  pd = optional_import("pandas", "extra")
100
- response = await self.get_klines_symbols(*args, **kwargs)
177
+ response = await self._get_klines_symbols_async(*args, **kwargs)
101
178
  return pd.DataFrame(response, columns=["symbol"])