crypticorn 1.0.2rc3__py3-none-any.whl → 2.0.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.
Files changed (259) hide show
  1. crypticorn/__init__.py +3 -3
  2. crypticorn/auth/__init__.py +2 -0
  3. crypticorn/auth/client/__init__.py +112 -0
  4. crypticorn/auth/client/api/__init__.py +8 -0
  5. crypticorn/auth/client/api/admin_api.py +522 -0
  6. crypticorn/auth/client/api/auth_api.py +2089 -0
  7. crypticorn/auth/client/api/service_api.py +309 -0
  8. crypticorn/auth/client/api/user_api.py +2540 -0
  9. crypticorn/auth/client/api/wallet_api.py +1698 -0
  10. crypticorn/auth/client/api_client.py +758 -0
  11. crypticorn/auth/client/api_response.py +20 -0
  12. crypticorn/auth/client/configuration.py +584 -0
  13. crypticorn/auth/client/exceptions.py +220 -0
  14. crypticorn/auth/client/models/__init__.py +91 -0
  15. crypticorn/auth/client/models/add_wallet200_response.py +86 -0
  16. crypticorn/auth/client/models/add_wallet_request.py +107 -0
  17. crypticorn/auth/client/models/authorize_user200_response.py +107 -0
  18. crypticorn/auth/client/models/authorize_user200_response_auth.py +101 -0
  19. crypticorn/auth/client/models/authorize_user_request.py +96 -0
  20. crypticorn/auth/client/models/create_user_request.py +114 -0
  21. crypticorn/auth/client/models/list_wallets200_response.py +137 -0
  22. crypticorn/auth/client/models/list_wallets200_response_balances_inner.py +115 -0
  23. crypticorn/auth/client/models/list_wallets200_response_balances_inner_sale_round.py +115 -0
  24. crypticorn/auth/client/models/list_wallets200_response_balances_inner_wallet.py +168 -0
  25. crypticorn/auth/client/models/list_wallets200_response_balances_inner_wallet_vesting_wallets_inner.py +191 -0
  26. crypticorn/auth/client/models/list_wallets200_response_data_inner.py +102 -0
  27. crypticorn/auth/client/models/list_wallets200_response_user_value.py +118 -0
  28. crypticorn/auth/client/models/logout_default_response.py +108 -0
  29. crypticorn/auth/client/models/logout_default_response_issues_inner.py +83 -0
  30. crypticorn/auth/client/models/refresh_token_info200_response.py +97 -0
  31. crypticorn/auth/client/models/refresh_token_info200_response_user_session.py +105 -0
  32. crypticorn/auth/client/models/resend_verification_email_request.py +84 -0
  33. crypticorn/auth/client/models/revoke_user_tokens_request.py +83 -0
  34. crypticorn/auth/client/models/rotate_tokens200_response.py +110 -0
  35. crypticorn/auth/client/models/token_info200_response.py +97 -0
  36. crypticorn/auth/client/models/unlink_wallet_request.py +83 -0
  37. crypticorn/auth/client/models/update_user_request.py +93 -0
  38. crypticorn/auth/client/models/user_reset_password_request.py +87 -0
  39. crypticorn/auth/client/models/user_set_password_request.py +89 -0
  40. crypticorn/auth/client/models/verify200_response.py +110 -0
  41. crypticorn/auth/client/models/verify_email200_response.py +107 -0
  42. crypticorn/auth/client/models/verify_email200_response_auth.py +101 -0
  43. crypticorn/auth/client/models/verify_email200_response_auth_auth.py +110 -0
  44. crypticorn/auth/client/models/verify_email_request.py +83 -0
  45. crypticorn/auth/client/models/verify_wallet_request.py +91 -0
  46. crypticorn/auth/client/models/wallet_verified200_response.py +83 -0
  47. crypticorn/auth/client/models/whoami200_response.py +104 -0
  48. crypticorn/auth/client/rest.py +195 -0
  49. crypticorn/auth/main.py +45 -0
  50. crypticorn/client.py +46 -8
  51. crypticorn/common/__init__.py +5 -0
  52. crypticorn/common/auth.py +43 -0
  53. crypticorn/common/auth_client.py +163 -0
  54. crypticorn/common/errors.py +432 -0
  55. crypticorn/common/scopes.py +29 -0
  56. crypticorn/common/urls.py +25 -0
  57. crypticorn/hive/__init__.py +2 -1
  58. crypticorn/hive/client/__init__.py +57 -0
  59. crypticorn/hive/client/api/__init__.py +6 -0
  60. crypticorn/hive/client/api/data_api.py +594 -0
  61. crypticorn/hive/client/api/models_api.py +1680 -0
  62. crypticorn/hive/client/api/status_api.py +263 -0
  63. crypticorn/hive/client/api_client.py +758 -0
  64. crypticorn/hive/client/api_response.py +20 -0
  65. crypticorn/hive/client/configuration.py +612 -0
  66. crypticorn/hive/client/exceptions.py +220 -0
  67. crypticorn/hive/client/models/__init__.py +38 -0
  68. crypticorn/hive/client/models/coins.py +44 -0
  69. crypticorn/hive/client/models/data_download_response.py +113 -0
  70. crypticorn/hive/client/models/data_info.py +115 -0
  71. crypticorn/hive/client/models/data_value_value_value_inner.py +154 -0
  72. crypticorn/hive/client/models/data_version.py +35 -0
  73. crypticorn/hive/client/models/download_links.py +91 -0
  74. crypticorn/hive/client/models/evaluation.py +86 -0
  75. crypticorn/hive/client/models/evaluation_response.py +85 -0
  76. crypticorn/hive/client/models/feature_size.py +36 -0
  77. crypticorn/hive/client/models/http_validation_error.py +99 -0
  78. crypticorn/hive/client/models/model.py +133 -0
  79. crypticorn/hive/client/models/model_create.py +93 -0
  80. crypticorn/hive/client/models/model_status.py +35 -0
  81. crypticorn/hive/client/models/model_update.py +83 -0
  82. crypticorn/hive/client/models/target.py +36 -0
  83. crypticorn/hive/client/models/target_type.py +35 -0
  84. crypticorn/hive/client/models/validation_error.py +105 -0
  85. crypticorn/hive/client/models/validation_error_loc_inner.py +159 -0
  86. crypticorn/hive/client/py.typed +0 -0
  87. crypticorn/hive/client/rest.py +195 -0
  88. crypticorn/hive/main.py +27 -100
  89. crypticorn/klines/client/__init__.py +21 -7
  90. crypticorn/klines/client/api/__init__.py +0 -1
  91. crypticorn/klines/client/api/funding_rates_api.py +90 -79
  92. crypticorn/klines/client/api/health_check_api.py +29 -45
  93. crypticorn/klines/client/api/ohlcv_data_api.py +104 -87
  94. crypticorn/klines/client/api/symbols_api.py +36 -54
  95. crypticorn/klines/client/api/udf_api.py +228 -352
  96. crypticorn/klines/client/api_client.py +106 -148
  97. crypticorn/klines/client/api_response.py +2 -3
  98. crypticorn/klines/client/configuration.py +64 -50
  99. crypticorn/klines/client/exceptions.py +20 -16
  100. crypticorn/klines/client/models/__init__.py +21 -7
  101. crypticorn/klines/client/models/base_response_health_check_response.py +21 -15
  102. crypticorn/klines/client/models/base_response_list_funding_rate_response.py +21 -15
  103. crypticorn/klines/client/models/base_response_list_str.py +16 -14
  104. crypticorn/klines/client/models/base_response_ohlcv_response.py +21 -15
  105. crypticorn/klines/client/models/error_response.py +23 -15
  106. crypticorn/klines/client/models/exchange.py +11 -11
  107. crypticorn/klines/client/models/funding_rate_response.py +11 -11
  108. crypticorn/klines/client/models/health_check_response.py +14 -12
  109. crypticorn/klines/client/models/history_error_response.py +11 -11
  110. crypticorn/klines/client/models/history_no_data_response.py +16 -16
  111. crypticorn/klines/client/models/history_success_response.py +16 -16
  112. crypticorn/klines/client/models/http_validation_error.py +14 -10
  113. crypticorn/klines/client/models/market.py +2 -4
  114. crypticorn/klines/client/models/ohlcv_response.py +22 -15
  115. crypticorn/klines/client/models/resolution.py +5 -7
  116. crypticorn/klines/client/models/response_get_history_udf_history_get.py +71 -22
  117. crypticorn/klines/client/models/search_symbol_response.py +22 -15
  118. crypticorn/klines/client/models/sort_direction.py +2 -4
  119. crypticorn/klines/client/models/symbol_group_response.py +5 -9
  120. crypticorn/klines/client/models/symbol_info_response.py +40 -24
  121. crypticorn/klines/client/models/symbol_type.py +5 -10
  122. crypticorn/klines/client/models/timeframe.py +5 -7
  123. crypticorn/klines/client/models/udf_config_response.py +60 -21
  124. crypticorn/klines/client/models/validation_error.py +19 -13
  125. crypticorn/klines/client/models/validation_error_loc_inner.py +32 -11
  126. crypticorn/klines/client/rest.py +30 -41
  127. crypticorn/klines/main.py +52 -15
  128. crypticorn/pay/__init__.py +2 -0
  129. crypticorn/pay/client/__init__.py +52 -0
  130. crypticorn/pay/client/api/__init__.py +7 -0
  131. crypticorn/pay/client/api/now_payments_api.py +813 -0
  132. crypticorn/pay/client/api/payments_api.py +799 -0
  133. crypticorn/pay/client/api/products_api.py +891 -0
  134. crypticorn/pay/client/api/status_api.py +260 -0
  135. crypticorn/pay/client/api_client.py +758 -0
  136. crypticorn/pay/client/api_response.py +20 -0
  137. crypticorn/pay/client/configuration.py +612 -0
  138. crypticorn/pay/client/exceptions.py +220 -0
  139. crypticorn/pay/client/models/__init__.py +32 -0
  140. crypticorn/pay/client/models/api_status_res.py +83 -0
  141. crypticorn/pay/client/models/combined_payment_history.py +101 -0
  142. crypticorn/pay/client/models/create_invoice_req.py +188 -0
  143. crypticorn/pay/client/models/create_invoice_res.py +188 -0
  144. crypticorn/pay/client/models/currency.py +165 -0
  145. crypticorn/pay/client/models/estimate_price_req.py +91 -0
  146. crypticorn/pay/client/models/estimate_price_res.py +102 -0
  147. crypticorn/pay/client/models/get_currencies_res.py +99 -0
  148. crypticorn/pay/client/models/get_payment_status_res.py +222 -0
  149. crypticorn/pay/client/models/get_payments_list_res.py +109 -0
  150. crypticorn/pay/client/models/http_validation_error.py +99 -0
  151. crypticorn/pay/client/models/min_amount_req.py +124 -0
  152. crypticorn/pay/client/models/min_amount_res.py +105 -0
  153. crypticorn/pay/client/models/now_api_status_res.py +83 -0
  154. crypticorn/pay/client/models/now_create_invoice_req.py +188 -0
  155. crypticorn/pay/client/models/now_create_invoice_res.py +188 -0
  156. crypticorn/pay/client/models/now_fee_structure.py +104 -0
  157. crypticorn/pay/client/models/now_payment_model.py +124 -0
  158. crypticorn/pay/client/models/now_payment_status.py +42 -0
  159. crypticorn/pay/client/models/now_webhook_payload.py +181 -0
  160. crypticorn/pay/client/models/payment.py +231 -0
  161. crypticorn/pay/client/models/payment_status.py +40 -0
  162. crypticorn/pay/client/models/product.py +87 -0
  163. crypticorn/pay/client/models/product_model.py +119 -0
  164. crypticorn/pay/client/models/product_subs_model.py +108 -0
  165. crypticorn/pay/client/models/services.py +34 -0
  166. crypticorn/pay/client/models/unified_payment_model.py +112 -0
  167. crypticorn/pay/client/models/validation_error.py +105 -0
  168. crypticorn/pay/client/models/validation_error_loc_inner.py +159 -0
  169. crypticorn/pay/client/py.typed +0 -0
  170. crypticorn/pay/client/rest.py +195 -0
  171. crypticorn/pay/main.py +35 -0
  172. crypticorn/trade/client/__init__.py +9 -4
  173. crypticorn/trade/client/api/__init__.py +0 -1
  174. crypticorn/trade/client/api/api_keys_api.py +203 -304
  175. crypticorn/trade/client/api/bots_api.py +177 -250
  176. crypticorn/trade/client/api/exchanges_api.py +38 -57
  177. crypticorn/trade/client/api/futures_trading_panel_api.py +223 -321
  178. crypticorn/trade/client/api/notifications_api.py +247 -364
  179. crypticorn/trade/client/api/orders_api.py +44 -63
  180. crypticorn/trade/client/api/status_api.py +35 -53
  181. crypticorn/trade/client/api/strategies_api.py +852 -64
  182. crypticorn/trade/client/api/trading_actions_api.py +126 -203
  183. crypticorn/trade/client/api_client.py +115 -154
  184. crypticorn/trade/client/api_response.py +2 -3
  185. crypticorn/trade/client/configuration.py +128 -90
  186. crypticorn/trade/client/exceptions.py +21 -17
  187. crypticorn/trade/client/models/__init__.py +9 -4
  188. crypticorn/trade/client/models/action_model.py +114 -50
  189. crypticorn/trade/client/models/api_error_identifier.py +60 -51
  190. crypticorn/trade/client/models/api_error_level.py +37 -0
  191. crypticorn/trade/client/models/api_error_type.py +37 -0
  192. crypticorn/trade/client/models/api_key_model.py +49 -28
  193. crypticorn/trade/client/models/bot_model.py +76 -31
  194. crypticorn/trade/client/models/bot_status.py +37 -0
  195. crypticorn/trade/client/models/exchange.py +3 -5
  196. crypticorn/trade/client/models/execution_ids.py +14 -14
  197. crypticorn/trade/client/models/futures_balance.py +39 -23
  198. crypticorn/trade/client/models/futures_trading_action.py +98 -46
  199. crypticorn/trade/client/models/http_validation_error.py +15 -11
  200. crypticorn/trade/client/models/margin_mode.py +3 -5
  201. crypticorn/trade/client/models/market_type.py +3 -5
  202. crypticorn/trade/client/models/notification_model.py +60 -27
  203. crypticorn/trade/client/models/notification_type.py +4 -6
  204. crypticorn/trade/client/models/order_model.py +125 -65
  205. crypticorn/trade/client/models/order_status.py +6 -8
  206. crypticorn/trade/client/models/post_futures_action.py +16 -12
  207. crypticorn/trade/client/models/strategy_exchange_info.py +11 -12
  208. crypticorn/trade/client/models/strategy_model.py +66 -27
  209. crypticorn/trade/client/models/strategy_model_input.py +160 -0
  210. crypticorn/trade/client/models/strategy_model_output.py +160 -0
  211. crypticorn/trade/client/models/tpsl.py +35 -21
  212. crypticorn/trade/client/models/trading_action_type.py +5 -7
  213. crypticorn/trade/client/models/update_notification.py +17 -13
  214. crypticorn/trade/client/models/validation_error.py +20 -14
  215. crypticorn/trade/client/models/validation_error_loc_inner.py +33 -12
  216. crypticorn/trade/client/rest.py +108 -170
  217. crypticorn/trade/main.py +26 -19
  218. crypticorn-2.0.0.dist-info/METADATA +74 -0
  219. crypticorn-2.0.0.dist-info/RECORD +226 -0
  220. {crypticorn-1.0.2rc3.dist-info → crypticorn-2.0.0.dist-info}/WHEEL +1 -1
  221. crypticorn/hive/requirements.txt +0 -4
  222. crypticorn/hive/utils.py +0 -109
  223. crypticorn/klines/requirements.txt +0 -4
  224. crypticorn/klines/test/test_base_response_health_check_response.py +0 -56
  225. crypticorn/klines/test/test_base_response_list_funding_rate_response.py +0 -59
  226. crypticorn/klines/test/test_base_response_list_str.py +0 -56
  227. crypticorn/klines/test/test_base_response_ohlcv_response.py +0 -72
  228. crypticorn/klines/test/test_error_response.py +0 -57
  229. crypticorn/klines/test/test_exchange.py +0 -56
  230. crypticorn/klines/test/test_funding_rate_response.py +0 -56
  231. crypticorn/klines/test/test_funding_rates_api.py +0 -38
  232. crypticorn/klines/test/test_health_check_api.py +0 -38
  233. crypticorn/klines/test/test_health_check_response.py +0 -52
  234. crypticorn/klines/test/test_history_error_response.py +0 -53
  235. crypticorn/klines/test/test_history_no_data_response.py +0 -69
  236. crypticorn/klines/test/test_history_success_response.py +0 -87
  237. crypticorn/klines/test/test_http_validation_error.py +0 -58
  238. crypticorn/klines/test/test_market.py +0 -33
  239. crypticorn/klines/test/test_ohlcv_data_api.py +0 -38
  240. crypticorn/klines/test/test_ohlcv_response.py +0 -86
  241. crypticorn/klines/test/test_resolution.py +0 -33
  242. crypticorn/klines/test/test_response_get_history_udf_history_get.py +0 -89
  243. crypticorn/klines/test/test_search_symbol_response.py +0 -62
  244. crypticorn/klines/test/test_sort_direction.py +0 -33
  245. crypticorn/klines/test/test_symbol_group_response.py +0 -53
  246. crypticorn/klines/test/test_symbol_info_response.py +0 -84
  247. crypticorn/klines/test/test_symbol_type.py +0 -54
  248. crypticorn/klines/test/test_symbols_api.py +0 -38
  249. crypticorn/klines/test/test_timeframe.py +0 -33
  250. crypticorn/klines/test/test_udf_api.py +0 -80
  251. crypticorn/klines/test/test_udf_config_response.py +0 -95
  252. crypticorn/klines/test/test_validation_error.py +0 -60
  253. crypticorn/klines/test/test_validation_error_loc_inner.py +0 -50
  254. crypticorn/trade/requirements.txt +0 -4
  255. crypticorn-1.0.2rc3.dist-info/LICENSE.md +0 -19
  256. crypticorn-1.0.2rc3.dist-info/METADATA +0 -47
  257. crypticorn-1.0.2rc3.dist-info/RECORD +0 -128
  258. /crypticorn/{klines/test/__init__.py → auth/client/py.typed} +0 -0
  259. {crypticorn-1.0.2rc3.dist-info → crypticorn-2.0.0.dist-info}/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
