crypticorn 1.0.0__py3-none-any.whl → 1.0.1__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 (36) hide show
  1. crypticorn/models/__init__.py +31 -0
  2. crypticorn/models/action_model.py +205 -0
  3. crypticorn/models/api_error_identifier.py +81 -0
  4. crypticorn/models/api_key_model.py +138 -0
  5. crypticorn/models/bot_model.py +118 -0
  6. crypticorn/models/create_api_key_response.py +99 -0
  7. crypticorn/models/deleted.py +87 -0
  8. crypticorn/models/exchange.py +37 -0
  9. crypticorn/models/execution_ids.py +91 -0
  10. crypticorn/models/futures_balance.py +109 -0
  11. crypticorn/models/futures_balance_error.py +89 -0
  12. crypticorn/models/futures_trading_action.py +198 -0
  13. crypticorn/models/get_futures_balance200_response_inner.py +134 -0
  14. crypticorn/models/http_validation_error.py +95 -0
  15. crypticorn/models/id.py +87 -0
  16. crypticorn/models/margin_mode.py +37 -0
  17. crypticorn/models/market_type.py +37 -0
  18. crypticorn/models/modified.py +87 -0
  19. crypticorn/models/notification_model.py +111 -0
  20. crypticorn/models/notification_type.py +39 -0
  21. crypticorn/models/order_model.py +266 -0
  22. crypticorn/models/order_status.py +40 -0
  23. crypticorn/models/post_futures_action.py +93 -0
  24. crypticorn/models/strategy_exchange_info.py +90 -0
  25. crypticorn/models/strategy_model.py +115 -0
  26. crypticorn/models/tpsl.py +116 -0
  27. crypticorn/models/trading_action_type.py +39 -0
  28. crypticorn/models/update_notification.py +91 -0
  29. crypticorn/models/validation_error.py +99 -0
  30. crypticorn/models/validation_error_loc_inner.py +138 -0
  31. {crypticorn-1.0.0.dist-info → crypticorn-1.0.1.dist-info}/METADATA +9 -3
  32. crypticorn-1.0.1.dist-info/RECORD +38 -0
  33. {crypticorn-1.0.0.dist-info → crypticorn-1.0.1.dist-info}/WHEEL +1 -1
  34. crypticorn-1.0.0.dist-info/RECORD +0 -8
  35. {crypticorn-1.0.0.dist-info → crypticorn-1.0.1.dist-info}/LICENSE.md +0 -0
  36. {crypticorn-1.0.0.dist-info → crypticorn-1.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,266 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ FastAPI
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1.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, StrictFloat, StrictInt, StrictStr
21
+ from typing import Any, ClassVar, Dict, List, Optional, Union
22
+ from crypticorn.models.api_error_identifier import ApiErrorIdentifier
23
+ from crypticorn.models.exchange import Exchange
24
+ from crypticorn.models.margin_mode import MarginMode
25
+ from crypticorn.models.market_type import MarketType
26
+ from crypticorn.models.order_status import OrderStatus
27
+ from crypticorn.models.trading_action_type import TradingActionType
28
+ from typing import Optional, Set
29
+ from typing_extensions import Self
30
+
31
+ class OrderModel(BaseModel):
32
+ """
33
+ Response model for orders. All optional as the model is built step by step.
34
+ """ # noqa: E501
35
+ id: Optional[StrictStr] = None
36
+ trading_action_id: Optional[StrictStr] = None
37
+ execution_id: Optional[StrictStr] = None
38
+ exchange_order_id: Optional[StrictStr] = None
39
+ position_id: Optional[StrictStr] = None
40
+ api_key_id: Optional[StrictStr] = None
41
+ user_id: Optional[StrictStr] = None
42
+ bot_id: Optional[StrictStr] = None
43
+ client_order_id: Optional[StrictStr] = None
44
+ exchange: Optional[Exchange] = None
45
+ symbol: Optional[StrictStr] = None
46
+ common_symbol: Optional[StrictStr] = None
47
+ timestamp: Optional[StrictInt] = None
48
+ price: Optional[Union[StrictFloat, StrictInt]] = None
49
+ action_type: Optional[TradingActionType] = None
50
+ market_type: Optional[MarketType] = None
51
+ margin_mode: Optional[MarginMode] = None
52
+ status_code: Optional[ApiErrorIdentifier] = None
53
+ status: Optional[OrderStatus] = None
54
+ filled_perc: Optional[Union[StrictFloat, StrictInt]] = None
55
+ filled_qty: Optional[Union[StrictFloat, StrictInt]] = None
56
+ fee: Optional[Union[StrictFloat, StrictInt]] = None
57
+ leverage: Optional[Union[StrictFloat, StrictInt]] = None
58
+ order_details: Optional[Dict[str, Any]] = None
59
+ pnl: Optional[Union[StrictFloat, StrictInt]] = None
60
+ __properties: ClassVar[List[str]] = ["id", "trading_action_id", "execution_id", "exchange_order_id", "position_id", "api_key_id", "user_id", "bot_id", "client_order_id", "exchange", "symbol", "common_symbol", "timestamp", "price", "action_type", "market_type", "margin_mode", "status_code", "status", "filled_perc", "filled_qty", "fee", "leverage", "order_details", "pnl"]
61
+
62
+ model_config = ConfigDict(
63
+ populate_by_name=True,
64
+ validate_assignment=True,
65
+ protected_namespaces=(),
66
+ )
67
+
68
+
69
+ def to_str(self) -> str:
70
+ """Returns the string representation of the model using alias"""
71
+ return pprint.pformat(self.model_dump(by_alias=True))
72
+
73
+ def to_json(self) -> str:
74
+ """Returns the JSON representation of the model using alias"""
75
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
76
+ return json.dumps(self.to_dict())
77
+
78
+ @classmethod
79
+ def from_json(cls, json_str: str) -> Optional[Self]:
80
+ """Create an instance of OrderModel from a JSON string"""
81
+ return cls.from_dict(json.loads(json_str))
82
+
83
+ def to_dict(self) -> Dict[str, Any]:
84
+ """Return the dictionary representation of the model using alias.
85
+
86
+ This has the following differences from calling pydantic's
87
+ `self.model_dump(by_alias=True)`:
88
+
89
+ * `None` is only added to the output dict for nullable fields that
90
+ were set at model initialization. Other fields with value `None`
91
+ are ignored.
92
+ """
93
+ excluded_fields: Set[str] = set([
94
+ ])
95
+
96
+ _dict = self.model_dump(
97
+ by_alias=True,
98
+ exclude=excluded_fields,
99
+ exclude_none=True,
100
+ )
101
+ # set to None if id (nullable) is None
102
+ # and model_fields_set contains the field
103
+ if self.id is None and "id" in self.model_fields_set:
104
+ _dict['id'] = None
105
+
106
+ # set to None if trading_action_id (nullable) is None
107
+ # and model_fields_set contains the field
108
+ if self.trading_action_id is None and "trading_action_id" in self.model_fields_set:
109
+ _dict['trading_action_id'] = None
110
+
111
+ # set to None if execution_id (nullable) is None
112
+ # and model_fields_set contains the field
113
+ if self.execution_id is None and "execution_id" in self.model_fields_set:
114
+ _dict['execution_id'] = None
115
+
116
+ # set to None if exchange_order_id (nullable) is None
117
+ # and model_fields_set contains the field
118
+ if self.exchange_order_id is None and "exchange_order_id" in self.model_fields_set:
119
+ _dict['exchange_order_id'] = None
120
+
121
+ # set to None if position_id (nullable) is None
122
+ # and model_fields_set contains the field
123
+ if self.position_id is None and "position_id" in self.model_fields_set:
124
+ _dict['position_id'] = None
125
+
126
+ # set to None if api_key_id (nullable) is None
127
+ # and model_fields_set contains the field
128
+ if self.api_key_id is None and "api_key_id" in self.model_fields_set:
129
+ _dict['api_key_id'] = None
130
+
131
+ # set to None if user_id (nullable) is None
132
+ # and model_fields_set contains the field
133
+ if self.user_id is None and "user_id" in self.model_fields_set:
134
+ _dict['user_id'] = None
135
+
136
+ # set to None if bot_id (nullable) is None
137
+ # and model_fields_set contains the field
138
+ if self.bot_id is None and "bot_id" in self.model_fields_set:
139
+ _dict['bot_id'] = None
140
+
141
+ # set to None if client_order_id (nullable) is None
142
+ # and model_fields_set contains the field
143
+ if self.client_order_id is None and "client_order_id" in self.model_fields_set:
144
+ _dict['client_order_id'] = None
145
+
146
+ # set to None if exchange (nullable) is None
147
+ # and model_fields_set contains the field
148
+ if self.exchange is None and "exchange" in self.model_fields_set:
149
+ _dict['exchange'] = None
150
+
151
+ # set to None if symbol (nullable) is None
152
+ # and model_fields_set contains the field
153
+ if self.symbol is None and "symbol" in self.model_fields_set:
154
+ _dict['symbol'] = None
155
+
156
+ # set to None if common_symbol (nullable) is None
157
+ # and model_fields_set contains the field
158
+ if self.common_symbol is None and "common_symbol" in self.model_fields_set:
159
+ _dict['common_symbol'] = None
160
+
161
+ # set to None if timestamp (nullable) is None
162
+ # and model_fields_set contains the field
163
+ if self.timestamp is None and "timestamp" in self.model_fields_set:
164
+ _dict['timestamp'] = None
165
+
166
+ # set to None if price (nullable) is None
167
+ # and model_fields_set contains the field
168
+ if self.price is None and "price" in self.model_fields_set:
169
+ _dict['price'] = None
170
+
171
+ # set to None if action_type (nullable) is None
172
+ # and model_fields_set contains the field
173
+ if self.action_type is None and "action_type" in self.model_fields_set:
174
+ _dict['action_type'] = None
175
+
176
+ # set to None if market_type (nullable) is None
177
+ # and model_fields_set contains the field
178
+ if self.market_type is None and "market_type" in self.model_fields_set:
179
+ _dict['market_type'] = None
180
+
181
+ # set to None if margin_mode (nullable) is None
182
+ # and model_fields_set contains the field
183
+ if self.margin_mode is None and "margin_mode" in self.model_fields_set:
184
+ _dict['margin_mode'] = None
185
+
186
+ # set to None if status_code (nullable) is None
187
+ # and model_fields_set contains the field
188
+ if self.status_code is None and "status_code" in self.model_fields_set:
189
+ _dict['status_code'] = None
190
+
191
+ # set to None if status (nullable) is None
192
+ # and model_fields_set contains the field
193
+ if self.status is None and "status" in self.model_fields_set:
194
+ _dict['status'] = None
195
+
196
+ # set to None if filled_perc (nullable) is None
197
+ # and model_fields_set contains the field
198
+ if self.filled_perc is None and "filled_perc" in self.model_fields_set:
199
+ _dict['filled_perc'] = None
200
+
201
+ # set to None if filled_qty (nullable) is None
202
+ # and model_fields_set contains the field
203
+ if self.filled_qty is None and "filled_qty" in self.model_fields_set:
204
+ _dict['filled_qty'] = None
205
+
206
+ # set to None if fee (nullable) is None
207
+ # and model_fields_set contains the field
208
+ if self.fee is None and "fee" in self.model_fields_set:
209
+ _dict['fee'] = None
210
+
211
+ # set to None if leverage (nullable) is None
212
+ # and model_fields_set contains the field
213
+ if self.leverage is None and "leverage" in self.model_fields_set:
214
+ _dict['leverage'] = None
215
+
216
+ # set to None if order_details (nullable) is None
217
+ # and model_fields_set contains the field
218
+ if self.order_details is None and "order_details" in self.model_fields_set:
219
+ _dict['order_details'] = None
220
+
221
+ # set to None if pnl (nullable) is None
222
+ # and model_fields_set contains the field
223
+ if self.pnl is None and "pnl" in self.model_fields_set:
224
+ _dict['pnl'] = None
225
+
226
+ return _dict
227
+
228
+ @classmethod
229
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
230
+ """Create an instance of OrderModel from a dict"""
231
+ if obj is None:
232
+ return None
233
+
234
+ if not isinstance(obj, dict):
235
+ return cls.model_validate(obj)
236
+
237
+ _obj = cls.model_validate({
238
+ "id": obj.get("id"),
239
+ "trading_action_id": obj.get("trading_action_id"),
240
+ "execution_id": obj.get("execution_id"),
241
+ "exchange_order_id": obj.get("exchange_order_id"),
242
+ "position_id": obj.get("position_id"),
243
+ "api_key_id": obj.get("api_key_id"),
244
+ "user_id": obj.get("user_id"),
245
+ "bot_id": obj.get("bot_id"),
246
+ "client_order_id": obj.get("client_order_id"),
247
+ "exchange": obj.get("exchange"),
248
+ "symbol": obj.get("symbol"),
249
+ "common_symbol": obj.get("common_symbol"),
250
+ "timestamp": obj.get("timestamp"),
251
+ "price": obj.get("price"),
252
+ "action_type": obj.get("action_type"),
253
+ "market_type": obj.get("market_type"),
254
+ "margin_mode": obj.get("margin_mode"),
255
+ "status_code": obj.get("status_code"),
256
+ "status": obj.get("status"),
257
+ "filled_perc": obj.get("filled_perc"),
258
+ "filled_qty": obj.get("filled_qty"),
259
+ "fee": obj.get("fee"),
260
+ "leverage": obj.get("leverage"),
261
+ "order_details": obj.get("order_details"),
262
+ "pnl": obj.get("pnl")
263
+ })
264
+ return _obj
265
+
266
+
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ FastAPI
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1.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 json
17
+ from enum import Enum
18
+ from typing_extensions import Self
19
+
20
+
21
+ class OrderStatus(str, Enum):
22
+ """
23
+ Status of the order
24
+ """
25
+
26
+ """
27
+ allowed enum values
28
+ """
29
+ NEW = 'new'
30
+ FILLED = 'filled'
31
+ PARTIALLY_FILLED = 'partially_filled'
32
+ CANCELLED = 'cancelled'
33
+ FAILED = 'failed'
34
+
35
+ @classmethod
36
+ def from_json(cls, json_str: str) -> Self:
37
+ """Create an instance of OrderStatus from a JSON string"""
38
+ return cls(json.loads(json_str))
39
+
40
+
@@ -0,0 +1,93 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ FastAPI
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1.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
22
+ from crypticorn.models.execution_ids import ExecutionIds
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+ class PostFuturesAction(BaseModel):
27
+ """
28
+ PostFuturesAction
29
+ """ # noqa: E501
30
+ id: StrictStr = Field(description="Action ID.")
31
+ execution_ids: ExecutionIds = Field(description="Execution IDs for the action.")
32
+ __properties: ClassVar[List[str]] = ["id", "execution_ids"]
33
+
34
+ model_config = ConfigDict(
35
+ populate_by_name=True,
36
+ validate_assignment=True,
37
+ protected_namespaces=(),
38
+ )
39
+
40
+
41
+ def to_str(self) -> str:
42
+ """Returns the string representation of the model using alias"""
43
+ return pprint.pformat(self.model_dump(by_alias=True))
44
+
45
+ def to_json(self) -> str:
46
+ """Returns the JSON representation of the model using alias"""
47
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48
+ return json.dumps(self.to_dict())
49
+
50
+ @classmethod
51
+ def from_json(cls, json_str: str) -> Optional[Self]:
52
+ """Create an instance of PostFuturesAction from a JSON string"""
53
+ return cls.from_dict(json.loads(json_str))
54
+
55
+ def to_dict(self) -> Dict[str, Any]:
56
+ """Return the dictionary representation of the model using alias.
57
+
58
+ This has the following differences from calling pydantic's
59
+ `self.model_dump(by_alias=True)`:
60
+
61
+ * `None` is only added to the output dict for nullable fields that
62
+ were set at model initialization. Other fields with value `None`
63
+ are ignored.
64
+ """
65
+ excluded_fields: Set[str] = set([
66
+ ])
67
+
68
+ _dict = self.model_dump(
69
+ by_alias=True,
70
+ exclude=excluded_fields,
71
+ exclude_none=True,
72
+ )
73
+ # override the default output from pydantic by calling `to_dict()` of execution_ids
74
+ if self.execution_ids:
75
+ _dict['execution_ids'] = self.execution_ids.to_dict()
76
+ return _dict
77
+
78
+ @classmethod
79
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
80
+ """Create an instance of PostFuturesAction from a dict"""
81
+ if obj is None:
82
+ return None
83
+
84
+ if not isinstance(obj, dict):
85
+ return cls.model_validate(obj)
86
+
87
+ _obj = cls.model_validate({
88
+ "id": obj.get("id"),
89
+ "execution_ids": ExecutionIds.from_dict(obj["execution_ids"]) if obj.get("execution_ids") is not None else None
90
+ })
91
+ return _obj
92
+
93
+
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ FastAPI
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1.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, StrictFloat, StrictInt
21
+ from typing import Any, ClassVar, Dict, List, Union
22
+ from crypticorn.models.exchange import Exchange
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+ class StrategyExchangeInfo(BaseModel):
27
+ """
28
+ StrategyExchangeInfo
29
+ """ # noqa: E501
30
+ exchange: Exchange = Field(description="Exchange name. Of type Exchange")
31
+ min_amount: Union[StrictFloat, StrictInt] = Field(description="Minimum amount for the strategy on the exchange")
32
+ __properties: ClassVar[List[str]] = ["exchange", "min_amount"]
33
+
34
+ model_config = ConfigDict(
35
+ populate_by_name=True,
36
+ validate_assignment=True,
37
+ protected_namespaces=(),
38
+ )
39
+
40
+
41
+ def to_str(self) -> str:
42
+ """Returns the string representation of the model using alias"""
43
+ return pprint.pformat(self.model_dump(by_alias=True))
44
+
45
+ def to_json(self) -> str:
46
+ """Returns the JSON representation of the model using alias"""
47
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48
+ return json.dumps(self.to_dict())
49
+
50
+ @classmethod
51
+ def from_json(cls, json_str: str) -> Optional[Self]:
52
+ """Create an instance of StrategyExchangeInfo from a JSON string"""
53
+ return cls.from_dict(json.loads(json_str))
54
+
55
+ def to_dict(self) -> Dict[str, Any]:
56
+ """Return the dictionary representation of the model using alias.
57
+
58
+ This has the following differences from calling pydantic's
59
+ `self.model_dump(by_alias=True)`:
60
+
61
+ * `None` is only added to the output dict for nullable fields that
62
+ were set at model initialization. Other fields with value `None`
63
+ are ignored.
64
+ """
65
+ excluded_fields: Set[str] = set([
66
+ ])
67
+
68
+ _dict = self.model_dump(
69
+ by_alias=True,
70
+ exclude=excluded_fields,
71
+ exclude_none=True,
72
+ )
73
+ return _dict
74
+
75
+ @classmethod
76
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
77
+ """Create an instance of StrategyExchangeInfo from a dict"""
78
+ if obj is None:
79
+ return None
80
+
81
+ if not isinstance(obj, dict):
82
+ return cls.model_validate(obj)
83
+
84
+ _obj = cls.model_validate({
85
+ "exchange": obj.get("exchange"),
86
+ "min_amount": obj.get("min_amount")
87
+ })
88
+ return _obj
89
+
90
+
@@ -0,0 +1,115 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ FastAPI
5
+
6
+ No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
+
8
+ The version of the OpenAPI document: 0.1.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, StrictBool, StrictInt, StrictStr
21
+ from typing import Any, ClassVar, Dict, List, Optional, Union
22
+ from typing_extensions import Annotated
23
+ from crypticorn.models.strategy_exchange_info import StrategyExchangeInfo
24
+ from typing import Optional, Set
25
+ from typing_extensions import Self
26
+
27
+ class StrategyModel(BaseModel):
28
+ """
29
+ StrategyModel
30
+ """ # noqa: E501
31
+ id: Optional[StrictStr] = None
32
+ identifier: StrictStr = Field(description="Unique human readable identifier for the strategy e.g. 'daily_trend_momentum'")
33
+ name: StrictStr = Field(description="Name of the strategy")
34
+ description: StrictStr = Field(description="Description of the strategy")
35
+ exchanges: List[StrategyExchangeInfo] = Field(description="Exchanges supported by the strategy.")
36
+ enabled: StrictBool = Field(description="Whether the strategy is enabled")
37
+ leverage: StrictInt = Field(description="Leverage for the strategy")
38
+ performance_fee: Union[Annotated[float, Field(le=1.0, strict=True)], Annotated[int, Field(le=1, strict=True)]] = Field(description="Performance fee for the strategy")
39
+ __properties: ClassVar[List[str]] = ["id", "identifier", "name", "description", "exchanges", "enabled", "leverage", "performance_fee"]
40
+
41
+ model_config = ConfigDict(
42
+ populate_by_name=True,
43
+ validate_assignment=True,
44
+ protected_namespaces=(),
45
+ )
46
+
47
+
48
+ def to_str(self) -> str:
49
+ """Returns the string representation of the model using alias"""
50
+ return pprint.pformat(self.model_dump(by_alias=True))
51
+
52
+ def to_json(self) -> str:
53
+ """Returns the JSON representation of the model using alias"""
54
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
55
+ return json.dumps(self.to_dict())
56
+
57
+ @classmethod
58
+ def from_json(cls, json_str: str) -> Optional[Self]:
59
+ """Create an instance of StrategyModel from a JSON string"""
60
+ return cls.from_dict(json.loads(json_str))
61
+
62
+ def to_dict(self) -> Dict[str, Any]:
63
+ """Return the dictionary representation of the model using alias.
64
+
65
+ This has the following differences from calling pydantic's
66
+ `self.model_dump(by_alias=True)`:
67
+
68
+ * `None` is only added to the output dict for nullable fields that
69
+ were set at model initialization. Other fields with value `None`
70
+ are ignored.
71
+ """
72
+ excluded_fields: Set[str] = set([
73
+ ])
74
+
75
+ _dict = self.model_dump(
76
+ by_alias=True,
77
+ exclude=excluded_fields,
78
+ exclude_none=True,
79
+ )
80
+ # override the default output from pydantic by calling `to_dict()` of each item in exchanges (list)
81
+ _items = []
82
+ if self.exchanges:
83
+ for _item_exchanges in self.exchanges:
84
+ if _item_exchanges:
85
+ _items.append(_item_exchanges.to_dict())
86
+ _dict['exchanges'] = _items
87
+ # set to None if id (nullable) is None
88
+ # and model_fields_set contains the field
89
+ if self.id is None and "id" in self.model_fields_set:
90
+ _dict['id'] = None
91
+
92
+ return _dict
93
+
94
+ @classmethod
95
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
96
+ """Create an instance of StrategyModel from a dict"""
97
+ if obj is None:
98
+ return None
99
+
100
+ if not isinstance(obj, dict):
101
+ return cls.model_validate(obj)
102
+
103
+ _obj = cls.model_validate({
104
+ "id": obj.get("id"),
105
+ "identifier": obj.get("identifier"),
106
+ "name": obj.get("name"),
107
+ "description": obj.get("description"),
108
+ "exchanges": [StrategyExchangeInfo.from_dict(_item) for _item in obj["exchanges"]] if obj.get("exchanges") is not None else None,
109
+ "enabled": obj.get("enabled"),
110
+ "leverage": obj.get("leverage"),
111
+ "performance_fee": obj.get("performance_fee")
112
+ })
113
+ return _obj
114
+
115
+