crypticorn 1.0.0__py3-none-any.whl → 1.0.2rc1__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 (160) hide show
  1. crypticorn/__init__.py +3 -3
  2. crypticorn/client.py +722 -0
  3. crypticorn/{api.py → hive/main.py} +6 -6
  4. crypticorn/hive/requirements.txt +4 -0
  5. crypticorn/{utils.py → hive/utils.py} +2 -2
  6. crypticorn/klines/client/__init__.py +62 -0
  7. crypticorn/klines/client/api/__init__.py +9 -0
  8. crypticorn/klines/client/api/funding_rates_api.py +362 -0
  9. crypticorn/klines/client/api/health_check_api.py +281 -0
  10. crypticorn/klines/client/api/ohlcv_data_api.py +409 -0
  11. crypticorn/klines/client/api/symbols_api.py +308 -0
  12. crypticorn/klines/client/api/udf_api.py +1929 -0
  13. crypticorn/klines/client/api_client.py +797 -0
  14. crypticorn/klines/client/api_response.py +21 -0
  15. crypticorn/klines/client/configuration.py +565 -0
  16. crypticorn/klines/client/exceptions.py +216 -0
  17. crypticorn/klines/client/models/__init__.py +41 -0
  18. crypticorn/klines/client/models/base_response_health_check_response.py +108 -0
  19. crypticorn/klines/client/models/base_response_list_funding_rate_response.py +112 -0
  20. crypticorn/klines/client/models/base_response_list_str.py +104 -0
  21. crypticorn/klines/client/models/base_response_ohlcv_response.py +108 -0
  22. crypticorn/klines/client/models/error_response.py +101 -0
  23. crypticorn/klines/client/models/exchange.py +91 -0
  24. crypticorn/klines/client/models/funding_rate_response.py +92 -0
  25. crypticorn/klines/client/models/health_check_response.py +89 -0
  26. crypticorn/klines/client/models/history_error_response.py +89 -0
  27. crypticorn/klines/client/models/history_no_data_response.py +99 -0
  28. crypticorn/klines/client/models/history_success_response.py +99 -0
  29. crypticorn/klines/client/models/http_validation_error.py +95 -0
  30. crypticorn/klines/client/models/market.py +37 -0
  31. crypticorn/klines/client/models/ohlcv_response.py +98 -0
  32. crypticorn/klines/client/models/resolution.py +40 -0
  33. crypticorn/klines/client/models/response_get_history_udf_history_get.py +149 -0
  34. crypticorn/klines/client/models/search_symbol_response.py +97 -0
  35. crypticorn/klines/client/models/sort_direction.py +37 -0
  36. crypticorn/klines/client/models/symbol_group_response.py +87 -0
  37. crypticorn/klines/client/models/symbol_info_response.py +115 -0
  38. crypticorn/klines/client/models/symbol_type.py +89 -0
  39. crypticorn/klines/client/models/timeframe.py +40 -0
  40. crypticorn/klines/client/models/udf_config_response.py +121 -0
  41. crypticorn/klines/client/models/validation_error.py +99 -0
  42. crypticorn/klines/client/models/validation_error_loc_inner.py +138 -0
  43. crypticorn/klines/client/py.typed +0 -0
  44. crypticorn/klines/client/rest.py +257 -0
  45. crypticorn/klines/main.py +42 -0
  46. crypticorn/klines/requirements.txt +4 -0
  47. crypticorn/klines/test/__init__.py +0 -0
  48. crypticorn/klines/test/test_base_response_health_check_response.py +56 -0
  49. crypticorn/klines/test/test_base_response_list_funding_rate_response.py +59 -0
  50. crypticorn/klines/test/test_base_response_list_str.py +56 -0
  51. crypticorn/klines/test/test_base_response_ohlcv_response.py +72 -0
  52. crypticorn/klines/test/test_error_response.py +57 -0
  53. crypticorn/klines/test/test_exchange.py +56 -0
  54. crypticorn/klines/test/test_funding_rate_response.py +56 -0
  55. crypticorn/klines/test/test_funding_rates_api.py +38 -0
  56. crypticorn/klines/test/test_health_check_api.py +38 -0
  57. crypticorn/klines/test/test_health_check_response.py +52 -0
  58. crypticorn/klines/test/test_history_error_response.py +53 -0
  59. crypticorn/klines/test/test_history_no_data_response.py +69 -0
  60. crypticorn/klines/test/test_history_success_response.py +87 -0
  61. crypticorn/klines/test/test_http_validation_error.py +58 -0
  62. crypticorn/klines/test/test_market.py +33 -0
  63. crypticorn/klines/test/test_ohlcv_data_api.py +38 -0
  64. crypticorn/klines/test/test_ohlcv_response.py +86 -0
  65. crypticorn/klines/test/test_resolution.py +33 -0
  66. crypticorn/klines/test/test_response_get_history_udf_history_get.py +89 -0
  67. crypticorn/klines/test/test_search_symbol_response.py +62 -0
  68. crypticorn/klines/test/test_sort_direction.py +33 -0
  69. crypticorn/klines/test/test_symbol_group_response.py +53 -0
  70. crypticorn/klines/test/test_symbol_info_response.py +84 -0
  71. crypticorn/klines/test/test_symbol_type.py +54 -0
  72. crypticorn/klines/test/test_symbols_api.py +38 -0
  73. crypticorn/klines/test/test_timeframe.py +33 -0
  74. crypticorn/klines/test/test_udf_api.py +80 -0
  75. crypticorn/klines/test/test_udf_config_response.py +95 -0
  76. crypticorn/klines/test/test_validation_error.py +60 -0
  77. crypticorn/klines/test/test_validation_error_loc_inner.py +50 -0
  78. crypticorn/trade/client/__init__.py +63 -0
  79. crypticorn/trade/client/api/__init__.py +13 -0
  80. crypticorn/trade/client/api/api_keys_api.py +1468 -0
  81. crypticorn/trade/client/api/bots_api.py +1211 -0
  82. crypticorn/trade/client/api/exchanges_api.py +297 -0
  83. crypticorn/trade/client/api/futures_trading_panel_api.py +1463 -0
  84. crypticorn/trade/client/api/notifications_api.py +1767 -0
  85. crypticorn/trade/client/api/orders_api.py +331 -0
  86. crypticorn/trade/client/api/status_api.py +278 -0
  87. crypticorn/trade/client/api/strategies_api.py +331 -0
  88. crypticorn/trade/client/api/trading_actions_api.py +898 -0
  89. crypticorn/trade/client/api_client.py +797 -0
  90. crypticorn/trade/client/api_response.py +21 -0
  91. crypticorn/trade/client/configuration.py +574 -0
  92. crypticorn/trade/client/exceptions.py +216 -0
  93. crypticorn/trade/client/models/__init__.py +38 -0
  94. crypticorn/trade/client/models/action_model.py +202 -0
  95. crypticorn/trade/client/models/api_error_identifier.py +83 -0
  96. crypticorn/trade/client/models/api_key_model.py +135 -0
  97. crypticorn/trade/client/models/bot_model.py +122 -0
  98. crypticorn/trade/client/models/exchange.py +37 -0
  99. crypticorn/trade/client/models/execution_ids.py +91 -0
  100. crypticorn/trade/client/models/futures_balance.py +109 -0
  101. crypticorn/trade/client/models/futures_trading_action.py +198 -0
  102. crypticorn/trade/client/models/http_validation_error.py +95 -0
  103. crypticorn/trade/client/models/margin_mode.py +37 -0
  104. crypticorn/trade/client/models/market_type.py +37 -0
  105. crypticorn/trade/client/models/notification_model.py +113 -0
  106. crypticorn/trade/client/models/notification_type.py +39 -0
  107. crypticorn/trade/client/models/order_model.py +263 -0
  108. crypticorn/trade/client/models/order_status.py +40 -0
  109. crypticorn/trade/client/models/post_futures_action.py +93 -0
  110. crypticorn/trade/client/models/strategy_exchange_info.py +90 -0
  111. crypticorn/trade/client/models/strategy_model.py +119 -0
  112. crypticorn/trade/client/models/tpsl.py +116 -0
  113. crypticorn/trade/client/models/trading_action_type.py +39 -0
  114. crypticorn/trade/client/models/update_notification.py +91 -0
  115. crypticorn/trade/client/models/validation_error.py +99 -0
  116. crypticorn/trade/client/models/validation_error_loc_inner.py +138 -0
  117. crypticorn/trade/client/py.typed +0 -0
  118. crypticorn/trade/client/rest.py +257 -0
  119. crypticorn/trade/main.py +38 -0
  120. crypticorn/trade/requirements.txt +4 -0
  121. crypticorn/trade/test/__init__.py +0 -0
  122. crypticorn/trade/test/test_action_model.py +87 -0
  123. crypticorn/trade/test/test_api_error_identifier.py +33 -0
  124. crypticorn/trade/test/test_api_key_model.py +61 -0
  125. crypticorn/trade/test/test_api_keys_api.py +66 -0
  126. crypticorn/trade/test/test_bot_model.py +64 -0
  127. crypticorn/trade/test/test_bots_api.py +59 -0
  128. crypticorn/trade/test/test_exchange.py +33 -0
  129. crypticorn/trade/test/test_exchanges_api.py +38 -0
  130. crypticorn/trade/test/test_execution_ids.py +68 -0
  131. crypticorn/trade/test/test_futures_balance.py +62 -0
  132. crypticorn/trade/test/test_futures_trading_action.py +86 -0
  133. crypticorn/trade/test/test_futures_trading_panel_api.py +66 -0
  134. crypticorn/trade/test/test_http_validation_error.py +58 -0
  135. crypticorn/trade/test/test_margin_mode.py +33 -0
  136. crypticorn/trade/test/test_market_type.py +33 -0
  137. crypticorn/trade/test/test_notification_model.py +59 -0
  138. crypticorn/trade/test/test_notification_type.py +33 -0
  139. crypticorn/trade/test/test_notifications_api.py +73 -0
  140. crypticorn/trade/test/test_order_model.py +75 -0
  141. crypticorn/trade/test/test_order_status.py +33 -0
  142. crypticorn/trade/test/test_orders_api.py +38 -0
  143. crypticorn/trade/test/test_post_futures_action.py +72 -0
  144. crypticorn/trade/test/test_status_api.py +38 -0
  145. crypticorn/trade/test/test_strategies_api.py +38 -0
  146. crypticorn/trade/test/test_strategy_exchange_info.py +54 -0
  147. crypticorn/trade/test/test_strategy_model.py +73 -0
  148. crypticorn/trade/test/test_tpsl.py +56 -0
  149. crypticorn/trade/test/test_trading_action_type.py +33 -0
  150. crypticorn/trade/test/test_trading_actions_api.py +52 -0
  151. crypticorn/trade/test/test_update_notification.py +54 -0
  152. crypticorn/trade/test/test_validation_error.py +60 -0
  153. crypticorn/trade/test/test_validation_error_loc_inner.py +50 -0
  154. crypticorn-1.0.2rc1.dist-info/METADATA +47 -0
  155. crypticorn-1.0.2rc1.dist-info/RECORD +158 -0
  156. {crypticorn-1.0.0.dist-info → crypticorn-1.0.2rc1.dist-info}/WHEEL +1 -1
  157. crypticorn-1.0.0.dist-info/METADATA +0 -34
  158. crypticorn-1.0.0.dist-info/RECORD +0 -8
  159. {crypticorn-1.0.0.dist-info → crypticorn-1.0.2rc1.dist-info}/LICENSE.md +0 -0
  160. {crypticorn-1.0.0.dist-info → crypticorn-1.0.2rc1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,21 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Optional, Generic, Mapping, TypeVar
5
+ from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+ class ApiResponse(BaseModel, Generic[T]):
10
+ """
11
+ API response object
12
+ """
13
+
14
+ status_code: StrictInt = Field(description="HTTP status code")
15
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
16
+ data: T = Field(description="Deserialized data given the data type")
17
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
18
+
19
+ model_config = {
20
+ "arbitrary_types_allowed": True
21
+ }
@@ -0,0 +1,574 @@
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
+ import copy
16
+ import http.client as httplib
17
+ import logging
18
+ from logging import FileHandler
19
+ import multiprocessing
20
+ import sys
21
+ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict
22
+ from typing_extensions import NotRequired, Self
23
+
24
+ import urllib3
25
+
26
+
27
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
28
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
29
+ 'minimum', 'exclusiveMinimum', 'maxLength',
30
+ 'minLength', 'pattern', 'maxItems', 'minItems'
31
+ }
32
+
33
+ ServerVariablesT = Dict[str, str]
34
+
35
+ GenericAuthSetting = TypedDict(
36
+ "GenericAuthSetting",
37
+ {
38
+ "type": str,
39
+ "in": str,
40
+ "key": str,
41
+ "value": str,
42
+ },
43
+ )
44
+
45
+
46
+ OAuth2AuthSetting = TypedDict(
47
+ "OAuth2AuthSetting",
48
+ {
49
+ "type": Literal["oauth2"],
50
+ "in": Literal["header"],
51
+ "key": Literal["Authorization"],
52
+ "value": str,
53
+ },
54
+ )
55
+
56
+
57
+ APIKeyAuthSetting = TypedDict(
58
+ "APIKeyAuthSetting",
59
+ {
60
+ "type": Literal["api_key"],
61
+ "in": str,
62
+ "key": str,
63
+ "value": Optional[str],
64
+ },
65
+ )
66
+
67
+
68
+ BasicAuthSetting = TypedDict(
69
+ "BasicAuthSetting",
70
+ {
71
+ "type": Literal["basic"],
72
+ "in": Literal["header"],
73
+ "key": Literal["Authorization"],
74
+ "value": Optional[str],
75
+ },
76
+ )
77
+
78
+
79
+ BearerFormatAuthSetting = TypedDict(
80
+ "BearerFormatAuthSetting",
81
+ {
82
+ "type": Literal["bearer"],
83
+ "in": Literal["header"],
84
+ "format": Literal["JWT"],
85
+ "key": Literal["Authorization"],
86
+ "value": str,
87
+ },
88
+ )
89
+
90
+
91
+ BearerAuthSetting = TypedDict(
92
+ "BearerAuthSetting",
93
+ {
94
+ "type": Literal["bearer"],
95
+ "in": Literal["header"],
96
+ "key": Literal["Authorization"],
97
+ "value": str,
98
+ },
99
+ )
100
+
101
+
102
+ HTTPSignatureAuthSetting = TypedDict(
103
+ "HTTPSignatureAuthSetting",
104
+ {
105
+ "type": Literal["http-signature"],
106
+ "in": Literal["header"],
107
+ "key": Literal["Authorization"],
108
+ "value": None,
109
+ },
110
+ )
111
+
112
+
113
+ AuthSettings = TypedDict(
114
+ "AuthSettings",
115
+ {
116
+ "OAuth2PasswordBearer": OAuth2AuthSetting,
117
+ },
118
+ total=False,
119
+ )
120
+
121
+
122
+ class HostSettingVariable(TypedDict):
123
+ description: str
124
+ default_value: str
125
+ enum_values: List[str]
126
+
127
+
128
+ class HostSetting(TypedDict):
129
+ url: str
130
+ description: str
131
+ variables: NotRequired[Dict[str, HostSettingVariable]]
132
+
133
+
134
+ class Configuration:
135
+ """This class contains various settings of the API client.
136
+
137
+ :param host: Base url.
138
+ :param ignore_operation_servers
139
+ Boolean to ignore operation servers for the API client.
140
+ Config will use `host` as the base url regardless of the operation servers.
141
+ :param api_key: Dict to store API key(s).
142
+ Each entry in the dict specifies an API key.
143
+ The dict key is the name of the security scheme in the OAS specification.
144
+ The dict value is the API key secret.
145
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
146
+ The dict key is the name of the security scheme in the OAS specification.
147
+ The dict value is an API key prefix when generating the auth data.
148
+ :param username: Username for HTTP basic authentication.
149
+ :param password: Password for HTTP basic authentication.
150
+ :param access_token: Access token.
151
+ :param server_index: Index to servers configuration.
152
+ :param server_variables: Mapping with string values to replace variables in
153
+ templated server configuration. The validation of enums is performed for
154
+ variables with defined enum values before.
155
+ :param server_operation_index: Mapping from operation ID to an index to server
156
+ configuration.
157
+ :param server_operation_variables: Mapping from operation ID to a mapping with
158
+ string values to replace variables in templated server configuration.
159
+ The validation of enums is performed for variables with defined enum
160
+ values before.
161
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
162
+ in PEM format.
163
+ :param retries: Number of retries for API requests.
164
+
165
+ :Example:
166
+ """
167
+
168
+ _default: ClassVar[Optional[Self]] = None
169
+
170
+ def __init__(
171
+ self,
172
+ host: Optional[str]=None,
173
+ api_key: Optional[Dict[str, str]]=None,
174
+ api_key_prefix: Optional[Dict[str, str]]=None,
175
+ username: Optional[str]=None,
176
+ password: Optional[str]=None,
177
+ access_token: Optional[str]=None,
178
+ server_index: Optional[int]=None,
179
+ server_variables: Optional[ServerVariablesT]=None,
180
+ server_operation_index: Optional[Dict[int, int]]=None,
181
+ server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
182
+ ignore_operation_servers: bool=False,
183
+ ssl_ca_cert: Optional[str]=None,
184
+ retries: Optional[int] = None,
185
+ *,
186
+ debug: Optional[bool] = None,
187
+ ) -> None:
188
+ """Constructor
189
+ """
190
+ self._base_path = "http://localhost/v1/trade" if host is None else host
191
+ """Default Base url
192
+ """
193
+ self.server_index = 0 if server_index is None and host is None else server_index
194
+ self.server_operation_index = server_operation_index or {}
195
+ """Default server index
196
+ """
197
+ self.server_variables = server_variables or {}
198
+ self.server_operation_variables = server_operation_variables or {}
199
+ """Default server variables
200
+ """
201
+ self.ignore_operation_servers = ignore_operation_servers
202
+ """Ignore operation servers
203
+ """
204
+ self.temp_folder_path = None
205
+ """Temp file folder for downloading files
206
+ """
207
+ # Authentication Settings
208
+ self.api_key = {}
209
+ if api_key:
210
+ self.api_key = api_key
211
+ """dict to store API key(s)
212
+ """
213
+ self.api_key_prefix = {}
214
+ if api_key_prefix:
215
+ self.api_key_prefix = api_key_prefix
216
+ """dict to store API prefix (e.g. Bearer)
217
+ """
218
+ self.refresh_api_key_hook = None
219
+ """function hook to refresh API key if expired
220
+ """
221
+ self.username = username
222
+ """Username for HTTP basic authentication
223
+ """
224
+ self.password = password
225
+ """Password for HTTP basic authentication
226
+ """
227
+ self.access_token = access_token
228
+ """Access token
229
+ """
230
+ self.logger = {}
231
+ """Logging Settings
232
+ """
233
+ self.logger["package_logger"] = logging.getLogger("client")
234
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
235
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
236
+ """Log format
237
+ """
238
+ self.logger_stream_handler = None
239
+ """Log stream handler
240
+ """
241
+ self.logger_file_handler: Optional[FileHandler] = None
242
+ """Log file handler
243
+ """
244
+ self.logger_file = None
245
+ """Debug file location
246
+ """
247
+ if debug is not None:
248
+ self.debug = debug
249
+ else:
250
+ self.__debug = False
251
+ """Debug switch
252
+ """
253
+
254
+ self.verify_ssl = True
255
+ """SSL/TLS verification
256
+ Set this to false to skip verifying SSL certificate when calling API
257
+ from https server.
258
+ """
259
+ self.ssl_ca_cert = ssl_ca_cert
260
+ """Set this to customize the certificate file to verify the peer.
261
+ """
262
+ self.cert_file = None
263
+ """client certificate file
264
+ """
265
+ self.key_file = None
266
+ """client key file
267
+ """
268
+ self.assert_hostname = None
269
+ """Set this to True/False to enable/disable SSL hostname verification.
270
+ """
271
+ self.tls_server_name = None
272
+ """SSL/TLS Server Name Indication (SNI)
273
+ Set this to the SNI value expected by the server.
274
+ """
275
+
276
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
277
+ """urllib3 connection pool's maximum number of connections saved
278
+ per pool. urllib3 uses 1 connection as default value, but this is
279
+ not the best value when you are making a lot of possibly parallel
280
+ requests to the same host, which is often the case here.
281
+ cpu_count * 5 is used as default value to increase performance.
282
+ """
283
+
284
+ self.proxy: Optional[str] = None
285
+ """Proxy URL
286
+ """
287
+ self.proxy_headers = None
288
+ """Proxy headers
289
+ """
290
+ self.safe_chars_for_path_param = ''
291
+ """Safe chars for path_param
292
+ """
293
+ self.retries = retries
294
+ """Adding retries to override urllib3 default value 3
295
+ """
296
+ # Enable client side validation
297
+ self.client_side_validation = True
298
+
299
+ self.socket_options = None
300
+ """Options to pass down to the underlying urllib3 socket
301
+ """
302
+
303
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
304
+ """datetime format
305
+ """
306
+
307
+ self.date_format = "%Y-%m-%d"
308
+ """date format
309
+ """
310
+
311
+ def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
312
+ cls = self.__class__
313
+ result = cls.__new__(cls)
314
+ memo[id(self)] = result
315
+ for k, v in self.__dict__.items():
316
+ if k not in ('logger', 'logger_file_handler'):
317
+ setattr(result, k, copy.deepcopy(v, memo))
318
+ # shallow copy of loggers
319
+ result.logger = copy.copy(self.logger)
320
+ # use setters to configure loggers
321
+ result.logger_file = self.logger_file
322
+ result.debug = self.debug
323
+ return result
324
+
325
+ def __setattr__(self, name: str, value: Any) -> None:
326
+ object.__setattr__(self, name, value)
327
+
328
+ @classmethod
329
+ def set_default(cls, default: Optional[Self]) -> None:
330
+ """Set default instance of configuration.
331
+
332
+ It stores default configuration, which can be
333
+ returned by get_default_copy method.
334
+
335
+ :param default: object of Configuration
336
+ """
337
+ cls._default = default
338
+
339
+ @classmethod
340
+ def get_default_copy(cls) -> Self:
341
+ """Deprecated. Please use `get_default` instead.
342
+
343
+ Deprecated. Please use `get_default` instead.
344
+
345
+ :return: The configuration object.
346
+ """
347
+ return cls.get_default()
348
+
349
+ @classmethod
350
+ def get_default(cls) -> Self:
351
+ """Return the default configuration.
352
+
353
+ This method returns newly created, based on default constructor,
354
+ object of Configuration class or returns a copy of default
355
+ configuration.
356
+
357
+ :return: The configuration object.
358
+ """
359
+ if cls._default is None:
360
+ cls._default = cls()
361
+ return cls._default
362
+
363
+ @property
364
+ def logger_file(self) -> Optional[str]:
365
+ """The logger file.
366
+
367
+ If the logger_file is None, then add stream handler and remove file
368
+ handler. Otherwise, add file handler and remove stream handler.
369
+
370
+ :param value: The logger_file path.
371
+ :type: str
372
+ """
373
+ return self.__logger_file
374
+
375
+ @logger_file.setter
376
+ def logger_file(self, value: Optional[str]) -> None:
377
+ """The logger file.
378
+
379
+ If the logger_file is None, then add stream handler and remove file
380
+ handler. Otherwise, add file handler and remove stream handler.
381
+
382
+ :param value: The logger_file path.
383
+ :type: str
384
+ """
385
+ self.__logger_file = value
386
+ if self.__logger_file:
387
+ # If set logging file,
388
+ # then add file handler and remove stream handler.
389
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
390
+ self.logger_file_handler.setFormatter(self.logger_formatter)
391
+ for _, logger in self.logger.items():
392
+ logger.addHandler(self.logger_file_handler)
393
+
394
+ @property
395
+ def debug(self) -> bool:
396
+ """Debug status
397
+
398
+ :param value: The debug status, True or False.
399
+ :type: bool
400
+ """
401
+ return self.__debug
402
+
403
+ @debug.setter
404
+ def debug(self, value: bool) -> None:
405
+ """Debug status
406
+
407
+ :param value: The debug status, True or False.
408
+ :type: bool
409
+ """
410
+ self.__debug = value
411
+ if self.__debug:
412
+ # if debug status is True, turn on debug logging
413
+ for _, logger in self.logger.items():
414
+ logger.setLevel(logging.DEBUG)
415
+ # turn on httplib debug
416
+ httplib.HTTPConnection.debuglevel = 1
417
+ else:
418
+ # if debug status is False, turn off debug logging,
419
+ # setting log level to default `logging.WARNING`
420
+ for _, logger in self.logger.items():
421
+ logger.setLevel(logging.WARNING)
422
+ # turn off httplib debug
423
+ httplib.HTTPConnection.debuglevel = 0
424
+
425
+ @property
426
+ def logger_format(self) -> str:
427
+ """The logger format.
428
+
429
+ The logger_formatter will be updated when sets logger_format.
430
+
431
+ :param value: The format string.
432
+ :type: str
433
+ """
434
+ return self.__logger_format
435
+
436
+ @logger_format.setter
437
+ def logger_format(self, value: str) -> None:
438
+ """The logger format.
439
+
440
+ The logger_formatter will be updated when sets logger_format.
441
+
442
+ :param value: The format string.
443
+ :type: str
444
+ """
445
+ self.__logger_format = value
446
+ self.logger_formatter = logging.Formatter(self.__logger_format)
447
+
448
+ def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
449
+ """Gets API key (with prefix if set).
450
+
451
+ :param identifier: The identifier of apiKey.
452
+ :param alias: The alternative identifier of apiKey.
453
+ :return: The token for api key authentication.
454
+ """
455
+ if self.refresh_api_key_hook is not None:
456
+ self.refresh_api_key_hook(self)
457
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
458
+ if key:
459
+ prefix = self.api_key_prefix.get(identifier)
460
+ if prefix:
461
+ return "%s %s" % (prefix, key)
462
+ else:
463
+ return key
464
+
465
+ return None
466
+
467
+ def get_basic_auth_token(self) -> Optional[str]:
468
+ """Gets HTTP basic authentication header (string).
469
+
470
+ :return: The token for basic HTTP authentication.
471
+ """
472
+ username = ""
473
+ if self.username is not None:
474
+ username = self.username
475
+ password = ""
476
+ if self.password is not None:
477
+ password = self.password
478
+ return urllib3.util.make_headers(
479
+ basic_auth=username + ':' + password
480
+ ).get('authorization')
481
+
482
+ def auth_settings(self)-> AuthSettings:
483
+ """Gets Auth Settings dict for api client.
484
+
485
+ :return: The Auth Settings information dict.
486
+ """
487
+ auth: AuthSettings = {}
488
+ if self.access_token is not None:
489
+ auth['OAuth2PasswordBearer'] = {
490
+ 'type': 'oauth2',
491
+ 'in': 'header',
492
+ 'key': 'Authorization',
493
+ 'value': 'Bearer ' + self.access_token
494
+ }
495
+ return auth
496
+
497
+ def to_debug_report(self) -> str:
498
+ """Gets the essential information for debugging.
499
+
500
+ :return: The report for debugging.
501
+ """
502
+ return "Python SDK Debug Report:\n"\
503
+ "OS: {env}\n"\
504
+ "Python Version: {pyversion}\n"\
505
+ "Version of the API: 0.1.0\n"\
506
+ "SDK Package Version: 1.0.0".\
507
+ format(env=sys.platform, pyversion=sys.version)
508
+
509
+ def get_host_settings(self) -> List[HostSetting]:
510
+ """Gets an array of host settings
511
+
512
+ :return: An array of host settings
513
+ """
514
+ return [
515
+ {
516
+ 'url': "http://localhost/v1/trade",
517
+ 'description': "No description provided",
518
+ }
519
+ ]
520
+
521
+ def get_host_from_settings(
522
+ self,
523
+ index: Optional[int],
524
+ variables: Optional[ServerVariablesT]=None,
525
+ servers: Optional[List[HostSetting]]=None,
526
+ ) -> str:
527
+ """Gets host URL based on the index and variables
528
+ :param index: array index of the host settings
529
+ :param variables: hash of variable and the corresponding value
530
+ :param servers: an array of host settings or None
531
+ :return: URL based on host settings
532
+ """
533
+ if index is None:
534
+ return self._base_path
535
+
536
+ variables = {} if variables is None else variables
537
+ servers = self.get_host_settings() if servers is None else servers
538
+
539
+ try:
540
+ server = servers[index]
541
+ except IndexError:
542
+ raise ValueError(
543
+ "Invalid index {0} when selecting the host settings. "
544
+ "Must be less than {1}".format(index, len(servers)))
545
+
546
+ url = server['url']
547
+
548
+ # go through variables and replace placeholders
549
+ for variable_name, variable in server.get('variables', {}).items():
550
+ used_value = variables.get(
551
+ variable_name, variable['default_value'])
552
+
553
+ if 'enum_values' in variable \
554
+ and used_value not in variable['enum_values']:
555
+ raise ValueError(
556
+ "The variable `{0}` in the host URL has invalid value "
557
+ "{1}. Must be {2}.".format(
558
+ variable_name, variables[variable_name],
559
+ variable['enum_values']))
560
+
561
+ url = url.replace("{" + variable_name + "}", used_value)
562
+
563
+ return url
564
+
565
+ @property
566
+ def host(self) -> str:
567
+ """Return generated host."""
568
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
569
+
570
+ @host.setter
571
+ def host(self, value: str) -> None:
572
+ """Fix base path."""
573
+ self._base_path = value
574
+ self.server_index = None