3
  """
4
- FastAPI
4
+ Trading API
5
5
 
6
6
  No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
7
7
 
@@ -16,23 +16,16 @@ import io
16
16
  import json
17
17
  import re
18
18
  import ssl
19
+ from typing import Optional, Union
19
20
 
20
- import urllib3
21
+ import aiohttp
22
+ import aiohttp_retry
21
23
 
22
24
  from crypticorn.trade.client.exceptions import ApiException, ApiValueError
23
25
 
24
- SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
25
- RESTResponseType = urllib3.HTTPResponse
26
+ RESTResponseType = aiohttp.ClientResponse
26
27
 
27
-
28
- def is_socks_proxy_url(url):
29
- if url is None:
30
- return False
31
- split_section = url.split("://")
32
- if len(split_section) < 2:
33
- return False
34
- else:
35
- return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
28
+ ALLOW_RETRY_METHODS = frozenset({"DELETE", "GET", "HEAD", "OPTIONS", "PUT", "TRACE"})
36
29
 
37
30
 
38
31
  class RESTResponse(io.IOBase):
@@ -43,13 +36,13 @@ class RESTResponse(io.IOBase):
43
36
  self.reason = resp.reason
44
37
  self.data = None
45
38
 
46
- def read(self):
39
+ async def read(self):
47
40
  if self.data is None:
48
- self.data = self.response.data
41
+ self.data = await self.response.read()
49
42
  return self.data
50
43
 
51
44
  def getheaders(self):
52
- """Returns a dictionary of the response headers."""
45
+ """Returns a CIMultiDictProxy of the response headers."""
53
46
  return self.response.headers
54
47
 
55
48
  def getheader(self, name, default=None):
@@ -60,67 +53,44 @@ class RESTResponse(io.IOBase):
60
53
  class RESTClientObject:
61
54
 
62
55
  def __init__(self, configuration) -> None:
63
- # urllib3.PoolManager will pass all kw parameters to connectionpool
64
- # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
65
- # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501
66
- # Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501
67
-
68
- # cert_reqs
69
- if configuration.verify_ssl:
70
- cert_reqs = ssl.CERT_REQUIRED
71
- else:
72
- cert_reqs = ssl.CERT_NONE
73
-
74
- pool_args = {
75
- "cert_reqs": cert_reqs,
76
- "ca_certs": configuration.ssl_ca_cert,
77
- "cert_file": configuration.cert_file,
78
- "key_file": configuration.key_file,
79
- }
80
- if configuration.assert_hostname is not None:
81
- pool_args['assert_hostname'] = (
82
- configuration.assert_hostname
83
- )
84
56
 
85
- if configuration.retries is not None:
86
- pool_args['retries'] = configuration.retries
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(cafile=configuration.ssl_ca_cert)
61
+ if configuration.cert_file:
62
+ self.ssl_context.load_cert_chain(
63
+ configuration.cert_file, keyfile=configuration.key_file
64
+ )
87
65
 
88
- if configuration.tls_server_name:
89
- pool_args['server_hostname'] = configuration.tls_server_name
66
+ if not configuration.verify_ssl:
67
+ self.ssl_context.check_hostname = False
68
+ self.ssl_context.verify_mode = ssl.CERT_NONE
90
69
 
70
+ self.proxy = configuration.proxy
71
+ self.proxy_headers = configuration.proxy_headers
91
72
 
92
- if configuration.socket_options is not None:
93
- pool_args['socket_options'] = configuration.socket_options
73
+ self.retries = configuration.retries
94
74
 
95
- if configuration.connection_pool_maxsize is not None:
96
- pool_args['maxsize'] = configuration.connection_pool_maxsize
75
+ self.pool_manager: Optional[aiohttp.ClientSession] = None
76
+ self.retry_client: Optional[aiohttp_retry.RetryClient] = None
97
77
 
98
- # https pool manager
99
- self.pool_manager: urllib3.PoolManager
100
-
101
- if configuration.proxy:
102
- if is_socks_proxy_url(configuration.proxy):
103
- from urllib3.contrib.socks import SOCKSProxyManager
104
- pool_args["proxy_url"] = configuration.proxy
105
- pool_args["headers"] = configuration.proxy_headers
106
- self.pool_manager = SOCKSProxyManager(**pool_args)
107
- else:
108
- pool_args["proxy_url"] = configuration.proxy
109
- pool_args["proxy_headers"] = configuration.proxy_headers
110
- self.pool_manager = urllib3.ProxyManager(**pool_args)
111
- else:
112
- self.pool_manager = urllib3.PoolManager(**pool_args)
78
+ async def close(self) -> None:
79
+ if self.pool_manager:
80
+ await self.pool_manager.close()
81
+ if self.retry_client is not None:
82
+ await self.retry_client.close()
113
83
 
114
- def request(
84
+ async def request(
115
85
  self,
116
86
  method,
117
87
  url,
118
88
  headers=None,
119
89
  body=None,
120
90
  post_params=None,
121
- _request_timeout=None
91
+ _request_timeout=None,
122
92
  ):
123
- """Perform requests.
93
+ """Execute request
124
94
 
125
95
  :param method: http request method
126
96
  :param url: http request url
@@ -135,15 +105,7 @@ class RESTClientObject:
135
105
  (connection, read) timeouts.
136
106
  """
