crypticorn 2.1.6__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.
crypticorn/auth/main.py CHANGED
@@ -7,7 +7,6 @@ from crypticorn.auth import (
7
7
  WalletApi,
8
8
  AuthApi,
9
9
  )
10
- from crypticorn.common import BaseURL, ApiVersion, Service, apikey_header as aph
11
10
 
12
11
 
13
12
  class AuthClient:
@@ -17,19 +16,9 @@ class AuthClient:
17
16
 
18
17
  def __init__(
19
18
  self,
20
- base_url: BaseURL,
21
- api_version: ApiVersion,
22
- api_key: str = None,
23
- jwt: str = None,
19
+ config: Configuration,
24
20
  ):
25
- self.host = f"{base_url.value}/{api_version.value}/{Service.AUTH.value}"
26
- self.config = Configuration(
27
- host=self.host,
28
- access_token=jwt,
29
- api_key={aph.scheme_name: api_key} if api_key else None,
30
- api_key_prefix=({aph.scheme_name: aph.model.name} if api_key else None),
31
- debug=True,
32
- )
21
+ self.config = config
33
22
  self.base_client = ApiClient(configuration=self.config)
34
23
  # Instantiate all the endpoint clients
35
24
  self.admin = AdminApi(self.base_client)
@@ -37,9 +26,3 @@ class AuthClient:
37
26
  self.user = UserApi(self.base_client)
38
27
  self.wallet = WalletApi(self.base_client)
39
28
  self.login = AuthApi(self.base_client)
40
-
41
- async def __aenter__(self):
42
- return self
43
-
44
- async def __aexit__(self, exc_type, exc_val, exc_tb):
45
- await self.base_client.close()
crypticorn/client.py CHANGED
@@ -1,11 +1,11 @@
1
- from crypticorn.hive import HiveClient
1
+ from crypticorn.hive import HiveClient, Configuration
2
2
  from crypticorn.klines import KlinesClient
3
3
  from crypticorn.pay import PayClient
4
4
  from crypticorn.trade import TradeClient
5
5
  from crypticorn.metrics import MetricsClient
6
- from crypticorn.common import BaseURL, ApiVersion
7
-
8
-
6
+ from crypticorn.auth import AuthClient
7
+ from crypticorn.common import BaseUrl, ApiVersion, Service, apikey_header as aph
8
+ import warnings
9
9
  class ApiClient:
