crypticorn 2.17.0rc5__py3-none-any.whl → 2.17.0rc7__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 (62) hide show
  1. crypticorn/auth/client/api/admin_api.py +6 -24
  2. crypticorn/auth/client/api/auth_api.py +36 -144
  3. crypticorn/auth/client/api/service_api.py +3 -12
  4. crypticorn/auth/client/api/user_api.py +33 -132
  5. crypticorn/auth/client/api/wallet_api.py +18 -72
  6. crypticorn/cli/templates/Dockerfile +5 -2
  7. crypticorn/common/auth.py +30 -0
  8. crypticorn/common/errors.py +10 -0
  9. crypticorn/common/pagination.py +1 -1
  10. crypticorn/common/router/admin_router.py +1 -11
  11. crypticorn/common/router/status_router.py +30 -2
  12. crypticorn/common/scopes.py +2 -2
  13. crypticorn/dex/client/api/admin_api.py +21 -84
  14. crypticorn/dex/client/api/signals_api.py +9 -36
  15. crypticorn/dex/client/api/status_api.py +6 -24
  16. crypticorn/hive/client/api/admin_api.py +18 -72
  17. crypticorn/hive/client/api/data_api.py +6 -24
  18. crypticorn/hive/client/api/models_api.py +21 -84
  19. crypticorn/hive/client/api/status_api.py +6 -24
  20. crypticorn/klines/client/api/admin_api.py +18 -72
  21. crypticorn/klines/client/api/change_in_timeframe_api.py +3 -12
  22. crypticorn/klines/client/api/funding_rates_api.py +3 -12
  23. crypticorn/klines/client/api/ohlcv_data_api.py +3 -12
  24. crypticorn/klines/client/api/status_api.py +6 -24
  25. crypticorn/klines/client/api/symbols_api.py +3 -12
  26. crypticorn/klines/client/api/udf_api.py +18 -72
  27. crypticorn/metrics/client/api/admin_api.py +18 -72
  28. crypticorn/metrics/client/api/exchanges_api.py +12 -48
  29. crypticorn/metrics/client/api/indicators_api.py +6 -24
  30. crypticorn/metrics/client/api/logs_api.py +3 -12
  31. crypticorn/metrics/client/api/marketcap_api.py +12 -48
  32. crypticorn/metrics/client/api/markets_api.py +3 -12
  33. crypticorn/metrics/client/api/quote_currencies_api.py +3 -12
  34. crypticorn/metrics/client/api/status_api.py +6 -24
  35. crypticorn/metrics/client/api/tokens_api.py +6 -24
  36. crypticorn/pay/client/api/admin_api.py +21 -84
  37. crypticorn/pay/client/api/now_payments_api.py +15 -60
  38. crypticorn/pay/client/api/payments_api.py +6 -24
  39. crypticorn/pay/client/api/products_api.py +12 -48
  40. crypticorn/pay/client/api/status_api.py +6 -24
  41. crypticorn/trade/client/__init__.py +10 -0
  42. crypticorn/trade/client/api/admin_api.py +21 -84
  43. crypticorn/trade/client/api/api_keys_api.py +207 -184
  44. crypticorn/trade/client/api/bots_api.py +2435 -662
  45. crypticorn/trade/client/api/exchanges_api.py +9 -36
  46. crypticorn/trade/client/api/notifications_api.py +18 -72
  47. crypticorn/trade/client/api/orders_api.py +3 -12
  48. crypticorn/trade/client/api/status_api.py +6 -24
  49. crypticorn/trade/client/api/strategies_api.py +15 -60
  50. crypticorn/trade/client/api/trading_actions_api.py +431 -112
  51. crypticorn/trade/client/configuration.py +2 -2
  52. crypticorn/trade/client/models/__init__.py +10 -0
  53. crypticorn/trade/client/models/paginated_response_futures_trading_action.py +134 -0
  54. crypticorn/trade/client/models/paginated_response_union_futures_trading_action_spot_trading_action.py +141 -0
  55. crypticorn/trade/client/models/paginated_response_union_futures_trading_action_spot_trading_action_data_inner.py +165 -0
  56. crypticorn/trade/client/models/spot_trading_action.py +207 -0
  57. {crypticorn-2.17.0rc5.dist-info → crypticorn-2.17.0rc7.dist-info}/METADATA +3 -3
  58. {crypticorn-2.17.0rc5.dist-info → crypticorn-2.17.0rc7.dist-info}/RECORD +62 -58
  59. {crypticorn-2.17.0rc5.dist-info → crypticorn-2.17.0rc7.dist-info}/WHEEL +0 -0
  60. {crypticorn-2.17.0rc5.dist-info → crypticorn-2.17.0rc7.dist-info}/entry_points.txt +0 -0
  61. {crypticorn-2.17.0rc5.dist-info → crypticorn-2.17.0rc7.dist-info}/licenses/LICENSE +0 -0
  62. {crypticorn-2.17.0rc5.dist-info → crypticorn-2.17.0rc7.dist-info}/top_level.txt +0 -0