137
107
  method = method.upper()
138
- assert method in [
139
- 'GET',
140
- 'HEAD',
141
- 'DELETE',
142
- 'POST',
143
- 'PUT',
144
- 'PATCH',
145
- 'OPTIONS'
146
- ]
108
+ assert method in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"]
147
109
 
148
110
  if post_params and body:
149
111
  raise ApiValueError(
@@ -152,106 +114,82 @@ class RESTClientObject:
152
114
 
153
115
  post_params = post_params or {}
154
116
  headers = headers or {}
117
+ # url already contains the URL query string
118
+ timeout = _request_timeout or 5 * 60
119
+
120
+ if "Content-Type" not in headers:
121
+ headers["Content-Type"] = "application/json"
122
+
123
+ args = {"method": method, "url": url, "timeout": timeout, "headers": headers}
124
+
125
+ if self.proxy:
126
+ args["proxy"] = self.proxy
127
+ if self.proxy_headers:
128
+ args["proxy_headers"] = self.proxy_headers
129
+
130
+ # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
131
+ if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
132
+ if re.search("json", headers["Content-Type"], re.IGNORECASE):
133
+ if body is not None:
134
+ body = json.dumps(body)
135
+ args["data"] = body
136
+ elif headers["Content-Type"] == "application/x-www-form-urlencoded":
137
+ args["data"] = aiohttp.FormData(post_params)
138
+ elif headers["Content-Type"] == "multipart/form-data":
139
+ # must del headers['Content-Type'], or the correct
140
+ # Content-Type which generated by aiohttp
141
+ del headers["Content-Type"]
142
+ data = aiohttp.FormData()
143
+ for param in post_params:
144
+ k, v = param
145
+ if isinstance(v, tuple) and len(v) == 3:
146
+ data.add_field(k, value=v[1], filename=v[0], content_type=v[2])
147
+ else:
148
+ # Ensures that dict objects are serialized
149
+ if isinstance(v, dict):
150
+ v = json.dumps(v)
151
+ elif isinstance(v, int):
152
+ v = str(v)
153
+ data.add_field(k, v)
154
+ args["data"] = data
155
+
156
+ # Pass a `bytes` or `str` parameter directly in the body to support
157
+ # other content types than Json when `body` argument is provided
158
+ # in serialized form
159
+ elif isinstance(body, str) or isinstance(body, bytes):
160
+ args["data"] = body
161
+ else:
162
+ # Cannot generate the request from given parameters
163
+ msg = """Cannot prepare a request message for provided
164
+ arguments. Please check that your arguments match
165
+ declared content type."""
166
+ raise ApiException(status=0, reason=msg)
155
167
 
156
- timeout = None
157
- if _request_timeout:
158
- if isinstance(_request_timeout, (int, float)):
159
- timeout = urllib3.Timeout(total=_request_timeout)
160
- elif (
161
- isinstance(_request_timeout, tuple)
162
- and len(_request_timeout) == 2
163
- ):
164
- timeout = urllib3.Timeout(
165
- connect=_request_timeout[0],
166
- read=_request_timeout[1]
167
- )
168
+ pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
168
169
 
169
- try:
170
- # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
171
- if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
172
-
173
- # no content type provided or payload is json
174
- content_type = headers.get('Content-Type')
175
- if (
176
- not content_type
177
- or re.search('json', content_type, re.IGNORECASE)
178
- ):
179
- request_body = None
180
- if body is not None:
181
- request_body = json.dumps(body)
182
- r = self.pool_manager.request(
183
- method,
184
- url,
185
- body=request_body,
186
- timeout=timeout,
187
- headers=headers,
188
- preload_content=False
189
- )
190
- elif content_type == 'application/x-www-form-urlencoded':
191
- r = self.pool_manager.request(
192
- method,
193
- url,
194
- fields=post_params,
195
- encode_multipart=False,
196
- timeout=timeout,
197
- headers=headers,
198
- preload_content=False
199
- )
200
- elif content_type == 'multipart/form-data':
201
- # must del headers['Content-Type'], or the correct
202
- # Content-Type which generated by urllib3 will be
203
- # overwritten.
204
- del headers['Content-Type']
205
- # Ensures that dict objects are serialized
206
- post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
207
- r = self.pool_manager.request(
208
- method,
209
- url,
210
- fields=post_params,
211
- encode_multipart=True,
212
- timeout=timeout,
213
- headers=headers,
214
- preload_content=False
215
- )
216
- # Pass a `string` parameter directly in the body to support
217
- # other content types than JSON when `body` argument is
218
- # provided in serialized form.
219
- elif isinstance(body, str) or isinstance(body, bytes):
220
- r = self.pool_manager.request(
221
- method,
222
- url,
223
- body=body,
224
- timeout=timeout,
225
- headers=headers,
226
- preload_content=False
227
- )
228
- elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
229
- request_body = "true" if body else "false"
230
- r = self.pool_manager.request(
231
- method,
232
- url,
233
- body=request_body,
234
- preload_content=False,
235
- timeout=timeout,
236
- headers=headers)
237
- else:
238
- # Cannot generate the request from given parameters
239
- msg = """Cannot prepare a request message for provided
240
- arguments. Please check that your arguments match
241
- declared content type."""
242
- raise ApiException(status=0, reason=msg)
243
- # For `GET`, `HEAD`
244
- else:
245
- r = self.pool_manager.request(
246
- method,
247
- url,
248
- fields={},
249
- timeout=timeout,
250
- headers=headers,
251
- preload_content=False
170
+ # https pool manager
171
+ if self.pool_manager is None:
172
+ self.pool_manager = aiohttp.ClientSession(
173
+ connector=aiohttp.TCPConnector(
174
+ limit=self.maxsize, ssl=self.ssl_context
175
+ ),
176
+ trust_env=True,
177
+ )
178
+ pool_manager = self.pool_manager
179
+
180
+ if self.retries is not None and method in ALLOW_RETRY_METHODS:
181
+ if self.retry_client is None:
182
+ self.retry_client = aiohttp_retry.RetryClient(
183
+ client_session=self.pool_manager,
184
+ retry_options=aiohttp_retry.ExponentialRetry(
185
+ attempts=self.retries,
186
+ factor=2.0,
187
+ start_timeout=0.1,
188
+ max_timeout=120.0,
189
+ ),
252
190
  )
253
- except urllib3.exceptions.SSLError as e:
254
- msg = "\n".join([type(e).__name__, str(e)])
255
- raise ApiException(status=0, reason=msg)
191
+ pool_manager = self.retry_client
192
+
193
+ r = await pool_manager.request(**args)
256
194
 
257
195
  return RESTResponse(r)
crypticorn/trade/main.py CHANGED
@@ -1,16 +1,17 @@
1
1
  from crypticorn.trade import (
2
+ ApiClient,
3
+ APIKeysApi,
2
4
  BotsApi,
5
+ Configuration,
3
6
  ExchangesApi,
7
+ FuturesTradingPanelApi,
4
8
  NotificationsApi,
5
9
  OrdersApi,
6
10
  StatusApi,
7
11
  StrategiesApi,
8
12
  TradingActionsApi,
9
- FuturesTradingPanelApi,
10
- APIKeysApi,
11
- ApiClient,
12
- Configuration,
13
13
  )
14
+ from crypticorn.common import BaseURL, ApiVersion, Service, apikey_header as aph
14
15
 
15
16
 
16
17
  class TradeClient:
@@ -18,22 +19,28 @@ class TradeClient:
18
19
  A client for interacting with the Crypticorn Trade API.
19
20
  """
20
21
 
21
- def __init__(self, base_url: str = None, api_key: str = None, jwt: str = None):
22
- # Configure Trade client
23
- self.host = f"{base_url}/v1/trade"
24
- config = Configuration(
22
+ def __init__(
23
+ self,
24
+ base_url: BaseURL,
25
+ api_version: ApiVersion,
26
+ api_key: str = None,
27
+ jwt: str = None,
28
+ ):
29
+ self.host = f"{base_url.value}/{api_version.value}/{Service.TRADE.value}"
30
+ self.config = Configuration(
25
31
  host=self.host,
26
32
  access_token=jwt,
27
- # authorization=api_key, # TODO: add api key verification
33
+ api_key={aph.scheme_name: api_key} if api_key else None,
34
+ api_key_prefix=({aph.scheme_name: aph.model.name} if api_key else None),
28
35
  )
29
- base_client = ApiClient(configuration=config)
36
+ self.base_client = ApiClient(configuration=self.config)
30
37
  # Instantiate all the endpoint clients
31
- self.bots = BotsApi(base_client)
32
- self.exchanges = ExchangesApi(base_client)
33
- self.notifications = NotificationsApi(base_client)
34
- self.orders = OrdersApi(base_client)
35
- self.status = StatusApi(base_client)
36
- self.strategies = StrategiesApi(base_client)
37
- self.actions = TradingActionsApi(base_client)
38
- self.futures = FuturesTradingPanelApi(base_client)
39
- self.api_keys = APIKeysApi(base_client)
38
+ self.bots = BotsApi(self.base_client)
39
+ self.exchanges = ExchangesApi(self.base_client)
40
+ self.notifications = NotificationsApi(self.base_client)
41
+ self.orders = OrdersApi(self.base_client)
42
+ self.status = StatusApi(self.base_client)
43
+ self.strategies = StrategiesApi(self.base_client)
44
+ self.actions = TradingActionsApi(self.base_client)
45
+ self.futures = FuturesTradingPanelApi(self.base_client)
46
+ self.api_keys = APIKeysApi(self.base_client)
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: crypticorn
3
+ Version: 2.0.0
4
+ Summary: Maximise Your Crypto Trading Profits with AI Predictions
5
+ Author-email: Crypticorn <timon@crypticorn.com>
6
+ Project-URL: Homepage, https://crypticorn.com
7
+ Keywords: machine learning,data science,crypto,modelling
8
+ Classifier: Topic :: Scientific/Engineering
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: urllib3<3.0.0,>=1.25.3
17
+ Requires-Dist: python_dateutil>=2.8.2
18
+ Requires-Dist: aiohttp>=3.8.4
19
+ Requires-Dist: aiohttp-retry>=2.8.3
20
+ Requires-Dist: pydantic>=2
21
+ Requires-Dist: typing-extensions>=4.7.1
22
+ Requires-Dist: pandas<3.0.0,>=2.2.0
23
+ Requires-Dist: requests<3.0.0,>=2.32.0
24
+ Requires-Dist: tqdm<5.0.0,>=4.67.0
25
+ Requires-Dist: pydantic<3.0.0,>=2.0.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: streamlit; extra == "dev"
28
+ Requires-Dist: httpx; extra == "dev"
29
+ Requires-Dist: build; extra == "dev"
30
+ Requires-Dist: black; extra == "dev"
31
+ Requires-Dist: twine; extra == "dev"
32
+ Requires-Dist: pyflakes; extra == "dev"
33
+ Provides-Extra: test
34
+ Requires-Dist: pytest>=7.2.1; extra == "test"
35
+ Requires-Dist: pytest-cov>=2.8.1; extra == "test"
36
+ Requires-Dist: tox>=3.9.0; extra == "test"
37
+ Requires-Dist: flake8>=4.0.0; extra == "test"
38
+ Requires-Dist: types-python-dateutil>=2.8.19.14; extra == "test"
39
+ Requires-Dist: mypy>=1.5; extra == "test"
40
+
41
+ # What is Crypticorn?
42
+
43
+ Crypticorn is at the forefront of cutting-edge artificial intelligence cryptocurrency trading.
44
+ Crypticorn offers AI-based solutions for both active and passive investors, including:
45
+ - Prediction Dashboard with trading terminal,
46
+ - AI Agents with different strategies,
47
+ - DEX AI Signals for newly launched tokens,
48
+ - DEX AI Bots
49
+
50
+ Use this API Client to contribute to the so-called Hive AI, a community driven AI Meta Model for predicting the
51
+ cryptocurrency market.
52
+
53
+ ## Usage
54
+
55
+ Within an asynchronous context the session is closed automatically.
56
+ ```python
57
+ async with ApiClient(base_url="http://localhost", jwt=jwt) as client:
58
+ # json response
59
+ response = await client.pay.products.get_products_without_preload_content()
60
+ print(await response.json())
61
+ # serialized response with pydantic models
62
+ response = await client.pay.products.get_products()
63
+ print(response)
64
+ # json response with http info
65
+ response = await client.pay.products.get_products_with_http_info()
66
+ print(response)
67
+ ```
68
+
69
+ Without the context you need to close the session manually.
70
+ ```python
71
+ client = ApiClient(base_url="http://localhost", jwt=jwt)
72
+ response = asyncio.run(client.hive.models.get_all_models())
73
+ asyncio.run(client.close())
74
+ ```