10
10
  """
11
11
  The official client for interacting with the Crypticorn API.
@@ -15,34 +15,30 @@ class ApiClient:
15
15
 
16
16
  def __init__(
17
17
  self,
18
- base_url: BaseURL = BaseURL.PROD,
19
18
  api_key: str = None,
20
19
  jwt: str = None,
21
- hive_version: ApiVersion = ApiVersion.V1,
22
- klines_version: ApiVersion = ApiVersion.V1,
23
- pay_version: ApiVersion = ApiVersion.V1,
24
- trade_version: ApiVersion = ApiVersion.V1,
25
- auth_version: ApiVersion = ApiVersion.V1,
26
- metrics_version: ApiVersion = ApiVersion.V1,
20
+ base_url: BaseUrl = BaseUrl.PROD,
27
21
  ):
28
22
  self.base_url = base_url
23
+ '''The base URL the client will use to connect to the API.'''
29
24
  self.api_key = api_key
25
+ '''The API key to use for authentication.'''
30
26
  self.jwt = jwt
31
- self.hive = HiveClient(base_url, hive_version, api_key, jwt)
32
- self.trade = TradeClient(base_url, trade_version, api_key, jwt)
33
- self.klines = KlinesClient(base_url, klines_version, api_key, jwt)
34
- self.pay = PayClient(base_url, pay_version, api_key, jwt)
35
- self.metrics = MetricsClient(base_url, metrics_version, api_key, jwt)
36
- # currently not working due to circular import since the AUTH_Handler
37
- # is also using the ApiClient
38
- # self.auth = AuthClient(base_url, auth_version, api_key, jwt)
27
+ '''The JWT to use for authentication.'''
39
28
 
40
- async def __aenter__(self):
41
- return self
42
-
43
- async def __aexit__(self, exc_type, exc_val, exc_tb):
44
- await self.close()
29
+ self.hive = HiveClient(self._get_default_config(Service.HIVE))
30
+ self.trade = TradeClient(self._get_default_config(Service.TRADE))
31
+ self.klines = KlinesClient(self._get_default_config(Service.KLINES))
32
+ self.pay = PayClient(self._get_default_config(Service.PAY))
33
+ self.metrics = MetricsClient(self._get_default_config(Service.METRICS))
34
+ self.auth = AuthClient(self._get_default_config(Service.AUTH))
45
35
 
36
+ def __new__(cls, *args, **kwargs):
37
+ if kwargs.get("api_key") and not kwargs.get("jwt"):
38
+ # auth-service does not allow api_key
39
+ warnings.warn("The auth module does only accept JWT to be used to authenticate. If you use this module, you need to provide a JWT.")
40
+ return super().__new__(cls)
41
+
46
42
  async def close(self):
47
43
  """Close all client sessions."""
48
44
  clients = [
@@ -51,8 +47,61 @@ class ApiClient:
51
47
  self.klines.base_client,
52
48
  self.pay.base_client,
53
49
  self.metrics.base_client,
50
+ self.auth.base_client,
54
51
  ]
55
52
 
56
53
  for client in clients:
57
54
  if hasattr(client, "close"):
58
55
  await client.close()
56
+
57
+ def _get_default_config(self, service: Service, version: ApiVersion = ApiVersion.V1):
58
+ """
59
+ Get the default configuration for a given service.
60
+ """
61
+ return Configuration(
62
+ host=f"{self.base_url}/{version}/{service}",
63
+ access_token=self.jwt,
64
+ api_key={aph.scheme_name: self.api_key} if self.api_key else None,
65
+ api_key_prefix=({aph.scheme_name: aph.model.name} if self.api_key else None),
66
+ )
67
+
68
+ def configure(self, config: Configuration, sub_client: any):
69
+ """
70
+ Update a sub-client's configuration by overriding with the values set in the new config.
71
+ Useful for testing a specific service against a local server instead of the default proxy.
72
+
73
+ :param config: The new configuration to use for the sub-client.
74
+ :param sub_client: The sub-client to configure.
75
+
76
+ Example:
77
+ This will override the host for the Hive client to connect to http://localhost:8000 instead of the default proxy:
78
+ >>> async with ApiClient(base_url=BaseUrl.DEV, jwt=jwt) as client:
79
+ >>> client.configure(config=HiveConfig(host="http://localhost:8000"), sub_client=client.hive)
80
+ """
81
+ new_config = sub_client.config
82
+ for attr in vars(config):
83
+ new_value = getattr(config, attr)
84
+ if new_value is not None:
85
+ setattr(new_config, attr, new_value)
86
+
87
+ if sub_client == self.hive:
88
+ self.hive = HiveClient(new_config)
89
+ elif sub_client == self.trade:
90
+ self.trade = TradeClient(new_config)
91
+ elif sub_client == self.klines:
92
+ self.klines = KlinesClient(new_config)
93
+ elif sub_client == self.pay:
94
+ self.pay = PayClient(new_config)
95
+ elif sub_client == self.metrics:
96
+ self.metrics = MetricsClient(new_config)
97
+ elif sub_client == self.auth:
98
+ self.auth = AuthClient(new_config)
99
+ else:
100
+ raise ValueError(f"Unknown sub-client: {sub_client}")
101
+
102
+ async def __aenter__(self):
103
+ return self
104
+
105
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
106
+ await self.close()
107
+
@@ -1,5 +1,4 @@
1
1
  from crypticorn.common.errors import *
2
2
  from crypticorn.common.scopes import *
3
3
  from crypticorn.common.urls import *
4
- from crypticorn.common.auth import *
5
- from crypticorn.common.auth_client import *
4
+ from crypticorn.common.auth import *
crypticorn/common/auth.py CHANGED
@@ -1,6 +1,24 @@
1
- from fastapi.security import APIKeyHeader, HTTPBearer
1
+ import json
2
2
 
3
+ from crypticorn.auth import Verify200Response, AuthClient, Configuration
4
+ from crypticorn.auth.client.exceptions import ApiException
5
+ from crypticorn.common import (
6
+ ApiError,
7
+ ApiVersion,
8
+ BaseUrl,
9
+ Scope,
10
+ Service,
11
+ )
12
+ from fastapi import Depends, HTTPException, Query, status
13
+ from fastapi.security import (
14
+ HTTPAuthorizationCredentials,
15
+ SecurityScopes,
16
+ HTTPBearer,
17
+ APIKeyHeader,
18
+ )
19
+ from typing_extensions import Annotated
3
20
 
21
+ # Auth Schemes
4
22
  http_bearer = HTTPBearer(
5
23
  bearerFormat="JWT",
6
24
  auto_error=False,
@@ -12,3 +30,189 @@ apikey_header = APIKeyHeader(
12
30
  auto_error=False,
13
31
  description="The API key to use for authentication.",
14
32
  )
33
+
34
+ # Auth Handler
35
+ class AuthHandler:
36
+ """
37
+ Middleware for verifying API requests. Verifies the validity of the authentication token, scopes, etc.
38
+
39
+ @param base_url: The base URL of the API.
40
+ @param api_version: The version of the API.
41
+ """
42
+
43
+ def __init__(
44
+ self,
45
+ base_url: BaseUrl = BaseUrl.PROD,
46
+ ):
47
+ self.url = f"{base_url}/{ApiVersion.V1}/{Service.AUTH}"
48
+ self.client = AuthClient(Configuration(host=self.url))
49
+
50
+ self.no_credentials_exception = HTTPException(
51
+ status_code=status.HTTP_401_UNAUTHORIZED,
52
+ detail=ApiError.NO_CREDENTIALS.identifier,
53
+ )
54
+
55
+ async def _verify_api_key(self, api_key: str) -> None:
56
+ """
57
+ Verifies the API key.
58
+ """
59
+ return await self.client.login.verify_api_key(api_key)
60
+
61
+ async def _verify_bearer(
62
+ self, bearer: HTTPAuthorizationCredentials
63
+ ) -> Verify200Response:
64
+ """
65
+ Verifies the bearer token.
66
+ """
67
+ self.client.config.access_token = bearer.credentials
68
+ return await self.client.login.verify()
69
+
70
+ async def _validate_scopes(
71
+ self, api_scopes: list[Scope], user_scopes: list[Scope]
72
+ ) -> bool:
73
+ """
74
+ Checks if the user scopes are a subset of the API scopes.
75
+ """
76
+ if not set(api_scopes).issubset(user_scopes):
77
+ raise HTTPException(
78
+ status_code=status.HTTP_403_FORBIDDEN,
79
+ detail=ApiError.INSUFFICIENT_SCOPES.identifier,
80
+ )
81
+
82
+ async def _extract_message(self, e: ApiException) -> str:
83
+ """
84
+ Tries to extract the message from the body of the exception.
85
+ """
86
+ try:
87
+ load = json.loads(e.body)
88
+ except (json.JSONDecodeError, TypeError):
89
+ return e.body
90
+ else:
91
+ common_keys = ["message"]
92
+ for key in common_keys:
93
+ if key in load:
94
+ return load[key]
95
+ return load
96
+
97
+ async def _handle_exception(self, e: Exception) -> HTTPException:
98
+ """
99
+ Handles exceptions and returns a HTTPException with the appropriate status code and detail.
100
+ """
101
+ if isinstance(e, ApiException):
102
+ return HTTPException(
103
+ status_code=e.status,
104
+ detail=await self._extract_message(e),
105
+ )
106
+ elif isinstance(e, HTTPException):
107
+ return e
108
+ else:
109
+ return HTTPException(
110
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
111
+ detail=str(e),
112
+ )
113
+
114
+ async def api_key_auth(
115
+ self,
116
+ api_key: Annotated[str | None, Depends(apikey_header)] = None,
117
+ sec: SecurityScopes = SecurityScopes(),
118
+ ) -> Verify200Response:
119
+ """
120
+ Verifies the API key and checks if the user scopes are a subset of the API scopes.
121
+ Use this function if you only want to allow access via the API key.
122
+ """
123
+ return await self.combined_auth(bearer=None, api_key=api_key, sec=sec)
124
+
125
+ async def bearer_auth(
126
+ self,
127
+ bearer: Annotated[
128
+ HTTPAuthorizationCredentials | None,
129
+ Depends(http_bearer),
130
+ ] = None,
131
+ sec: SecurityScopes = SecurityScopes(),
132
+ ) -> Verify200Response:
133
+ """
134
+ Verifies the bearer token and checks if the user scopes are a subset of the API scopes.
135
+ Use this function if you only want to allow access via the bearer token.
136
+ """
137
+ return await self.combined_auth(bearer=bearer, api_key=None, sec=sec)
138
+
139
+ async def combined_auth(
140
+ self,
141
+ bearer: Annotated[
142
+ HTTPAuthorizationCredentials | None, Depends(http_bearer)
143
+ ] = None,
144
+ api_key: Annotated[str | None, Depends(apikey_header)] = None,
145
+ sec: SecurityScopes = SecurityScopes(),
146
+ ) -> Verify200Response:
147
+ """
148
+ Verifies the bearer token and/or API key and checks if the user scopes are a subset of the API scopes.
149
+ Returns early on the first successful verification, otherwise tries all available tokens.
150
+ Use this function if you want to allow access via either the bearer token or the API key.
151
+ """
152
+ tokens = [bearer, api_key]
153
+
154
+ last_error = None
155
+ for token in tokens:
156
+ try:
157
+ if token is None:
158
+ continue
159
+ res = None
160
+ if isinstance(token, str):
161
+ res = await self._verify_api_key(token)
162
+ elif isinstance(token, HTTPAuthorizationCredentials):
163
+ res = await self._verify_bearer(token)
164
+ if res is None:
165
+ continue
166
+ if sec:
167
+ await self._validate_scopes(sec.scopes, res.scopes)
168
+ return res
169
+
170
+ except Exception as e:
171
+ last_error = await self._handle_exception(e)
172
+ continue
173
+
174
+ raise last_error or self.no_credentials_exception
175
+
176
+ async def ws_api_key_auth(
177
+ self,
178
+ api_key: Annotated[str | None, Query()] = None,
179
+ sec: SecurityScopes = SecurityScopes(),
180
+ ) -> Verify200Response:
181
+ """
182
+ Verifies the API key and checks if the user scopes are a subset of the API scopes.
183
+ Use this function if you only want to allow access via the API key.
184
+ """
185
+ return await self.api_key_auth(api_key=api_key, sec=sec)
186
+
187
+ async def ws_bearer_auth(
188
+ self,
189
+ bearer: Annotated[str | None, Query()] = None,
190
+ sec: SecurityScopes = SecurityScopes(),
191
+ ) -> Verify200Response:
192
+ """
193
+ Verifies the bearer token and checks if the user scopes are a subset of the API scopes.
194
+ Use this function if you only want to allow access via the bearer token.
195
+ """
196
+ credentials = (
197
+ HTTPAuthorizationCredentials(scheme="Bearer", credentials=bearer)
198
+ if bearer
199
+ else None
200
+ )
201
+ return await self.bearer_auth(bearer=credentials, sec=sec)
202
+
203
+ async def ws_combined_auth(
204
+ self,
205
+ bearer: Annotated[str | None, Query()] = None,
206
+ api_key: Annotated[str | None, Query()] = None,
207
+ sec: SecurityScopes = SecurityScopes(),
208
+ ) -> Verify200Response:
209
+ """
210
+ Verifies the bearer token and/or API key and checks if the user scopes are a subset of the API scopes.
211
+ Use this function if you want to allow access via either the bearer token or the API key.
212
+ """
213
+ credentials = (
214
+ HTTPAuthorizationCredentials(scheme="Bearer", credentials=bearer)
215
+ if bearer
216
+ else None
217
+ )
218
+ return await self.combined_auth(bearer=credentials, api_key=api_key, sec=sec)
@@ -1,7 +1,7 @@
1
- from enum import Enum
1
+ from enum import StrEnum
2
2
 
3
3
 
4
- class Scope(str, Enum):
4
+ class Scope(StrEnum):
5
5
  """
