crypticorn 2.15.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.
- crypticorn/__init__.py +2 -2
- crypticorn/auth/client/api/admin_api.py +397 -13
- crypticorn/auth/client/api/auth_api.py +3610 -341
- crypticorn/auth/client/api/service_api.py +249 -7
- crypticorn/auth/client/api/user_api.py +2295 -179
- crypticorn/auth/client/api/wallet_api.py +1468 -81
- crypticorn/auth/client/configuration.py +2 -2
- crypticorn/auth/client/models/create_api_key_request.py +2 -1
- crypticorn/auth/client/models/get_api_keys200_response_inner.py +2 -1
- crypticorn/auth/client/rest.py +23 -4
- crypticorn/auth/main.py +8 -5
- crypticorn/cli/init.py +1 -1
- crypticorn/cli/templates/.env.docker.temp +3 -0
- crypticorn/cli/templates/.env.example.temp +4 -0
- crypticorn/cli/templates/Dockerfile +5 -2
- crypticorn/client.py +226 -59
- crypticorn/common/__init__.py +1 -0
- crypticorn/common/auth.py +45 -14
- crypticorn/common/decorators.py +1 -2
- crypticorn/common/enums.py +0 -2
- crypticorn/common/errors.py +10 -0
- crypticorn/common/metrics.py +30 -0
- crypticorn/common/middleware.py +94 -1
- crypticorn/common/pagination.py +252 -18
- crypticorn/common/router/admin_router.py +2 -2
- crypticorn/common/router/status_router.py +40 -2
- crypticorn/common/scopes.py +2 -0
- crypticorn/common/warnings.py +8 -0
- crypticorn/dex/__init__.py +6 -0
- crypticorn/dex/client/__init__.py +49 -0
- crypticorn/dex/client/api/__init__.py +6 -0
- crypticorn/dex/client/api/admin_api.py +2986 -0
- crypticorn/dex/client/api/signals_api.py +1798 -0
- crypticorn/dex/client/api/status_api.py +892 -0
- crypticorn/dex/client/api_client.py +758 -0
- crypticorn/dex/client/api_response.py +20 -0
- crypticorn/dex/client/configuration.py +620 -0
- crypticorn/dex/client/exceptions.py +220 -0
- crypticorn/dex/client/models/__init__.py +30 -0
- crypticorn/dex/client/models/api_error_identifier.py +121 -0
- crypticorn/dex/client/models/api_error_level.py +37 -0
- crypticorn/dex/client/models/api_error_type.py +37 -0
- crypticorn/dex/client/models/exception_detail.py +117 -0
- crypticorn/dex/client/models/log_level.py +38 -0
- crypticorn/dex/client/models/paginated_response_signal_with_token.py +134 -0
- crypticorn/dex/client/models/risk.py +86 -0
- crypticorn/dex/client/models/signal_overview_stats.py +158 -0
- crypticorn/dex/client/models/signal_volume.py +84 -0
- crypticorn/dex/client/models/signal_with_token.py +163 -0
- crypticorn/dex/client/models/token_data.py +127 -0
- crypticorn/dex/client/models/token_detail.py +116 -0
- crypticorn/dex/client/py.typed +0 -0
- crypticorn/dex/client/rest.py +217 -0
- crypticorn/dex/main.py +1 -0
- crypticorn/hive/client/api/admin_api.py +1173 -47
- crypticorn/hive/client/api/data_api.py +499 -17
- crypticorn/hive/client/api/models_api.py +1595 -87
- crypticorn/hive/client/api/status_api.py +397 -16
- crypticorn/hive/client/api_client.py +0 -5
- crypticorn/hive/client/models/api_error_identifier.py +1 -1
- crypticorn/hive/client/models/coin_info.py +1 -1
- crypticorn/hive/client/models/exception_detail.py +1 -1
- crypticorn/hive/client/models/target_info.py +1 -1
- crypticorn/hive/client/rest.py +23 -4
- crypticorn/hive/main.py +99 -25
- crypticorn/hive/utils.py +2 -2
- crypticorn/klines/client/api/admin_api.py +1173 -47
- crypticorn/klines/client/api/change_in_timeframe_api.py +269 -11
- crypticorn/klines/client/api/funding_rates_api.py +315 -11
- crypticorn/klines/client/api/ohlcv_data_api.py +390 -11
- crypticorn/klines/client/api/status_api.py +397 -16
- crypticorn/klines/client/api/symbols_api.py +216 -11
- crypticorn/klines/client/api/udf_api.py +1268 -51
- crypticorn/klines/client/api_client.py +0 -5
- crypticorn/klines/client/models/api_error_identifier.py +3 -1
- crypticorn/klines/client/models/exception_detail.py +1 -1
- crypticorn/klines/client/models/ohlcv.py +1 -1
- crypticorn/klines/client/models/symbol_group.py +1 -1
- crypticorn/klines/client/models/udf_config.py +1 -1
- crypticorn/klines/client/rest.py +23 -4
- crypticorn/klines/main.py +89 -12
- crypticorn/metrics/client/api/admin_api.py +1173 -47
- crypticorn/metrics/client/api/exchanges_api.py +1370 -145
- crypticorn/metrics/client/api/indicators_api.py +622 -17
- crypticorn/metrics/client/api/logs_api.py +296 -11
- crypticorn/metrics/client/api/marketcap_api.py +1207 -67
- crypticorn/metrics/client/api/markets_api.py +343 -11
- crypticorn/metrics/client/api/quote_currencies_api.py +228 -11
- crypticorn/metrics/client/api/status_api.py +397 -16
- crypticorn/metrics/client/api/tokens_api.py +382 -15
- crypticorn/metrics/client/api_client.py +0 -5
- crypticorn/metrics/client/configuration.py +4 -2
- crypticorn/metrics/client/models/exception_detail.py +1 -1
- crypticorn/metrics/client/models/exchange_mapping.py +1 -1
- crypticorn/metrics/client/models/marketcap_ranking.py +1 -1
- crypticorn/metrics/client/models/marketcap_symbol_ranking.py +1 -1
- crypticorn/metrics/client/models/ohlcv.py +1 -1
- crypticorn/metrics/client/rest.py +23 -4
- crypticorn/metrics/main.py +113 -19
- crypticorn/pay/client/api/admin_api.py +1585 -57
- crypticorn/pay/client/api/now_payments_api.py +961 -39
- crypticorn/pay/client/api/payments_api.py +562 -17
- crypticorn/pay/client/api/products_api.py +880 -30
- crypticorn/pay/client/api/status_api.py +397 -16
- crypticorn/pay/client/api_client.py +0 -5
- crypticorn/pay/client/configuration.py +2 -2
- crypticorn/pay/client/models/api_error_identifier.py +7 -7
- crypticorn/pay/client/models/exception_detail.py +1 -1
- crypticorn/pay/client/models/now_create_invoice_req.py +1 -1
- crypticorn/pay/client/models/now_create_invoice_res.py +1 -1
- crypticorn/pay/client/models/product.py +1 -1
- crypticorn/pay/client/models/product_create.py +1 -1
- crypticorn/pay/client/models/product_update.py +1 -1
- crypticorn/pay/client/models/scope.py +1 -0
- crypticorn/pay/client/rest.py +23 -4
- crypticorn/pay/main.py +10 -6
- crypticorn/trade/client/__init__.py +11 -1
- crypticorn/trade/client/api/__init__.py +0 -1
- crypticorn/trade/client/api/admin_api.py +1184 -55
- crypticorn/trade/client/api/api_keys_api.py +1678 -162
- crypticorn/trade/client/api/bots_api.py +7563 -187
- crypticorn/trade/client/api/exchanges_api.py +565 -19
- crypticorn/trade/client/api/notifications_api.py +1290 -116
- crypticorn/trade/client/api/orders_api.py +393 -55
- crypticorn/trade/client/api/status_api.py +397 -13
- crypticorn/trade/client/api/strategies_api.py +1133 -77
- crypticorn/trade/client/api/trading_actions_api.py +786 -65
- crypticorn/trade/client/models/__init__.py +11 -0
- crypticorn/trade/client/models/actions_count.py +88 -0
- crypticorn/trade/client/models/api_error_identifier.py +8 -7
- crypticorn/trade/client/models/bot.py +7 -18
- crypticorn/trade/client/models/bot_create.py +17 -1
- crypticorn/trade/client/models/bot_update.py +17 -1
- crypticorn/trade/client/models/exchange.py +6 -1
- crypticorn/trade/client/models/exchange_key.py +1 -1
- crypticorn/trade/client/models/exchange_key_balance.py +111 -0
- crypticorn/trade/client/models/exchange_key_create.py +17 -1
- crypticorn/trade/client/models/exchange_key_update.py +17 -1
- crypticorn/trade/client/models/execution_ids.py +1 -1
- crypticorn/trade/client/models/futures_balance.py +27 -25
- crypticorn/trade/client/models/futures_trading_action.py +6 -28
- crypticorn/trade/client/models/futures_trading_action_create.py +10 -13
- crypticorn/trade/client/models/notification.py +17 -1
- crypticorn/trade/client/models/notification_create.py +18 -2
- crypticorn/trade/client/models/notification_update.py +17 -1
- crypticorn/trade/client/models/order.py +2 -14
- crypticorn/trade/client/models/orders_count.py +88 -0
- crypticorn/trade/client/models/paginated_response_futures_trading_action.py +134 -0
- crypticorn/trade/client/models/paginated_response_order.py +134 -0
- crypticorn/trade/client/models/pn_l.py +95 -0
- crypticorn/trade/client/models/post_futures_action.py +1 -1
- crypticorn/trade/client/models/spot_balance.py +109 -0
- crypticorn/trade/client/models/spot_trading_action_create.py +4 -1
- crypticorn/trade/client/models/strategy.py +22 -4
- crypticorn/trade/client/models/strategy_create.py +23 -5
- crypticorn/trade/client/models/strategy_exchange_info.py +16 -4
- crypticorn/trade/client/models/strategy_update.py +19 -3
- crypticorn/trade/client/models/tpsl.py +4 -27
- crypticorn/trade/client/models/tpsl_create.py +6 -19
- crypticorn/trade/client/rest.py +23 -4
- crypticorn/trade/main.py +15 -12
- {crypticorn-2.15.0.dist-info → crypticorn-2.17.0.dist-info}/METADATA +65 -20
- {crypticorn-2.15.0.dist-info → crypticorn-2.17.0.dist-info}/RECORD +167 -132
- crypticorn/trade/client/api/futures_trading_panel_api.py +0 -1285
- {crypticorn-2.15.0.dist-info → crypticorn-2.17.0.dist-info}/WHEEL +0 -0
- {crypticorn-2.15.0.dist-info → crypticorn-2.17.0.dist-info}/entry_points.txt +0 -0
- {crypticorn-2.15.0.dist-info → crypticorn-2.17.0.dist-info}/licenses/LICENSE +0 -0
- {crypticorn-2.15.0.dist-info → crypticorn-2.17.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
"""
|
4
|
+
DEX AI API
|
5
|
+
|
6
|
+
API for DEX AI
|
7
|
+
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
10
|
+
|
11
|
+
Do not edit the class manually.
|
12
|
+
""" # noqa: E501
|
13
|
+
|
14
|
+
|
15
|
+
from __future__ import annotations
|
16
|
+
import pprint
|
17
|
+
import re # noqa: F401
|
18
|
+
import json
|
19
|
+
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
|
21
|
+
from typing import Any, ClassVar, Dict, List
|
22
|
+
from crypticorn.dex.client.models.risk import Risk
|
23
|
+
from crypticorn.dex.client.models.token_detail import TokenDetail
|
24
|
+
from typing import Optional, Set
|
25
|
+
from typing_extensions import Self
|
26
|
+
|
27
|
+
|
28
|
+
class TokenData(BaseModel):
|
29
|
+
"""
|
30
|
+
Main model for complete token data
|
31
|
+
""" # noqa: E501
|
32
|
+
|
33
|
+
token: TokenDetail = Field(description="Token details")
|
34
|
+
mcap: StrictStr = Field(description="Market cap")
|
35
|
+
price: StrictStr = Field(description="Price")
|
36
|
+
liquidity: StrictStr = Field(description="The liquidity of the token in USD")
|
37
|
+
risk: Risk = Field(description="Risk assessment")
|
38
|
+
buys: StrictInt = Field(description="Number of buys")
|
39
|
+
sells: StrictInt = Field(description="Number of sells")
|
40
|
+
txns: StrictInt = Field(description="Total transactions")
|
41
|
+
holders: StrictInt = Field(description="Number of holders")
|
42
|
+
__properties: ClassVar[List[str]] = [
|
43
|
+
"token",
|
44
|
+
"mcap",
|
45
|
+
"price",
|
46
|
+
"liquidity",
|
47
|
+
"risk",
|
48
|
+
"buys",
|
49
|
+
"sells",
|
50
|
+
"txns",
|
51
|
+
"holders",
|
52
|
+
]
|
53
|
+
|
54
|
+
model_config = ConfigDict(
|
55
|
+
populate_by_name=True,
|
56
|
+
validate_assignment=True,
|
57
|
+
protected_namespaces=(),
|
58
|
+
)
|
59
|
+
|
60
|
+
def to_str(self) -> str:
|
61
|
+
"""Returns the string representation of the model using alias"""
|
62
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
63
|
+
|
64
|
+
def to_json(self) -> str:
|
65
|
+
"""Returns the JSON representation of the model using alias"""
|
66
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
67
|
+
return json.dumps(self.to_dict())
|
68
|
+
|
69
|
+
@classmethod
|
70
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
71
|
+
"""Create an instance of TokenData from a JSON string"""
|
72
|
+
return cls.from_dict(json.loads(json_str))
|
73
|
+
|
74
|
+
def to_dict(self) -> Dict[str, Any]:
|
75
|
+
"""Return the dictionary representation of the model using alias.
|
76
|
+
|
77
|
+
This has the following differences from calling pydantic's
|
78
|
+
`self.model_dump(by_alias=True)`:
|
79
|
+
|
80
|
+
* `None` is only added to the output dict for nullable fields that
|
81
|
+
were set at model initialization. Other fields with value `None`
|
82
|
+
are ignored.
|
83
|
+
"""
|
84
|
+
excluded_fields: Set[str] = set([])
|
85
|
+
|
86
|
+
_dict = self.model_dump(
|
87
|
+
by_alias=True,
|
88
|
+
exclude=excluded_fields,
|
89
|
+
exclude_none=True,
|
90
|
+
)
|
91
|
+
# override the default output from pydantic by calling `to_dict()` of token
|
92
|
+
if self.token:
|
93
|
+
_dict["token"] = self.token.to_dict()
|
94
|
+
# override the default output from pydantic by calling `to_dict()` of risk
|
95
|
+
if self.risk:
|
96
|
+
_dict["risk"] = self.risk.to_dict()
|
97
|
+
return _dict
|
98
|
+
|
99
|
+
@classmethod
|
100
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
101
|
+
"""Create an instance of TokenData from a dict"""
|
102
|
+
if obj is None:
|
103
|
+
return None
|
104
|
+
|
105
|
+
if not isinstance(obj, dict):
|
106
|
+
return cls.model_validate(obj)
|
107
|
+
|
108
|
+
_obj = cls.model_validate(
|
109
|
+
{
|
110
|
+
"token": (
|
111
|
+
TokenDetail.from_dict(obj["token"])
|
112
|
+
if obj.get("token") is not None
|
113
|
+
else None
|
114
|
+
),
|
115
|
+
"mcap": obj.get("mcap"),
|
116
|
+
"price": obj.get("price"),
|
117
|
+
"liquidity": obj.get("liquidity"),
|
118
|
+
"risk": (
|
119
|
+
Risk.from_dict(obj["risk"]) if obj.get("risk") is not None else None
|
120
|
+
),
|
121
|
+
"buys": obj.get("buys"),
|
122
|
+
"sells": obj.get("sells"),
|
123
|
+
"txns": obj.get("txns"),
|
124
|
+
"holders": obj.get("holders"),
|
125
|
+
}
|
126
|
+
)
|
127
|
+
return _obj
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
"""
|
4
|
+
DEX AI API
|
5
|
+
|
6
|
+
API for DEX AI
|
7
|
+
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
10
|
+
|
11
|
+
Do not edit the class manually.
|
12
|
+
""" # noqa: E501
|
13
|
+
|
14
|
+
|
15
|
+
from __future__ import annotations
|
16
|
+
import pprint
|
17
|
+
import re # noqa: F401
|
18
|
+
import json
|
19
|
+
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, StrictStr
|
21
|
+
from typing import Any, ClassVar, Dict, List, Optional
|
22
|
+
from typing import Optional, Set
|
23
|
+
from typing_extensions import Self
|
24
|
+
|
25
|
+
|
26
|
+
class TokenDetail(BaseModel):
|
27
|
+
"""
|
28
|
+
Model for detailed token information
|
29
|
+
""" # noqa: E501
|
30
|
+
|
31
|
+
name: StrictStr = Field(description="Token name")
|
32
|
+
symbol: StrictStr = Field(description="Token symbol")
|
33
|
+
mint: StrictStr = Field(description="Token mint address (aka contract address)")
|
34
|
+
description: Optional[StrictStr] = None
|
35
|
+
image: Optional[StrictStr] = None
|
36
|
+
strict_socials: Optional[Dict[str, Any]] = Field(
|
37
|
+
default=None, description="Social media links", alias="strictSocials"
|
38
|
+
)
|
39
|
+
__properties: ClassVar[List[str]] = [
|
40
|
+
"name",
|
41
|
+
"symbol",
|
42
|
+
"mint",
|
43
|
+
"description",
|
44
|
+
"image",
|
45
|
+
"strictSocials",
|
46
|
+
]
|
47
|
+
|
48
|
+
model_config = ConfigDict(
|
49
|
+
populate_by_name=True,
|
50
|
+
validate_assignment=True,
|
51
|
+
protected_namespaces=(),
|
52
|
+
)
|
53
|
+
|
54
|
+
def to_str(self) -> str:
|
55
|
+
"""Returns the string representation of the model using alias"""
|
56
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
57
|
+
|
58
|
+
def to_json(self) -> str:
|
59
|
+
"""Returns the JSON representation of the model using alias"""
|
60
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
61
|
+
return json.dumps(self.to_dict())
|
62
|
+
|
63
|
+
@classmethod
|
64
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
65
|
+
"""Create an instance of TokenDetail from a JSON string"""
|
66
|
+
return cls.from_dict(json.loads(json_str))
|
67
|
+
|
68
|
+
def to_dict(self) -> Dict[str, Any]:
|
69
|
+
"""Return the dictionary representation of the model using alias.
|
70
|
+
|
71
|
+
This has the following differences from calling pydantic's
|
72
|
+
`self.model_dump(by_alias=True)`:
|
73
|
+
|
74
|
+
* `None` is only added to the output dict for nullable fields that
|
75
|
+
were set at model initialization. Other fields with value `None`
|
76
|
+
are ignored.
|
77
|
+
"""
|
78
|
+
excluded_fields: Set[str] = set([])
|
79
|
+
|
80
|
+
_dict = self.model_dump(
|
81
|
+
by_alias=True,
|
82
|
+
exclude=excluded_fields,
|
83
|
+
exclude_none=True,
|
84
|
+
)
|
85
|
+
# set to None if description (nullable) is None
|
86
|
+
# and model_fields_set contains the field
|
87
|
+
if self.description is None and "description" in self.model_fields_set:
|
88
|
+
_dict["description"] = None
|
89
|
+
|
90
|
+
# set to None if image (nullable) is None
|
91
|
+
# and model_fields_set contains the field
|
92
|
+
if self.image is None and "image" in self.model_fields_set:
|
93
|
+
_dict["image"] = None
|
94
|
+
|
95
|
+
return _dict
|
96
|
+
|
97
|
+
@classmethod
|
98
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
99
|
+
"""Create an instance of TokenDetail from a dict"""
|
100
|
+
if obj is None:
|
101
|
+
return None
|
102
|
+
|
103
|
+
if not isinstance(obj, dict):
|
104
|
+
return cls.model_validate(obj)
|
105
|
+
|
106
|
+
_obj = cls.model_validate(
|
107
|
+
{
|
108
|
+
"name": obj.get("name"),
|
109
|
+
"symbol": obj.get("symbol"),
|
110
|
+
"mint": obj.get("mint"),
|
111
|
+
"description": obj.get("description"),
|
112
|
+
"image": obj.get("image"),
|
113
|
+
"strictSocials": obj.get("strictSocials"),
|
114
|
+
}
|
115
|
+
)
|
116
|
+
return _obj
|
File without changes
|
@@ -0,0 +1,217 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
"""
|
4
|
+
DEX AI API
|
5
|
+
|
6
|
+
API for DEX AI
|
7
|
+
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
10
|
+
|
11
|
+
Do not edit the class manually.
|
12
|
+
""" # noqa: E501
|
13
|
+
|
14
|
+
|
15
|
+
import io
|
16
|
+
import json
|
17
|
+
import re
|
18
|
+
import ssl
|
19
|
+
from typing import Optional, Union
|
20
|
+
|
21
|
+
import aiohttp
|
22
|
+
import aiohttp_retry
|
23
|
+
|
24
|
+
from crypticorn.dex.client.exceptions import ApiException, ApiValueError
|
25
|
+
|
26
|
+
RESTResponseType = aiohttp.ClientResponse
|
27
|
+
|
28
|
+
ALLOW_RETRY_METHODS = frozenset({"DELETE", "GET", "HEAD", "OPTIONS", "PUT", "TRACE"})
|
29
|
+
|
30
|
+
|
31
|
+
class RESTResponse(io.IOBase):
|
32
|
+
|
33
|
+
def __init__(self, resp) -> None:
|
34
|
+
self.response = resp
|
35
|
+
self.status = resp.status
|
36
|
+
self.reason = resp.reason
|
37
|
+
self.data = None
|
38
|
+
|
39
|
+
async def read(self):
|
40
|
+
if self.data is None:
|
41
|
+
self.data = await self.response.read()
|
42
|
+
return self.data
|
43
|
+
|
44
|
+
def getheaders(self):
|
45
|
+
"""Returns a CIMultiDictProxy of the response headers."""
|
46
|
+
return self.response.headers
|
47
|
+
|
48
|
+
def getheader(self, name, default=None):
|
49
|
+
"""Returns a given response header."""
|
50
|
+
return self.response.headers.get(name, default)
|
51
|
+
|
52
|
+
|
53
|
+
class RESTClientObject:
|
54
|
+
|
55
|
+
def __init__(self, configuration) -> None:
|
56
|
+
|
57
|
+
# maxsize is number of requests to host that are allowed in parallel
|
58
|
+
self.maxsize = configuration.connection_pool_maxsize
|
59
|
+
|
60
|
+
self.ssl_context = ssl.create_default_context(
|
61
|
+
cafile=configuration.ssl_ca_cert,
|
62
|
+
cadata=configuration.ca_cert_data,
|
63
|
+
)
|
64
|
+
if configuration.cert_file:
|
65
|
+
self.ssl_context.load_cert_chain(
|
66
|
+
configuration.cert_file, keyfile=configuration.key_file
|
67
|
+
)
|
68
|
+
|
69
|
+
if not configuration.verify_ssl:
|
70
|
+
self.ssl_context.check_hostname = False
|
71
|
+
self.ssl_context.verify_mode = ssl.CERT_NONE
|
72
|
+
|
73
|
+
self.proxy = configuration.proxy
|
74
|
+
self.proxy_headers = configuration.proxy_headers
|
75
|
+
|
76
|
+
self.retries = configuration.retries
|
77
|
+
|
78
|
+
self.pool_manager: Optional[aiohttp.ClientSession] = None
|
79
|
+
self.retry_client: Optional[aiohttp_retry.RetryClient] = None
|
80
|
+
self.is_sync: bool = False # Track whether this is sync or async mode
|
81
|
+
|
82
|
+
async def close(self) -> None:
|
83
|
+
if self.pool_manager:
|
84
|
+
await self.pool_manager.close()
|
85
|
+
if self.retry_client is not None:
|
86
|
+
await self.retry_client.close()
|
87
|
+
|
88
|
+
async def request(
|
89
|
+
self,
|
90
|
+
method,
|
91
|
+
url,
|
92
|
+
headers=None,
|
93
|
+
body=None,
|
94
|
+
post_params=None,
|
95
|
+
_request_timeout=None,
|
96
|
+
):
|
97
|
+
"""Execute request
|
98
|
+
|
99
|
+
:param method: http request method
|
100
|
+
:param url: http request url
|
101
|
+
:param headers: http request headers
|
102
|
+
:param body: request json body, for `application/json`
|
103
|
+
:param post_params: request post parameters,
|
104
|
+
`application/x-www-form-urlencoded`
|
105
|
+
and `multipart/form-data`
|
106
|
+
:param _request_timeout: timeout setting for this request. If one
|
107
|
+
number provided, it will be total request
|
108
|
+
timeout. It can also be a pair (tuple) of
|
109
|
+
(connection, read) timeouts.
|
110
|
+
"""
|
111
|
+
method = method.upper()
|
112
|
+
assert method in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"]
|
113
|
+
|
114
|
+
if post_params and body:
|
115
|
+
raise ApiValueError(
|
116
|
+
"body parameter cannot be used with post_params parameter."
|
117
|
+
)
|
118
|
+
|
119
|
+
post_params = post_params or {}
|
120
|
+
headers = headers or {}
|
121
|
+
# url already contains the URL query string
|
122
|
+
timeout = _request_timeout or 5 * 60
|
123
|
+
|
124
|
+
if "Content-Type" not in headers:
|
125
|
+
headers["Content-Type"] = "application/json"
|
126
|
+
|
127
|
+
args = {"method": method, "url": url, "timeout": timeout, "headers": headers}
|
128
|
+
|
129
|
+
if self.proxy:
|
130
|
+
args["proxy"] = self.proxy
|
131
|
+
if self.proxy_headers:
|
132
|
+
args["proxy_headers"] = self.proxy_headers
|
133
|
+
|
134
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
135
|
+
if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
|
136
|
+
if re.search("json", headers["Content-Type"], re.IGNORECASE):
|
137
|
+
if body is not None:
|
138
|
+
body = json.dumps(body)
|
139
|
+
args["data"] = body
|
140
|
+
elif headers["Content-Type"] == "application/x-www-form-urlencoded":
|
141
|
+
args["data"] = aiohttp.FormData(post_params)
|
142
|
+
elif headers["Content-Type"] == "multipart/form-data":
|
143
|
+
# must del headers['Content-Type'], or the correct
|
144
|
+
# Content-Type which generated by aiohttp
|
145
|
+
del headers["Content-Type"]
|
146
|
+
data = aiohttp.FormData()
|
147
|
+
for param in post_params:
|
148
|
+
k, v = param
|
149
|
+
if isinstance(v, tuple) and len(v) == 3:
|
150
|
+
data.add_field(k, value=v[1], filename=v[0], content_type=v[2])
|
151
|
+
else:
|
152
|
+
# Ensures that dict objects are serialized
|
153
|
+
if isinstance(v, dict):
|
154
|
+
v = json.dumps(v)
|
155
|
+
elif isinstance(v, int):
|
156
|
+
v = str(v)
|
157
|
+
data.add_field(k, v)
|
158
|
+
args["data"] = data
|
159
|
+
|
160
|
+
# Pass a `bytes` or `str` parameter directly in the body to support
|
161
|
+
# other content types than Json when `body` argument is provided
|
162
|
+
# in serialized form
|
163
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
164
|
+
args["data"] = body
|
165
|
+
else:
|
166
|
+
# Cannot generate the request from given parameters
|
167
|
+
msg = """Cannot prepare a request message for provided
|
168
|
+
arguments. Please check that your arguments match
|
169
|
+
declared content type."""
|
170
|
+
raise ApiException(status=0, reason=msg)
|
171
|
+
|
172
|
+
pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
|
173
|
+
|
174
|
+
# For sync operations, always use a fresh session
|
175
|
+
should_close_session = False
|
176
|
+
|
177
|
+
if self.pool_manager is None:
|
178
|
+
self.pool_manager = aiohttp.ClientSession(
|
179
|
+
connector=aiohttp.TCPConnector(
|
180
|
+
limit=self.maxsize, ssl=self.ssl_context
|
181
|
+
),
|
182
|
+
trust_env=True,
|
183
|
+
)
|
184
|
+
# Only close session automatically in sync mode
|
185
|
+
should_close_session = self.is_sync
|
186
|
+
|
187
|
+
pool_manager = self.pool_manager
|
188
|
+
|
189
|
+
if self.retries is not None and method in ALLOW_RETRY_METHODS:
|
190
|
+
if self.retry_client is None:
|
191
|
+
self.retry_client = aiohttp_retry.RetryClient(
|
192
|
+
client_session=self.pool_manager,
|
193
|
+
retry_options=aiohttp_retry.ExponentialRetry(
|
194
|
+
attempts=self.retries,
|
195
|
+
factor=2.0,
|
196
|
+
start_timeout=0.1,
|
197
|
+
max_timeout=120.0,
|
198
|
+
),
|
199
|
+
)
|
200
|
+
pool_manager = self.retry_client
|
201
|
+
|
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/dex/main.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Edit this file. You can look in the other modules for examples.
|