@@ -215,7 +215,7 @@ class Configuration:
215
215
  debug: Optional[bool] = None,
216
216
  ) -> None:
217
217
  """Constructor"""
218
- self._base_path = "http://localhost:8000/v1/trade" if host is None else host
218
+ self._base_path = "http://localhost/v1/trade" if host is None else host
219
219
  """Default Base url
220
220
  """
221
221
  self.server_index = 0 if server_index is None and host is None else server_index
@@ -557,7 +557,7 @@ class Configuration:
557
557
  """
558
558
  return [
559
559
  {
560
- "url": "http://localhost:8000/v1/trade",
560
+ "url": "http://localhost/v1/trade",
561
561
  "description": "No description provided",
562
562
  }
563
563
  ]
@@ -42,12 +42,22 @@ from crypticorn.trade.client.models.notification_update import NotificationUpdat
42
42
  from crypticorn.trade.client.models.order import Order
43
43
  from crypticorn.trade.client.models.order_status import OrderStatus
44
44
  from crypticorn.trade.client.models.orders_count import OrdersCount
45
+ from crypticorn.trade.client.models.paginated_response_futures_trading_action import (
46
+ PaginatedResponseFuturesTradingAction,
47
+ )
45
48
  from crypticorn.trade.client.models.paginated_response_order import (
46
49
  PaginatedResponseOrder,
47
50
  )
51
+ from crypticorn.trade.client.models.paginated_response_union_futures_trading_action_spot_trading_action import (
52
+ PaginatedResponseUnionFuturesTradingActionSpotTradingAction,
53
+ )
54
+ from crypticorn.trade.client.models.paginated_response_union_futures_trading_action_spot_trading_action_data_inner import (
55
+ PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner,
56
+ )
48
57
  from crypticorn.trade.client.models.pn_l import PnL
49
58
  from crypticorn.trade.client.models.post_futures_action import PostFuturesAction
50
59
  from crypticorn.trade.client.models.spot_balance import SpotBalance
60
+ from crypticorn.trade.client.models.spot_trading_action import SpotTradingAction
51
61
  from crypticorn.trade.client.models.spot_trading_action_create import (
52
62
  SpotTradingActionCreate,
53
63
  )
@@ -0,0 +1,134 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Trading API
5
+
6
+ API for automated trading and exchange interface. This API is used to trade on the exchange and manage bots, API keys, orders, and more.
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
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from crypticorn.trade.client.models.futures_trading_action import FuturesTradingAction
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+
27
+ class PaginatedResponseFuturesTradingAction(BaseModel):
28
+ """
29
+ PaginatedResponseFuturesTradingAction
30
+ """ # noqa: E501
31
+
32
+ data: List[FuturesTradingAction]
33
+ total: StrictInt = Field(description="The total number of items")
34
+ page: StrictInt = Field(description="The current page number")
35
+ page_size: StrictInt = Field(description="The number of items per page")
36
+ prev: Optional[StrictInt] = None
37
+ next: Optional[StrictInt] = None
38
+ last: Optional[StrictInt] = None
39
+ __properties: ClassVar[List[str]] = [
40
+ "data",
41
+ "total",
42
+ "page",
43
+ "page_size",
44
+ "prev",
45
+ "next",
46
+ "last",
47
+ ]
48
+
49
+ model_config = ConfigDict(
50
+ populate_by_name=True,
51
+ validate_assignment=True,
52
+ protected_namespaces=(),
53
+ )
54
+
55
+ def to_str(self) -> str:
56
+ """Returns the string representation of the model using alias"""
57
+ return pprint.pformat(self.model_dump(by_alias=True))
58
+
59
+ def to_json(self) -> str:
60
+ """Returns the JSON representation of the model using alias"""
61
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
62
+ return json.dumps(self.to_dict())
63
+
64
+ @classmethod
65
+ def from_json(cls, json_str: str) -> Optional[Self]:
66
+ """Create an instance of PaginatedResponseFuturesTradingAction from a JSON string"""
67
+ return cls.from_dict(json.loads(json_str))
68
+
69
+ def to_dict(self) -> Dict[str, Any]:
70
+ """Return the dictionary representation of the model using alias.
71
+
72
+ This has the following differences from calling pydantic's
73
+ `self.model_dump(by_alias=True)`:
74
+
75
+ * `None` is only added to the output dict for nullable fields that
76
+ were set at model initialization. Other fields with value `None`
77
+ are ignored.
78
+ """
79
+ excluded_fields: Set[str] = set([])
80
+
81
+ _dict = self.model_dump(
82
+ by_alias=True,
83
+ exclude=excluded_fields,
84
+ exclude_none=True,
85
+ )
86
+ # override the default output from pydantic by calling `to_dict()` of each item in data (list)
87
+ _items = []
88
+ if self.data:
89
+ for _item_data in self.data:
90
+ if _item_data:
91
+ _items.append(_item_data.to_dict())
92
+ _dict["data"] = _items
93
+ # set to None if prev (nullable) is None
94
+ # and model_fields_set contains the field
95
+ if self.prev is None and "prev" in self.model_fields_set:
96
+ _dict["prev"] = None
97
+
98
+ # set to None if next (nullable) is None
99
+ # and model_fields_set contains the field
100
+ if self.next is None and "next" in self.model_fields_set:
101
+ _dict["next"] = None
102
+
103
+ # set to None if last (nullable) is None
104
+ # and model_fields_set contains the field
105
+ if self.last is None and "last" in self.model_fields_set:
106
+ _dict["last"] = None
107
+
108
+ return _dict
109
+
110
+ @classmethod
111
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
112
+ """Create an instance of PaginatedResponseFuturesTradingAction from a dict"""
113
+ if obj is None:
114
+ return None
115
+
116
+ if not isinstance(obj, dict):
117
+ return cls.model_validate(obj)
118
+
119
+ _obj = cls.model_validate(
120
+ {
121
+ "data": (
122
+ [FuturesTradingAction.from_dict(_item) for _item in obj["data"]]
123
+ if obj.get("data") is not None
124
+ else None
125
+ ),
126
+ "total": obj.get("total"),
127
+ "page": obj.get("page"),
128
+ "page_size": obj.get("page_size"),
129
+ "prev": obj.get("prev"),
130
+ "next": obj.get("next"),
131
+ "last": obj.get("last"),
132
+ }
133
+ )
134
+ return _obj
@@ -0,0 +1,141 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Trading API
5
+
6
+ API for automated trading and exchange interface. This API is used to trade on the exchange and manage bots, API keys, orders, and more.
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
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from crypticorn.trade.client.models.paginated_response_union_futures_trading_action_spot_trading_action_data_inner import (
23
+ PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner,
24
+ )
25
+ from typing import Optional, Set
26
+ from typing_extensions import Self
27
+
28
+
29
+ class PaginatedResponseUnionFuturesTradingActionSpotTradingAction(BaseModel):
30
+ """
31
+ PaginatedResponseUnionFuturesTradingActionSpotTradingAction
32
+ """ # noqa: E501
33
+
34
+ data: List[PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner]
35
+ total: StrictInt = Field(description="The total number of items")
36
+ page: StrictInt = Field(description="The current page number")
37
+ page_size: StrictInt = Field(description="The number of items per page")
38
+ prev: Optional[StrictInt] = None
39
+ next: Optional[StrictInt] = None
40
+ last: Optional[StrictInt] = None
41
+ __properties: ClassVar[List[str]] = [
42
+ "data",
43
+ "total",
44
+ "page",
45
+ "page_size",
46
+ "prev",
47
+ "next",
48
+ "last",
49
+ ]
50
+
51
+ model_config = ConfigDict(
52
+ populate_by_name=True,
53
+ validate_assignment=True,
54
+ protected_namespaces=(),
55
+ )
56
+
57
+ def to_str(self) -> str:
58
+ """Returns the string representation of the model using alias"""
59
+ return pprint.pformat(self.model_dump(by_alias=True))
60
+
61
+ def to_json(self) -> str:
62
+ """Returns the JSON representation of the model using alias"""
63
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64
+ return json.dumps(self.to_dict())
65
+
66
+ @classmethod
67
+ def from_json(cls, json_str: str) -> Optional[Self]:
68
+ """Create an instance of PaginatedResponseUnionFuturesTradingActionSpotTradingAction from a JSON string"""
69
+ return cls.from_dict(json.loads(json_str))
70
+
71
+ def to_dict(self) -> Dict[str, Any]:
72
+ """Return the dictionary representation of the model using alias.
73
+
74
+ This has the following differences from calling pydantic's
75
+ `self.model_dump(by_alias=True)`:
76
+
77
+ * `None` is only added to the output dict for nullable fields that
78
+ were set at model initialization. Other fields with value `None`
79
+ are ignored.
80
+ """
81
+ excluded_fields: Set[str] = set([])
82
+
83
+ _dict = self.model_dump(
84
+ by_alias=True,
85
+ exclude=excluded_fields,
86
+ exclude_none=True,
87
+ )
88
+ # override the default output from pydantic by calling `to_dict()` of each item in data (list)
89
+ _items = []
90
+ if self.data:
91
+ for _item_data in self.data:
92
+ if _item_data:
93
+ _items.append(_item_data.to_dict())
94
+ _dict["data"] = _items
95
+ # set to None if prev (nullable) is None
96
+ # and model_fields_set contains the field
97
+ if self.prev is None and "prev" in self.model_fields_set:
98
+ _dict["prev"] = None
99
+
100
+ # set to None if next (nullable) is None
101
+ # and model_fields_set contains the field
102
+ if self.next is None and "next" in self.model_fields_set:
103
+ _dict["next"] = None
104
+
105
+ # set to None if last (nullable) is None
106
+ # and model_fields_set contains the field
107
+ if self.last is None and "last" in self.model_fields_set:
108
+ _dict["last"] = None
109
+
110
+ return _dict
111
+
112
+ @classmethod
113
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
114
+ """Create an instance of PaginatedResponseUnionFuturesTradingActionSpotTradingAction from a dict"""
115
+ if obj is None:
116
+ return None
117
+
118
+ if not isinstance(obj, dict):
119
+ return cls.model_validate(obj)
120
+
121
+ _obj = cls.model_validate(
122
+ {
123
+ "data": (
124
+ [
125
+ PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner.from_dict(
126
+ _item
127
+ )
128
+ for _item in obj["data"]
129
+ ]
130
+ if obj.get("data") is not None
131
+ else None
132
+ ),
133
+ "total": obj.get("total"),
134
+ "page": obj.get("page"),
135
+ "page_size": obj.get("page_size"),
136
+ "prev": obj.get("prev"),
137
+ "next": obj.get("next"),
138
+ "last": obj.get("last"),
139
+ }
140
+ )
141
+ return _obj
@@ -0,0 +1,165 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Trading API
5
+
6
+ API for automated trading and exchange interface. This API is used to trade on the exchange and manage bots, API keys, orders, and more.
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
+ from inspect import getfullargspec
17
+ import json
18
+ import pprint
19
+ import re # noqa: F401
20
+ from pydantic import (
21
+ BaseModel,
22
+ ConfigDict,
23
+ Field,
24
+ StrictStr,
25
+ ValidationError,
26
+ field_validator,
27
+ )
28
+ from typing import Optional
29
+ from crypticorn.trade.client.models.futures_trading_action import FuturesTradingAction
30
+ from crypticorn.trade.client.models.spot_trading_action import SpotTradingAction
31
+ from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict
32
+ from typing_extensions import Literal, Self
33
+ from pydantic import Field
34
+
35
+ PAGINATEDRESPONSEUNIONFUTURESTRADINGACTIONSPOTTRADINGACTIONDATAINNER_ANY_OF_SCHEMAS = [
36
+ "FuturesTradingAction",
37
+ "SpotTradingAction",
38
+ ]
39
+
40
+
41
+ class PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner(BaseModel):
42
+ """
43
+ PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner
44
+ """
45
+
46
+ # data type: FuturesTradingAction
47
+ anyof_schema_1_validator: Optional[FuturesTradingAction] = None
48
+ # data type: SpotTradingAction
49
+ anyof_schema_2_validator: Optional[SpotTradingAction] = None
50
+ if TYPE_CHECKING:
51
+ actual_instance: Optional[Union[FuturesTradingAction, SpotTradingAction]] = None
52
+ else:
53
+ actual_instance: Any = None
54
+ any_of_schemas: Set[str] = {"FuturesTradingAction", "SpotTradingAction"}
55
+
56
+ model_config = {
57
+ "validate_assignment": True,
58
+ "protected_namespaces": (),
59
+ }
60
+
61
+ def __init__(self, *args, **kwargs) -> None:
62
+ if args:
63
+ if len(args) > 1:
64
+ raise ValueError(
65
+ "If a position argument is used, only 1 is allowed to set `actual_instance`"
66
+ )
67
+ if kwargs:
68
+ raise ValueError(
69
+ "If a position argument is used, keyword arguments cannot be used."
70
+ )
71
+ super().__init__(actual_instance=args[0])
72
+ else:
73
+ super().__init__(**kwargs)
74
+
75
+ @field_validator("actual_instance")
76
+ def actual_instance_must_validate_anyof(cls, v):
77
+ instance = (
78
+ PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner.model_construct()
79
+ )
80
+ error_messages = []
81
+ # validate data type: FuturesTradingAction
82
+ if not isinstance(v, FuturesTradingAction):
83
+ error_messages.append(
84
+ f"Error! Input type `{type(v)}` is not `FuturesTradingAction`"
85
+ )
86
+ else:
87
+ return v
88
+
89
+ # validate data type: SpotTradingAction
90
+ if not isinstance(v, SpotTradingAction):
91
+ error_messages.append(
92
+ f"Error! Input type `{type(v)}` is not `SpotTradingAction`"
93
+ )
94
+ else:
95
+ return v
96
+
97
+ if error_messages:
98
+ # no match
99
+ raise ValueError(
100
+ "No match found when setting the actual_instance in PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner with anyOf schemas: FuturesTradingAction, SpotTradingAction. Details: "
101
+ + ", ".join(error_messages)
102
+ )
103
+ else:
104
+ return v
105
+
106
+ @classmethod
107
+ def from_dict(cls, obj: Dict[str, Any]) -> Self:
108
+ return cls.from_json(json.dumps(obj))
109
+
110
+ @classmethod
111
+ def from_json(cls, json_str: str) -> Self:
112
+ """Returns the object represented by the json string"""
113
+ instance = cls.model_construct()
114
+ error_messages = []
115
+ # anyof_schema_1_validator: Optional[FuturesTradingAction] = None
116
+ try:
117
+ instance.actual_instance = FuturesTradingAction.from_json(json_str)
118
+ return instance
119
+ except (ValidationError, ValueError) as e:
120
+ error_messages.append(str(e))
121
+ # anyof_schema_2_validator: Optional[SpotTradingAction] = None
122
+ try:
123
+ instance.actual_instance = SpotTradingAction.from_json(json_str)
124
+ return instance
125
+ except (ValidationError, ValueError) as e:
126
+ error_messages.append(str(e))
127
+
128
+ if error_messages:
129
+ # no match
130
+ raise ValueError(
131
+ "No match found when deserializing the JSON string into PaginatedResponseUnionFuturesTradingActionSpotTradingActionDataInner with anyOf schemas: FuturesTradingAction, SpotTradingAction. Details: "
132
+ + ", ".join(error_messages)
133
+ )
134
+ else:
135
+ return instance
136
+
137
+ def to_json(self) -> str:
138
+ """Returns the JSON representation of the actual instance"""
139
+ if self.actual_instance is None:
140
+ return "null"
141
+
142
+ if hasattr(self.actual_instance, "to_json") and callable(
143
+ self.actual_instance.to_json
144
+ ):
145
+ return self.actual_instance.to_json()
146
+ else:
147
+ return json.dumps(self.actual_instance)
148
+
149
+ def to_dict(
150
+ self,
151
+ ) -> Optional[Union[Dict[str, Any], FuturesTradingAction, SpotTradingAction]]:
152
+ """Returns the dict representation of the actual instance"""
153
+ if self.actual_instance is None:
154
+ return None
155
+
156
+ if hasattr(self.actual_instance, "to_dict") and callable(
157
+ self.actual_instance.to_dict
158
+ ):
159
+ return self.actual_instance.to_dict()
160
+ else:
161
+ return self.actual_instance
162
+
163
+ def to_str(self) -> str:
164
+ """Returns the string representation of the actual instance"""
165
+ return pprint.pformat(self.model_dump())
@@ -0,0 +1,207 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Trading API
5
+
6
+ API for automated trading and exchange interface. This API is used to trade on the exchange and manage bots, API keys, orders, and more.
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, StrictBool, StrictInt, StrictStr
21
+ from typing import Any, ClassVar, Dict, List, Optional
22
+ from crypticorn.trade.client.models.market_type import MarketType
23
+ from crypticorn.trade.client.models.tpsl import TPSL
24
+ from crypticorn.trade.client.models.trading_action_type import TradingActionType
25
+ from typing import Optional, Set
26
+ from typing_extensions import Self
27
+
28
+
29
+ class SpotTradingAction(BaseModel):
30
+ """
31
+ Model for spot trading actions
32
+ """ # noqa: E501
33
+
34
+ created_at: Optional[StrictInt] = Field(
35
+ default=None, description="Timestamp of creation"
36
+ )
37
+ updated_at: Optional[StrictInt] = Field(
38
+ default=None, description="Timestamp of last update"
39
+ )
40
+ id: Optional[StrictStr] = Field(
41
+ default=None, description="Unique identifier for the resource"
42
+ )
43
+ execution_id: Optional[StrictStr] = None
44
+ open_order_execution_id: Optional[StrictStr] = None
45
+ action_type: TradingActionType = Field(description="The type of action.")
46
+ market_type: MarketType = Field(description="The type of market the action is for.")
47
+ strategy_id: StrictStr = Field(description="UID for the strategy.")
48
+ symbol: StrictStr = Field(
49
+ description="Trading symbol or asset pair in format: 'symbol/quote_currency' (see market service for valid symbols)"
50
+ )
51
+ is_limit: Optional[StrictBool] = None
52
+ limit_price: Optional[StrictStr] = None
53
+ allocation: StrictStr = Field(
54
+ description="How much of bot's balance to use for the order (for open actions). How much of the reference open order (open_order_execution_id) to close (for close actions). 0=0%, 1=100%."
55
+ )
56
+ take_profit: Optional[List[TPSL]] = None
57
+ stop_loss: Optional[List[TPSL]] = None
58
+ expiry_timestamp: Optional[StrictInt] = None
59
+ __properties: ClassVar[List[str]] = [
60
+ "created_at",
61
+ "updated_at",
62
+ "id",
63
+ "execution_id",
64
+ "open_order_execution_id",
65
+ "action_type",
66
+ "market_type",
67
+ "strategy_id",
68
+ "symbol",
69
+ "is_limit",
70
+ "limit_price",
71
+ "allocation",
72
+ "take_profit",
73
+ "stop_loss",
74
+ "expiry_timestamp",
75
+ ]
76
+
77
+ model_config = ConfigDict(
78
+ populate_by_name=True,
79
+ validate_assignment=True,
80
+ protected_namespaces=(),
81
+ )
82
+
83
+ def to_str(self) -> str:
84
+ """Returns the string representation of the model using alias"""
85
+ return pprint.pformat(self.model_dump(by_alias=True))
86
+
87
+ def to_json(self) -> str:
88
+ """Returns the JSON representation of the model using alias"""
89
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
90
+ return json.dumps(self.to_dict())
91
+
92
+ @classmethod
93
+ def from_json(cls, json_str: str) -> Optional[Self]:
94
+ """Create an instance of SpotTradingAction from a JSON string"""
95
+ return cls.from_dict(json.loads(json_str))
96
+
97
+ def to_dict(self) -> Dict[str, Any]:
98
+ """Return the dictionary representation of the model using alias.
99
+
100
+ This has the following differences from calling pydantic's
101
+ `self.model_dump(by_alias=True)`:
102
+
103
+ * `None` is only added to the output dict for nullable fields that
104
+ were set at model initialization. Other fields with value `None`
105
+ are ignored.
106
+ """
107
+ excluded_fields: Set[str] = set([])
108
+
109
+ _dict = self.model_dump(
110
+ by_alias=True,
111
+ exclude=excluded_fields,
112
+ exclude_none=True,
113
+ )
114
+ # override the default output from pydantic by calling `to_dict()` of each item in take_profit (list)
115
+ _items = []
116
+ if self.take_profit:
117
+ for _item_take_profit in self.take_profit:
118
+ if _item_take_profit:
119
+ _items.append(_item_take_profit.to_dict())
120
+ _dict["take_profit"] = _items
121
+ # override the default output from pydantic by calling `to_dict()` of each item in stop_loss (list)
122
+ _items = []
123
+ if self.stop_loss:
124
+ for _item_stop_loss in self.stop_loss:
125
+ if _item_stop_loss:
126
+ _items.append(_item_stop_loss.to_dict())
127
+ _dict["stop_loss"] = _items
128
+ # set to None if execution_id (nullable) is None
129
+ # and model_fields_set contains the field
130
+ if self.execution_id is None and "execution_id" in self.model_fields_set:
131
+ _dict["execution_id"] = None
132
+
133
+ # set to None if open_order_execution_id (nullable) is None
134
+ # and model_fields_set contains the field
135
+ if (
136
+ self.open_order_execution_id is None
137
+ and "open_order_execution_id" in self.model_fields_set
138
+ ):
139
+ _dict["open_order_execution_id"] = None
140
+
141
+ # set to None if is_limit (nullable) is None
142
+ # and model_fields_set contains the field
143
+ if self.is_limit is None and "is_limit" in self.model_fields_set:
144
+ _dict["is_limit"] = None
145
+
146
+ # set to None if limit_price (nullable) is None
147
+ # and model_fields_set contains the field
148
+ if self.limit_price is None and "limit_price" in self.model_fields_set:
149
+ _dict["limit_price"] = None
150
+
151
+ # set to None if take_profit (nullable) is None
152
+ # and model_fields_set contains the field
153
+ if self.take_profit is None and "take_profit" in self.model_fields_set:
154
+ _dict["take_profit"] = None
155
+
156
+ # set to None if stop_loss (nullable) is None
157
+ # and model_fields_set contains the field
158
+ if self.stop_loss is None and "stop_loss" in self.model_fields_set:
159
+ _dict["stop_loss"] = None
160
+
161
+ # set to None if expiry_timestamp (nullable) is None
162
+ # and model_fields_set contains the field
163
+ if (
164
+ self.expiry_timestamp is None
165
+ and "expiry_timestamp" in self.model_fields_set
166
+ ):
167
+ _dict["expiry_timestamp"] = None
168
+
169
+ return _dict
170
+
171
+ @classmethod
172
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
173
+ """Create an instance of SpotTradingAction from a dict"""
174
+ if obj is None:
175
+ return None
176
+
177
+ if not isinstance(obj, dict):
178
+ return cls.model_validate(obj)
179
+
180
+ _obj = cls.model_validate(
181
+ {
182
+ "created_at": obj.get("created_at"),
183
+ "updated_at": obj.get("updated_at"),
184
+ "id": obj.get("id"),
185
+ "execution_id": obj.get("execution_id"),
186
+ "open_order_execution_id": obj.get("open_order_execution_id"),
187
+ "action_type": obj.get("action_type"),
188
+ "market_type": obj.get("market_type"),
189
+ "strategy_id": obj.get("strategy_id"),
190
+ "symbol": obj.get("symbol"),
191
+ "is_limit": obj.get("is_limit"),
192
+ "limit_price": obj.get("limit_price"),
193
+ "allocation": obj.get("allocation"),
194
+ "take_profit": (
195
+ [TPSL.from_dict(_item) for _item in obj["take_profit"]]
196
+ if obj.get("take_profit") is not None
197
+ else None
198
+ ),
199
+ "stop_loss": (
200
+ [TPSL.from_dict(_item) for _item in obj["stop_loss"]]
201
+ if obj.get("stop_loss") is not None
202
+ else None
203
+ ),
204
+ "expiry_timestamp": obj.get("expiry_timestamp"),
205
+ }
206
+ )
207
+ return _obj