6
6
  The permission scopes for the API.
7
7
  """
crypticorn/common/urls.py CHANGED
@@ -1,23 +1,34 @@
1
- from enum import Enum
1
+ from enum import StrEnum
2
2
 
3
+ class ApiEnv(StrEnum):
4
+ PROD = "prod"
5
+ DEV = "dev"
6
+ LOCAL = "local"
7
+ DOCKER = "docker"
3
8
 
4
- class Domain(Enum):
5
- PROD = "crypticorn.com"
6
- DEV = "crypticorn.dev"
7
-
8
-
9
- class BaseURL(Enum):
9
+ class BaseUrl(StrEnum):
10
10
  PROD = "https://api.crypticorn.com"
11
11
  DEV = "https://api.crypticorn.dev"
12
12
  LOCAL = "http://localhost"
13
13
  DOCKER = "http://host.docker.internal"
14
14
 
15
+ @classmethod
16
+ def from_env(cls, env: ApiEnv) -> "BaseUrl":
17
+ if env == ApiEnv.PROD:
18
+ return cls.PROD
19
+ elif env == ApiEnv.DEV:
20
+ return cls.DEV
21
+ elif env == ApiEnv.LOCAL:
22
+ return cls.LOCAL
23
+ elif env == ApiEnv.DOCKER:
24
+ return cls.DOCKER
25
+
15
26
 
16
- class ApiVersion(Enum):
27
+ class ApiVersion(StrEnum):
17
28
  V1 = "v1"
18
29
 
19
30
 
20
- class Service(Enum):
31
+ class Service(StrEnum):
21
32
  HIVE = "hive"
22
33
  KLINES = "klines"
23
34
  PAY = "pay"
crypticorn/hive/main.py CHANGED
@@ -4,8 +4,9 @@ from crypticorn.hive import (
4
4
  ModelsApi,
5
5
  DataApi,
6
6
  StatusApi,
7
+ Configuration,
7
8
  )
8
- from crypticorn.common import BaseURL, ApiVersion, Service, apikey_header as aph
9
+ from crypticorn.common import apikey_header as aph
9
10
 
10
11
 
11
12
  class HiveClient:
@@ -15,18 +16,9 @@ class HiveClient:
15
16
 
16
17
  def __init__(
17
18
  self,
18
- base_url: BaseURL,
19
- api_version: ApiVersion,
20
- api_key: str = None,
21
- jwt: str = None,
19
+ config: Configuration,
22
20
  ):
23
- self.host = f"{base_url.value}/{api_version.value}/{Service.HIVE.value}"
24
- self.config = Configuration(
25
- host=self.host,
26
- access_token=jwt,
27
- api_key={aph.scheme_name: api_key} if api_key else None,
28
- api_key_prefix=({aph.scheme_name: aph.model.name} if api_key else None),
29
- )
21
+ self.config = config
30
22
  self.base_client = ApiClient(configuration=self.config)
31
23
  # Instantiate all the endpoint clients
32
24
  self.models = ModelsApi(self.base_client)
crypticorn/klines/main.py CHANGED
@@ -8,7 +8,6 @@ from crypticorn.klines import (
8
8
  SymbolsApi,
9
9
  UDFApi,
10
10
  )
11
- from crypticorn.common import BaseURL, ApiVersion, Service, apikey_header as aph
12
11
 
13
12
 
14
13
  class FundingRatesApiWrapper(FundingRatesApi):
@@ -58,18 +57,9 @@ class KlinesClient:
58
57
 
59
58
  def __init__(
60
59
  self,
61
- base_url: BaseURL,
62
- api_version: ApiVersion,
63
- api_key: str = None,
64
- jwt: str = None,
60
+ config: Configuration,
65
61
  ):
66
- self.host = f"{base_url.value}/{api_version.value}/{Service.KLINES.value}"
67
- self.config = Configuration(
68
- host=self.host,
69
- access_token=jwt,
70
- api_key={aph.scheme_name: api_key} if api_key else None,
71
- api_key_prefix=({aph.scheme_name: aph.model.name} if api_key else None),
72
- )
62
+ self.config = config
73
63
  self.base_client = ApiClient(configuration=self.config)
74
64
  # Instantiate all the endpoint clients
75
65
  self.funding = FundingRatesApiWrapper(self.base_client)
@@ -10,10 +10,9 @@ from crypticorn.metrics import (
10
10
  TokensApi,
11
11
  Market,
12
12
  )
13
- from crypticorn.common import BaseURL, ApiVersion, Service, apikey_header as aph
14
- from typing import Optional, Dict, Any, Union, Tuple
15
- from pydantic import StrictStr, StrictInt, StrictFloat, Field
13
+ from pydantic import StrictStr, StrictInt, Field
16
14
  from typing_extensions import Annotated
15
+ from typing import Optional
17
16
 
18
17
  import pandas as pd
19
18
 
@@ -25,18 +24,9 @@ class MetricsClient:
25
24
 
26
25
  def __init__(
27
26
  self,
28
- base_url: BaseURL,
29
- api_version: ApiVersion,
30
- api_key: str = None,
31
- jwt: str = None,
27
+ config: Configuration,
32
28
  ):
33
- self.host = f"{base_url.value}/{api_version.value}/{Service.METRICS.value}"
34
- self.config = Configuration(
35
- host=self.host,
36
- access_token=jwt,
37
- api_key={aph.scheme_name: api_key} if api_key else None,
38
- api_key_prefix=({aph.scheme_name: aph.model.name} if api_key else None),
39
- )
29
+ self.config = config
40
30
  self.base_client = ApiClient(configuration=self.config)
41
31
  # Instantiate all the endpoint clients
42
32
  self.status = HealthCheckApi(self.base_client)
crypticorn/pay/main.py CHANGED
@@ -6,7 +6,6 @@ from crypticorn.pay import (
6
6
  PaymentsApi,
7
7
  ProductsApi,
8
8
  )
9
- from crypticorn.common import BaseURL, ApiVersion, Service, apikey_header as aph
10
9
 
11
10
 
12
11
  class PayClient:
@@ -16,18 +15,9 @@ class PayClient:
16
15
 
17
16
  def __init__(
18
17
  self,
19
- base_url: BaseURL,
20
- api_version: ApiVersion,
21
- api_key: str = None,
22
- jwt: str = None,
18
+ config: Configuration,
23
19
  ):
24
- self.host = f"{base_url.value}/{api_version.value}/{Service.PAY.value}"
25
- self.config = Configuration(
26
- host=self.host,
27
- access_token=jwt,
28
- api_key={aph.scheme_name: api_key} if api_key else None,
29
- api_key_prefix=({aph.scheme_name: aph.model.name} if api_key else None),
30
- )
20
+ self.config = config
31
21
  self.base_client = ApiClient(configuration=self.config)
32
22
  self.now = NOWPaymentsApi(self.base_client)
33
23
  self.status = StatusApi(self.base_client)
crypticorn/trade/main.py CHANGED
@@ -11,7 +11,6 @@ from crypticorn.trade import (
11
11
  StrategiesApi,
12
12
  TradingActionsApi,
13
13
  )
14
- from crypticorn.common import BaseURL, ApiVersion, Service, apikey_header as aph
15
14
 
16
15
 
17
16
  class TradeClient:
@@ -21,18 +20,9 @@ class TradeClient:
21
20
 
22
21
  def __init__(
23
22
  self,
24
- base_url: BaseURL,
25
- api_version: ApiVersion,
26
- api_key: str = None,
27
- jwt: str = None,
23
+ config: Configuration,
28
24
  ):
29
- self.host = f"{base_url.value}/{api_version.value}/{Service.TRADE.value}"
30
- self.config = Configuration(
31
- host=self.host,
32
- access_token=jwt,
33
- api_key={aph.scheme_name: api_key} if api_key else None,
34
- api_key_prefix=({aph.scheme_name: aph.model.name} if api_key else None),
35
- )
25
+ self.config = config
36
26
  self.base_client = ApiClient(configuration=self.config)
37
27
  # Instantiate all the endpoint clients
38
28
  self.bots = BotsApi(self.base_client)
@@ -0,0 +1,146 @@
1
+ Metadata-Version: 2.4
2
+ Name: crypticorn
3
+ Version: 2.2.0
4
+ Summary: Maximise Your Crypto Trading Profits with AI Predictions
5
+ Author-email: Crypticorn <timon@crypticorn.com>
6
+ Project-URL: Homepage, https://crypticorn.com
7
+ Keywords: machine learning,data science,crypto,modelling
8
+ Classifier: Topic :: Scientific/Engineering
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: fastapi
17
+ Requires-Dist: urllib3<3.0.0,>=1.25.3
18
+ Requires-Dist: python_dateutil<3.0.0,>=2.8.2
19
+ Requires-Dist: aiohttp<4.0.0,>=3.8.4
20
+ Requires-Dist: aiohttp-retry<3.0.0,>=2.8.3
21
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
22
+ Requires-Dist: typing-extensions<5.0.0,>=4.7.1
23
+ Requires-Dist: pandas<3.0.0,>=2.2.0
24
+ Requires-Dist: requests<3.0.0,>=2.32.0
25
+ Requires-Dist: tqdm<5.0.0,>=4.67.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: streamlit; extra == "dev"
28
+ Requires-Dist: httpx; extra == "dev"
29
+ Requires-Dist: build; extra == "dev"
30
+ Requires-Dist: black; extra == "dev"
31
+ Requires-Dist: twine; extra == "dev"
32
+ Requires-Dist: pyflakes; extra == "dev"
33
+ Provides-Extra: test
34
+ Requires-Dist: pytest==8.3.5; extra == "test"
35
+ Requires-Dist: pytest-asyncio==0.26.0; extra == "test"
36
+ Requires-Dist: pytest-cov==6.1.1; extra == "test"
37
+ Requires-Dist: python-dotenv==1.0.1; extra == "test"
38
+
39
+ # What is Crypticorn?
40
+
41
+ Crypticorn is at the forefront of cutting-edge artificial intelligence cryptocurrency trading.
42
+ Crypticorn offers AI-based solutions for both active and passive investors, including:
43
+ - Prediction Dashboard with trading terminal,
44
+ - AI Agents with different strategies,
45
+ - DEX AI Signals for newly launched tokens,
46
+ - DEX AI Bots
47
+
48
+ Use this API Client to contribute to the so-called Hive AI, a community driven AI Meta Model for predicting the
49
+ cryptocurrency market.
50
+
51
+ ## Installation
52
+
53
+ You can install the latest stable version from PyPi:
54
+ ```bash
55
+ pip install crypticorn
56
+ ```
57
+
58
+ If you want a specific version, run:
59
+ ```bash
60
+ pip install crypticorn==2.0.0
61
+ ```
62
+
63
+ If you want the latest version, which could be a pre release, run:
64
+ ```bash
65
+ pip install --pre crypticorn
66
+ ```
67
+
68
+ ## Structure
69
+
70
+ Our API is available as an asynchronous Python SDK. The main entry point you need is the `ApiClient` class, which you would import like this:
71
+ ```python
72
+ from crypticorn import ApiClient
73
+ ```
74
+
75
+ ## Usage
76
+
77
+ ### With Async Context Protocol
78
+ ```python
79
+ async with ApiClient(base_url=BaseUrl.Prod, api_key="your-api-key") as client:
80
+ await client.pay.products.get_products()
81
+ ```
82
+
83
+ ### Without Async Context Protocol
84
+ Without the context you need to close the session manually.
85
+ ```python
86
+ client = ApiClient(base_url=BaseUrl.Prod, api_key="your-api-key")
87
+ asyncio.run(client.pay.models.get_products())
88
+ asyncio.run(client.close())
89
+ ```
90
+
91
+ ## Response Types
92
+
93
+ There are three different available output formats you can choose from:
94
+
95
+ ### Serialized Response
96
+ You can get fully serialized responses as pydantic models. Using this, you get the full benefits of pydantic's type checking.
97
+ ```python
98
+ response = await client.pay.products.get_products()
99
+ print(response)
100
+ ```
101
+ The output would look like this:
102
+ ```python
103
+ [ProductModel(id='67e8146e7bae32f3838fe36a', name='Awesome Product', price=5.0, scopes=None, duration=30, description='You need to buy this', is_active=True)]
104
+ ```
105
+
106
+ ### Serialized Response with HTTP Info
107
+ ```python
108
+ await client.pay.products.get_products_with_http_info()
109
+ print(res)
110
+ ```
111
+ The output would look like this:
112
+ ```python
113
+ status_code=200 headers={'Date': 'Wed, 09 Apr 2025 19:15:19 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Alt-Svc': 'h3=":443"; ma=86400', 'Server': 'cloudflare', 'Cf-Cache-Status': 'DYNAMIC', 'Content-Encoding': 'gzip', 'CF-RAY': '92dc551a687bbe5e-ZRH'} data=[ProductModel(id='67e8146e7bae32f3838fe36a', name='Awesome Product', price=5.0, scopes=None, duration=30, description='You need to buy this', is_active=True)] raw_data=b'[{"id":"67e8146e7bae32f3838fe36a","name":"Awesome Product","price":5.0,"duration":30,"description":"You need to buy this","is_active":true}]'
114
+ ```
115
+ You can then access the data of the response (as serialized output) with:
116
+ ```python
117
+ print(res.data)
118
+ ```
119
+ On top of that you get some information about the request:
120
+ ```python
121
+ print(res.status_code)
122
+ print(res.raw_data)
123
+ print(res.headers)
124
+
125
+
126
+ ### JSON Response
127
+ You can receive a classical JSON response by suffixing the function name with `_without_preload_content`
128
+ ```python
129
+ response = await client.pay.products.get_products_without_preload_content()
130
+ print(await response.json())
131
+ ```
132
+ The output would look like this:
133
+ ```python
134
+ [{'id': '67e8146e7bae32f3838fe36a', 'name': 'Awesome Product', 'price': 5.0, 'duration': 30, 'description': 'You need to buy this', 'is_active': True}]
135
+ ```
136
+
137
+ ## Advanced Usage
138
+
139
+ You can override some configuration for specific sub clients. If just want to use the API as is you don't need to configure anything.
140
+ This might be of use if you are testing a specific API locally.
141
+
142
+ This will override the host for the Hive client to connect to http://localhost:8000 instead of the default caddy proxy:
143
+ ```python
144
+ async with ApiClient(base_url=BaseUrl.DEV, jwt=jwt) as client:
145
+ client.configure(config=HiveConfig(host="http://localhost:8000"), sub_client=client.hive)
146
+ ```
@@ -1,7 +1,7 @@
1
1
  crypticorn/__init__.py,sha256=TL41V09dmtbd2ee07wmOuG9KJJpyvLMPJi5DEd9bDyU,129
2
- crypticorn/client.py,sha256=mj36LuJH9fF7rb_kKJuifAAepmU1j-jnWqk7a_q4jz4,2058
2
+ crypticorn/client.py,sha256=VleHzia13Fa_N3CK5ifktdd43IQl4u0CKQrfWtu2WiU,4320
3
3
  crypticorn/auth/__init__.py,sha256=JAl1tBLK9pYLr_-YKaj581c-c94PWLoqnatTIVAVvMM,81
4
- crypticorn/auth/main.py,sha256=ljPuO27VDiOO-jnNycBn96X8UbVHPgOUglj46ib3OjM,1336
4
+ crypticorn/auth/main.py,sha256=1ggu7V--I43TLWu2TLFRSnQmtaJEs8C8FbSXycCdvkI,686
5
5
  crypticorn/auth/client/__init__.py,sha256=ziGgrJ7judjAwOaSKF-7lgs1zhE-XEZkMYKD0WUkHfs,4990
6
6
  crypticorn/auth/client/api_client.py,sha256=H2jviD8CKiFnK1ZZXWKbSdBszBYcCQNcga9pwgM03D4,26908
7
7
  crypticorn/auth/client/api_response.py,sha256=WhxwYDSMm6wPixp9CegO8dJzjFxDz3JF1yCq9s0ZqKE,639
@@ -54,15 +54,14 @@ crypticorn/auth/client/models/verify_email_request.py,sha256=8MBfxPTLn5X6Z3vE2bl
54
54
  crypticorn/auth/client/models/verify_wallet_request.py,sha256=b0DAocvhKzPXPjM62DZqezlHxq3cNL7UVKl0d2judHQ,2691
55
55
  crypticorn/auth/client/models/wallet_verified200_response.py,sha256=QILnTLsCKdI-WdV_fsLBy1UH4ZZU-U-wWJ9ot8v08tI,2465
56
56
  crypticorn/auth/client/models/whoami200_response.py,sha256=uehdq5epgeOphhrIR3tbrseflxcLAzGyKF-VW-o5cY8,2974
57
- crypticorn/common/__init__.py,sha256=lY87VMTkIEqto6kcEjC1YWsUvT03QuPmXwxCaeWE854,196
58
- crypticorn/common/auth.py,sha256=LEnTh2bqbljCdTNJUqTOTo2Q39gEz0JRumF1Z5MHQz0,319
59
- crypticorn/common/auth_client.py,sha256=7ICjLRPOIXzEJXW76BgVxkNfi_QjuRdLZBX6TNvTpJE,7588
57
+ crypticorn/common/__init__.py,sha256=8QvHfHNl5CsTOuNBag9fXZ6PZdfyAveIBeVL_37Db1U,151
58
+ crypticorn/common/auth.py,sha256=NZMM0zGCgMn0lBV71EZ428it9tGdnPnTUHKthPx4kyg,7482
60
59
  crypticorn/common/errors.py,sha256=Yd3zLtrqCe0NvjfqxIHohT48T4yfSi-V4s_WyYAi8t4,12614
61
- crypticorn/common/scopes.py,sha256=pRD9RauSRSxVGo8k5b2x66h3Wy2aaVEcluZvu6aMTE0,1418
60
+ crypticorn/common/scopes.py,sha256=-dkEjY2AVAjdub4zLMy6IFltzii_Ll0NBaSWtI7w4BU,1419
62
61
  crypticorn/common/sorter.py,sha256=DPkQmxDeuti4onCiE8IJZUkTc5WZp1j4dIIc7wN9En0,1167
63
- crypticorn/common/urls.py,sha256=6--K5hJjNjVAIxQA9SdT20AZsDjTmFsamHTNabgiCw8,456
62
+ crypticorn/common/urls.py,sha256=twMpsXnGZhxa4-sV8Pmt4n0VUzVd_xUNiyGD2BckFKM,803
64
63
  crypticorn/hive/__init__.py,sha256=hRfTlEzEql4msytdUC_04vfaHzVKG5CGZle1M-9QFgY,81
65
- crypticorn/hive/main.py,sha256=RmCYSR0jwmfYWTK89dt79DuGPjEaip9XQs_LWNWr_tc,1036
64
+ crypticorn/hive/main.py,sha256=U4wurkxnKai2i7iiq049ah9nVzBxmexRxBdFIWfd9qE,631
66
65
  crypticorn/hive/client/__init__.py,sha256=DIj3v16Yq5l6yMPoywrL2sOvQ6ZqpAsSJuhssIp8JFQ,2396
67
66
  crypticorn/hive/client/api_client.py,sha256=KAz4MLfl1U6HCTx4qDWnWlIR6_SF4Q3Bq_Uq7OhHkT8,26889
68
67
  crypticorn/hive/client/api_response.py,sha256=WhxwYDSMm6wPixp9CegO8dJzjFxDz3JF1yCq9s0ZqKE,639
@@ -94,7 +93,7 @@ crypticorn/hive/client/models/target_type.py,sha256=8mdPpdfY_HZCMHhAWqiC1FQlrGSL
94
93
  crypticorn/hive/client/models/validation_error.py,sha256=YUfTXf3JIoubcwOkCqoNB4agJ6RrBIkJOFDfEjvgEiA,3166
95
94
  crypticorn/hive/client/models/validation_error_loc_inner.py,sha256=YeiVGPRvKAIijEbK6-fAnVo1A4U2d5d_LOyZ7P3jPoY,5070
96
95
  crypticorn/klines/__init__.py,sha256=9UUW013uZ5x4evz5zRUxbNid-6O9WAPPYvPZIHpAwms,87
97
- crypticorn/klines/main.py,sha256=Md1VqaFSwlbO9ZY4v8VIBYQr2kuYnsxgfaDpisDFarA,2187
96
+ crypticorn/klines/main.py,sha256=r43Q2CVp7-gqNT9gjtfALRyN5Dp4xCyw6YOWAPVIDik,1710
98
97
  crypticorn/klines/client/__init__.py,sha256=i4zgrQsA1BXPYa0YLnSOrStKk1iJyJw-2KDOtTDdizg,3795
99
98
  crypticorn/klines/client/api_client.py,sha256=Sih490VSmIfdDEq0A_ULlx7HR_e03bExGYta1kZEO7Y,27135
100
99
  crypticorn/klines/client/api_response.py,sha256=WhxwYDSMm6wPixp9CegO8dJzjFxDz3JF1yCq9s0ZqKE,639
@@ -135,7 +134,7 @@ crypticorn/klines/client/models/udf_config_response.py,sha256=VRBMwoCmtjSooF_Txq
135
134
  crypticorn/klines/client/models/validation_error.py,sha256=TMfS5WKx6jSNPdppQA5Yax-r3k0Gn31raWyTZPMsDPg,3509
136
135
  crypticorn/klines/client/models/validation_error_loc_inner.py,sha256=tUClZ2b89NWJWHagBsZ5rlEjiV1vn4sgpAncHKUIZRg,5411
137
136
  crypticorn/metrics/__init__.py,sha256=VT1pPYATCS_t_FFB14xYheb1YVyghFiHAT-RapO3NEY,120
138
- crypticorn/metrics/main.py,sha256=HeVj1B-OqeAoSQU1OIMngoSsPwZjBckNb1UC866obtE,3636
137
+ crypticorn/metrics/main.py,sha256=k0JYZyEgjtvYJmAxkKqETsBOFH9ZZkohhNh6dvKXHwM,3120
139
138
  crypticorn/metrics/client/__init__.py,sha256=9ooMGJCbi9evO8IklEjgRXdVZsuA8d4sTcKhijo7IHs,2799
140
139
  crypticorn/metrics/client/api_client.py,sha256=vP_byGPqgDnmt9nV2YXUiiYWFsJ3HWWi2s81f7gp8vU,27139
141
140
  crypticorn/metrics/client/api_response.py,sha256=WhxwYDSMm6wPixp9CegO8dJzjFxDz3JF1yCq9s0ZqKE,639
@@ -166,7 +165,7 @@ crypticorn/metrics/client/models/severity.py,sha256=7qCflKy5HPy6EL6Ig3bencZnddnu
166
165
  crypticorn/metrics/client/models/validation_error.py,sha256=yCwcbJ9w7lr_jSgcbsl2C37Zr9h93iAZxdHc7lKqeZs,3401
167
166
  crypticorn/metrics/client/models/validation_error_loc_inner.py,sha256=Rki-HutGR9cicKt_OP2vN-5-ofpvPsmT6VpSYeMfJfI,5302
168
167
  crypticorn/pay/__init__.py,sha256=ux-B-YbNetpTlZTb2fijuGUOEmSm4IB0fYtieGnVDBg,78
169
- crypticorn/pay/main.py,sha256=DbwP_DI5Zp3Ow-Fq2khnnb0hOvrpA29e-jeRyrCCbBs,1075
168
+ crypticorn/pay/main.py,sha256=6sCELtBpQglCDpHlOtCMfWct_itCNv9QZCeumZI22A0,601
170
169
  crypticorn/pay/client/__init__.py,sha256=-Nk_UoRtKtpbY1-9iP1hUdDczdP6eE3T_Z1wVNhkAZo,2377
171
170
  crypticorn/pay/client/api_client.py,sha256=kZqhvF9r2vqqOYnnu6hTAQVWPmzjFKhC9efShUCfr7o,26944
172
171
  crypticorn/pay/client/api_response.py,sha256=WhxwYDSMm6wPixp9CegO8dJzjFxDz3JF1yCq9s0ZqKE,639
@@ -216,7 +215,7 @@ crypticorn/pay/client/models/unified_payment_model.py,sha256=_Y9OtWZ-N7QDxsCte0U
216
215
  crypticorn/pay/client/models/validation_error.py,sha256=vzw1GCCSx0Tct-t8b4IfNQe4jaioantmwbwz2Cmi4AA,3226
217
216
  crypticorn/pay/client/models/validation_error_loc_inner.py,sha256=8Fp046J4qWnAIBATnrzS9qiKZKDY4C3UxSOJo9DTTcQ,5131
218
217
  crypticorn/trade/__init__.py,sha256=QzScH9n-ly3QSaBSpPP7EqYwhdzDqYCZJs0-AhEhrsY,84
219
- crypticorn/trade/main.py,sha256=UapbqtrjsgpjouNuCYxnP8iqcSEMRWCvxq8uN-JecvU,1520
218
+ crypticorn/trade/main.py,sha256=UZQ9ZJlus5CHLZBOimF6Cr4vx9ocTL5SjRA69MZ73tQ,1044
220
219
  crypticorn/trade/client/__init__.py,sha256=Wa4Pn_QmZfZpScj3eM5hTh1gxcg9j9O13jImEySmQJ0,3480
221
220
  crypticorn/trade/client/api_client.py,sha256=GZFlYDIxGpPWtK6CnTqZLN8kWSSSzcdziNY4kTB1hE4,26956
222
221
  crypticorn/trade/client/api_response.py,sha256=WhxwYDSMm6wPixp9CegO8dJzjFxDz3JF1yCq9s0ZqKE,639
@@ -260,7 +259,7 @@ crypticorn/trade/client/models/tpsl.py,sha256=QGPhcgadjxAgyzpRSwlZJg_CDLnKxdZgse
260
259
  crypticorn/trade/client/models/trading_action_type.py,sha256=jW0OsNz_ZNXlITxAfh979BH5U12oTXSr6qUVcKcGHhw,847
261
260
  crypticorn/trade/client/models/validation_error.py,sha256=uTkvsKrOAt-21UC0YPqCdRl_OMsuu7uhPtWuwRSYvv0,3228
262
261
  crypticorn/trade/client/models/validation_error_loc_inner.py,sha256=22ql-H829xTBgfxNQZsqd8fS3zQt9tLW1pj0iobo0jY,5131
263
- crypticorn-2.1.6.dist-info/METADATA,sha256=adfjnqk3cy9RW0emSxZkbuoeVNmnQutbmUtfLdElhF0,3138
264
- crypticorn-2.1.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
265
- crypticorn-2.1.6.dist-info/top_level.txt,sha256=EP3NY216qIBYfmvGl0L2Zc9ItP0DjGSkiYqd9xJwGcM,11
266
- crypticorn-2.1.6.dist-info/RECORD,,
262
+ crypticorn-2.2.0.dist-info/METADATA,sha256=aLpVj-g7X_LrGymsLqnbiByREFUDLZsHSScoeo2djPk,5393
263
+ crypticorn-2.2.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
264
+ crypticorn-2.2.0.dist-info/top_level.txt,sha256=EP3NY216qIBYfmvGl0L2Zc9ItP0DjGSkiYqd9xJwGcM,11
265
+ crypticorn-2.2.0.dist-info/RECORD,,
@@ -1,213 +0,0 @@
1
- from fastapi import Depends, HTTPException, Query, status
2
- from fastapi.security import HTTPAuthorizationCredentials, SecurityScopes
3
- from typing_extensions import Annotated, Doc
4
- import json
5
-
6
- from crypticorn.auth import AuthClient, Verify200Response
7
- from crypticorn.auth.client.exceptions import ApiException
8
- from crypticorn.common import (
9
- ApiError,
10
- Scope,
11
- ApiVersion,
12
- BaseURL,
13
- Domain,
14
- apikey_header,
15
- http_bearer,
16
- )
17
-
18
-
19
- class AuthHandler:
20
- """
21
- Middleware for verifying API requests. Verifies the validity of the authentication token, allowed scopes, etc.
22
- """
23
-
24
- def __init__(
25
- self,
26
- base_url: Annotated[
27
- BaseURL, Doc("The base URL for the auth service.")
28
- ] = BaseURL.PROD,
29
- api_version: Annotated[
30
- ApiVersion, Doc("The API version of the auth service.")
31
- ] = ApiVersion.V1,
32
- whitelist: Annotated[
33
- list[Domain],
34
- Doc(
35
- "The domains of which requests are allowed full access to the service."
36
- ),
37
- ] = [
38
- Domain.PROD,
39
- Domain.DEV,
40
- ], # TODO: decide whether this is needed, else omit
41
- ):
42
- self.whitelist = whitelist
43
- self.auth_client = AuthClient(base_url=base_url, api_version=api_version)
44
-
45
- self.no_credentials_exception = HTTPException(
46
- status_code=status.HTTP_401_UNAUTHORIZED,
47
- detail=ApiError.NO_CREDENTIALS.identifier,
48
- )
49
-
50
- async def _verify_api_key(self, api_key: str) -> None:
51
- """
52
- Verifies the API key.
53
- """
54
- return await self.auth_client.login.verify_api_key(api_key)
55
-
56
- async def _verify_bearer(
57
- self, bearer: HTTPAuthorizationCredentials
58
- ) -> Verify200Response:
59
- """
60
- Verifies the bearer token.
61
- """
62
- self.auth_client.config.access_token = bearer.credentials
63
- return await self.auth_client.login.verify()
64
-
65
- async def _validate_scopes(
66
- self, api_scopes: list[Scope], user_scopes: list[Scope]
67
- ) -> bool:
68
- """
69
- Checks if the user scopes are a subset of the API scopes.
70
- """
71
- if not set(api_scopes).issubset(user_scopes):
72
- raise HTTPException(
73
- status_code=status.HTTP_403_FORBIDDEN,
74
- detail=ApiError.INSUFFICIENT_SCOPES.identifier,
75
- )
76
-
77
- async def _extract_message(self, e: ApiException) -> str:
78
- """
79
- Tries to extract the message from the body of the exception.
80
- """
81
- try:
82
- load = json.loads(e.body)
83
- except (json.JSONDecodeError, TypeError):
84
- return e.body
85
- else:
86
- common_keys = ["message"]
87
- for key in common_keys:
88
- if key in load:
89
- return load[key]
90
- return load
91
-
92
- async def _handle_exception(self, e: Exception) -> HTTPException:
93
- """
94
- Handles exceptions and returns a HTTPException with the appropriate status code and detail.
95
- """
96
- if isinstance(e, ApiException):
97
- return HTTPException(
98
- status_code=e.status,
99
- detail=await self._extract_message(e),
100
- )
101
- elif isinstance(e, HTTPException):
102
- return e
103
- else:
104
- return HTTPException(
105
- status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
106
- detail=str(e),
107
- )
108
-
109
- async def api_key_auth(
110
- self,
111
- api_key: Annotated[str | None, Depends(apikey_header)] = None,
112
- sec: SecurityScopes = SecurityScopes(),
113
- ) -> Verify200Response:
114
- """
115
- Verifies the API key and checks if the user scopes are a subset of the API scopes.
116
- Use this function if you only want to allow access via the API key.
117
- """
118
- return await self.combined_auth(bearer=None, api_key=api_key, sec=sec)
119
-
120
- async def bearer_auth(
121
- self,
122
- bearer: Annotated[
123
- HTTPAuthorizationCredentials | None,
124
- Depends(http_bearer),
125
- ] = None,
126
- sec: SecurityScopes = SecurityScopes(),
127
- ) -> Verify200Response:
128
- """
129
- Verifies the bearer token and checks if the user scopes are a subset of the API scopes.
130
- Use this function if you only want to allow access via the bearer token.
131
- """
132
- return await self.combined_auth(bearer=bearer, api_key=None, sec=sec)
133
-
134
- async def combined_auth(
135
- self,
136
- bearer: Annotated[
137
- HTTPAuthorizationCredentials | None, Depends(http_bearer)
138
- ] = None,
139
- api_key: Annotated[str | None, Depends(apikey_header)] = None,
140
- sec: SecurityScopes = SecurityScopes(),
141
- ) -> Verify200Response:
142
- """
143
- Verifies the bearer token and/or API key and checks if the user scopes are a subset of the API scopes.
144
- Returns early on the first successful verification, otherwise tries all available tokens.
145
- Use this function if you want to allow access via either the bearer token or the API key.
146
- """
147
- tokens = [bearer, api_key]
148
-
149
- last_error = None
150
- for token in tokens:
151
- try:
152
- if token is None:
153
- continue
154
- res = None
155
- if isinstance(token, str):
156
- res = await self._verify_api_key(token)
157
- elif isinstance(token, HTTPAuthorizationCredentials):
158
- res = await self._verify_bearer(token)
159
- if res is None:
160
- continue
161
- if sec:
162
- await self._validate_scopes(sec.scopes, res.scopes)
163
- return res
164
-
165
- except Exception as e:
166
- last_error = await self._handle_exception(e)
167
- continue
168
-
169
- raise last_error or self.no_credentials_exception
170
-
171
- async def ws_api_key_auth(
172
- self,
173
- api_key: Annotated[str | None, Query()] = None,
174
- sec: SecurityScopes = SecurityScopes(),
175
- ) -> Verify200Response:
176
- """
177
- Verifies the API key and checks if the user scopes are a subset of the API scopes.
178
- Use this function if you only want to allow access via the API key.
179
- """
180
- return await self.api_key_auth(api_key=api_key, sec=sec)
181
-
182
- async def ws_bearer_auth(
183
- self,
184
- bearer: Annotated[str | None, Query()] = None,
185
- sec: SecurityScopes = SecurityScopes(),
186
- ) -> Verify200Response:
187
- """
188
- Verifies the bearer token and checks if the user scopes are a subset of the API scopes.
189
- Use this function if you only want to allow access via the bearer token.
190
- """
191
- credentials = (
192
- HTTPAuthorizationCredentials(scheme="Bearer", credentials=bearer)
193
- if bearer
194
- else None
195
- )
196
- return await self.bearer_auth(bearer=credentials, sec=sec)
197
-
198
- async def ws_combined_auth(
199
- self,
200
- bearer: Annotated[str | None, Query()] = None,
201
- api_key: Annotated[str | None, Query()] = None,
202
- sec: SecurityScopes = SecurityScopes(),
203
- ) -> Verify200Response:
204
- """
205
- Verifies the bearer token and/or API key and checks if the user scopes are a subset of the API scopes.
206
- Use this function if you want to allow access via either the bearer token or the API key.
207
- """
208
- credentials = (
209
- HTTPAuthorizationCredentials(scheme="Bearer", credentials=bearer)
210
- if bearer
211
- else None
212
- )
213
- return await self.combined_auth(bearer=credentials, api_key=api_key, sec=sec)
@@ -1,92 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: crypticorn
3
- Version: 2.1.6
4
- Summary: Maximise Your Crypto Trading Profits with AI Predictions
5
- Author-email: Crypticorn <timon@crypticorn.com>
6
- Project-URL: Homepage, https://crypticorn.com
7
- Keywords: machine learning,data science,crypto,modelling
8
- Classifier: Topic :: Scientific/Engineering
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Intended Audience :: Science/Research
11
- Classifier: Operating System :: OS Independent
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Typing :: Typed
14
- Requires-Python: >=3.10
15
- Description-Content-Type: text/markdown
16
- Requires-Dist: fastapi
17
- Requires-Dist: urllib3<3.0.0,>=1.25.3
18
- Requires-Dist: python_dateutil<3.0.0,>=2.8.2
19
- Requires-Dist: aiohttp<4.0.0,>=3.8.4
20
- Requires-Dist: aiohttp-retry<3.0.0,>=2.8.3
21
- Requires-Dist: pydantic<3.0.0,>=2.0.0
22
- Requires-Dist: typing-extensions<5.0.0,>=4.7.1
23
- Requires-Dist: pandas<3.0.0,>=2.2.0
24
- Requires-Dist: requests<3.0.0,>=2.32.0
25
- Requires-Dist: tqdm<5.0.0,>=4.67.0
26
- Provides-Extra: dev
27
- Requires-Dist: streamlit; extra == "dev"
28
- Requires-Dist: httpx; extra == "dev"
29
- Requires-Dist: build; extra == "dev"
30
- Requires-Dist: black; extra == "dev"
31
- Requires-Dist: twine; extra == "dev"
32
- Requires-Dist: pyflakes; extra == "dev"
33
- Provides-Extra: test
34
- Requires-Dist: pytest==8.3.5; extra == "test"
35
- Requires-Dist: pytest-asyncio==0.26.0; extra == "test"
36
- Requires-Dist: pytest-cov==6.1.1; extra == "test"
37
- Requires-Dist: python-dotenv==1.0.1; extra == "test"
38
-
39
- # What is Crypticorn?
40
-
41
- Crypticorn is at the forefront of cutting-edge artificial intelligence cryptocurrency trading.
42
- Crypticorn offers AI-based solutions for both active and passive investors, including:
43
- - Prediction Dashboard with trading terminal,
44
- - AI Agents with different strategies,
45
- - DEX AI Signals for newly launched tokens,
46
- - DEX AI Bots
47
-
48
- Use this API Client to contribute to the so-called Hive AI, a community driven AI Meta Model for predicting the
49
- cryptocurrency market.
50
-
51
- ## Installation
52
-
53
- You can install the latest stable version from PyPi:
54
- ```bash
55
- pip install crypticorn
56
- ```
57
-
58
- If you want a specific version, run:
59
- ```bash
60
- pip install crypticorn==2.0.0
61
- ```
62
-
63
- If you want the latest version, which could be a pre release, run:
64
- ```bash
65
- pip install --pre crypticorn
66
- ```
67
-
68
- ## Usage
69
-
70
- As of know the library is available in async mode only. There are two was of using it.
71
-
72
- ## With Async Context Protocol
73
- ```python
74
- async with ApiClient(base_url=BaseUrl.Prod, api_key="your-api-key") as client:
75
- # json response
76
- response = await client.pay.products.get_products_without_preload_content()
77
- print(await response.json())
78
- # serialized response with pydantic models
79
- response = await client.pay.products.get_products()
80
- print(response)
81
- # json response with http info
82
- response = await client.pay.products.get_products_with_http_info()
83
- print(response)
84
- ```
85
-
86
- ## Without Async Context Protocol
87
- Without the context you need to close the session manually.
88
- ```python
89
- client = ApiClient(base_url=BaseUrl.Prod, api_key="your-api-key")
90
- response = asyncio.run(client.hive.models.get_all_models())
91
- asyncio.run(client.close())
92
- ```