webull-openapi-python-sdk 1.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 (295) hide show
  1. samples/__init__.py +1 -0
  2. samples/data/__init__.py +1 -0
  3. samples/data/data_client.py +57 -0
  4. samples/data/data_streaming_client.py +86 -0
  5. samples/data/data_streaming_client_async.py +101 -0
  6. samples/trade/__init__.py +0 -0
  7. samples/trade/trade_client.py +163 -0
  8. samples/trade/trade_client_v2.py +181 -0
  9. samples/trade/trade_event_client.py +47 -0
  10. webull/__init__.py +1 -0
  11. webull/core/__init__.py +12 -0
  12. webull/core/auth/__init__.py +0 -0
  13. webull/core/auth/algorithm/__init__.py +0 -0
  14. webull/core/auth/algorithm/sha_hmac1.py +65 -0
  15. webull/core/auth/algorithm/sha_hmac256.py +75 -0
  16. webull/core/auth/composer/__init__.py +0 -0
  17. webull/core/auth/composer/default_signature_composer.py +125 -0
  18. webull/core/auth/credentials.py +46 -0
  19. webull/core/auth/signers/__init__.py +0 -0
  20. webull/core/auth/signers/app_key_signer.py +72 -0
  21. webull/core/auth/signers/signer.py +48 -0
  22. webull/core/auth/signers/signer_factory.py +58 -0
  23. webull/core/cache/__init__.py +225 -0
  24. webull/core/client.py +410 -0
  25. webull/core/common/__init__.py +0 -0
  26. webull/core/common/api_type.py +19 -0
  27. webull/core/common/easy_enum.py +35 -0
  28. webull/core/common/region.py +7 -0
  29. webull/core/compat.py +85 -0
  30. webull/core/context/__init__.py +0 -0
  31. webull/core/context/request_context_holder.py +33 -0
  32. webull/core/data/endpoints.json +22 -0
  33. webull/core/data/retry_config.json +15 -0
  34. webull/core/endpoint/__init__.py +8 -0
  35. webull/core/endpoint/chained_endpoint_resolver.py +57 -0
  36. webull/core/endpoint/default_endpoint_resolver.py +60 -0
  37. webull/core/endpoint/local_config_regional_endpoint_resolver.py +77 -0
  38. webull/core/endpoint/resolver_endpoint_request.py +46 -0
  39. webull/core/endpoint/user_customized_endpoint_resolver.py +55 -0
  40. webull/core/exception/__init__.py +0 -0
  41. webull/core/exception/error_code.py +23 -0
  42. webull/core/exception/error_msg.py +21 -0
  43. webull/core/exception/exceptions.py +53 -0
  44. webull/core/headers.py +57 -0
  45. webull/core/http/__init__.py +0 -0
  46. webull/core/http/initializer/__init__.py +0 -0
  47. webull/core/http/initializer/client_initializer.py +79 -0
  48. webull/core/http/initializer/token/__init__.py +0 -0
  49. webull/core/http/initializer/token/bean/__init__.py +0 -0
  50. webull/core/http/initializer/token/bean/access_token.py +40 -0
  51. webull/core/http/initializer/token/bean/check_token_request.py +44 -0
  52. webull/core/http/initializer/token/bean/create_token_request.py +45 -0
  53. webull/core/http/initializer/token/bean/refresh_token_request.py +44 -0
  54. webull/core/http/initializer/token/token_manager.py +208 -0
  55. webull/core/http/initializer/token/token_operation.py +72 -0
  56. webull/core/http/method_type.py +43 -0
  57. webull/core/http/protocol_type.py +43 -0
  58. webull/core/http/request.py +121 -0
  59. webull/core/http/response.py +166 -0
  60. webull/core/request.py +278 -0
  61. webull/core/retry/__init__.py +0 -0
  62. webull/core/retry/backoff_strategy.py +102 -0
  63. webull/core/retry/retry_condition.py +214 -0
  64. webull/core/retry/retry_policy.py +63 -0
  65. webull/core/retry/retry_policy_context.py +51 -0
  66. webull/core/utils/__init__.py +0 -0
  67. webull/core/utils/common.py +62 -0
  68. webull/core/utils/data.py +25 -0
  69. webull/core/utils/desensitize.py +33 -0
  70. webull/core/utils/validation.py +49 -0
  71. webull/core/vendored/__init__.py +0 -0
  72. webull/core/vendored/requests/__init__.py +94 -0
  73. webull/core/vendored/requests/__version__.py +28 -0
  74. webull/core/vendored/requests/_internal_utils.py +56 -0
  75. webull/core/vendored/requests/adapters.py +539 -0
  76. webull/core/vendored/requests/api.py +166 -0
  77. webull/core/vendored/requests/auth.py +307 -0
  78. webull/core/vendored/requests/certs.py +34 -0
  79. webull/core/vendored/requests/compat.py +85 -0
  80. webull/core/vendored/requests/cookies.py +555 -0
  81. webull/core/vendored/requests/exceptions.py +136 -0
  82. webull/core/vendored/requests/help.py +134 -0
  83. webull/core/vendored/requests/hooks.py +48 -0
  84. webull/core/vendored/requests/models.py +960 -0
  85. webull/core/vendored/requests/packages/__init__.py +17 -0
  86. webull/core/vendored/requests/packages/certifi/__init__.py +17 -0
  87. webull/core/vendored/requests/packages/certifi/__main__.py +16 -0
  88. webull/core/vendored/requests/packages/certifi/cacert.pem +4433 -0
  89. webull/core/vendored/requests/packages/certifi/core.py +51 -0
  90. webull/core/vendored/requests/packages/chardet/__init__.py +53 -0
  91. webull/core/vendored/requests/packages/chardet/big5freq.py +400 -0
  92. webull/core/vendored/requests/packages/chardet/big5prober.py +61 -0
  93. webull/core/vendored/requests/packages/chardet/chardistribution.py +247 -0
  94. webull/core/vendored/requests/packages/chardet/charsetgroupprober.py +120 -0
  95. webull/core/vendored/requests/packages/chardet/charsetprober.py +159 -0
  96. webull/core/vendored/requests/packages/chardet/cli/__init__.py +1 -0
  97. webull/core/vendored/requests/packages/chardet/cli/chardetect.py +99 -0
  98. webull/core/vendored/requests/packages/chardet/codingstatemachine.py +102 -0
  99. webull/core/vendored/requests/packages/chardet/compat.py +48 -0
  100. webull/core/vendored/requests/packages/chardet/cp949prober.py +63 -0
  101. webull/core/vendored/requests/packages/chardet/enums.py +90 -0
  102. webull/core/vendored/requests/packages/chardet/escprober.py +115 -0
  103. webull/core/vendored/requests/packages/chardet/escsm.py +260 -0
  104. webull/core/vendored/requests/packages/chardet/eucjpprober.py +106 -0
  105. webull/core/vendored/requests/packages/chardet/euckrfreq.py +209 -0
  106. webull/core/vendored/requests/packages/chardet/euckrprober.py +61 -0
  107. webull/core/vendored/requests/packages/chardet/euctwfreq.py +401 -0
  108. webull/core/vendored/requests/packages/chardet/euctwprober.py +60 -0
  109. webull/core/vendored/requests/packages/chardet/gb2312freq.py +297 -0
  110. webull/core/vendored/requests/packages/chardet/gb2312prober.py +60 -0
  111. webull/core/vendored/requests/packages/chardet/hebrewprober.py +306 -0
  112. webull/core/vendored/requests/packages/chardet/jisfreq.py +339 -0
  113. webull/core/vendored/requests/packages/chardet/jpcntx.py +247 -0
  114. webull/core/vendored/requests/packages/chardet/langbulgarianmodel.py +242 -0
  115. webull/core/vendored/requests/packages/chardet/langcyrillicmodel.py +347 -0
  116. webull/core/vendored/requests/packages/chardet/langgreekmodel.py +239 -0
  117. webull/core/vendored/requests/packages/chardet/langhebrewmodel.py +214 -0
  118. webull/core/vendored/requests/packages/chardet/langhungarianmodel.py +239 -0
  119. webull/core/vendored/requests/packages/chardet/langthaimodel.py +213 -0
  120. webull/core/vendored/requests/packages/chardet/langturkishmodel.py +207 -0
  121. webull/core/vendored/requests/packages/chardet/latin1prober.py +159 -0
  122. webull/core/vendored/requests/packages/chardet/mbcharsetprober.py +105 -0
  123. webull/core/vendored/requests/packages/chardet/mbcsgroupprober.py +68 -0
  124. webull/core/vendored/requests/packages/chardet/mbcssm.py +586 -0
  125. webull/core/vendored/requests/packages/chardet/sbcharsetprober.py +146 -0
  126. webull/core/vendored/requests/packages/chardet/sbcsgroupprober.py +87 -0
  127. webull/core/vendored/requests/packages/chardet/sjisprober.py +106 -0
  128. webull/core/vendored/requests/packages/chardet/universaldetector.py +300 -0
  129. webull/core/vendored/requests/packages/chardet/utf8prober.py +96 -0
  130. webull/core/vendored/requests/packages/chardet/version.py +23 -0
  131. webull/core/vendored/requests/packages/urllib3/__init__.py +114 -0
  132. webull/core/vendored/requests/packages/urllib3/_collections.py +346 -0
  133. webull/core/vendored/requests/packages/urllib3/connection.py +405 -0
  134. webull/core/vendored/requests/packages/urllib3/connectionpool.py +910 -0
  135. webull/core/vendored/requests/packages/urllib3/contrib/__init__.py +0 -0
  136. webull/core/vendored/requests/packages/urllib3/contrib/_appengine_environ.py +44 -0
  137. webull/core/vendored/requests/packages/urllib3/contrib/_securetransport/__init__.py +0 -0
  138. webull/core/vendored/requests/packages/urllib3/contrib/_securetransport/bindings.py +607 -0
  139. webull/core/vendored/requests/packages/urllib3/contrib/_securetransport/low_level.py +360 -0
  140. webull/core/vendored/requests/packages/urllib3/contrib/appengine.py +303 -0
  141. webull/core/vendored/requests/packages/urllib3/contrib/ntlmpool.py +125 -0
  142. webull/core/vendored/requests/packages/urllib3/contrib/pyopenssl.py +484 -0
  143. webull/core/vendored/requests/packages/urllib3/contrib/securetransport.py +818 -0
  144. webull/core/vendored/requests/packages/urllib3/contrib/socks.py +206 -0
  145. webull/core/vendored/requests/packages/urllib3/exceptions.py +260 -0
  146. webull/core/vendored/requests/packages/urllib3/fields.py +192 -0
  147. webull/core/vendored/requests/packages/urllib3/filepost.py +112 -0
  148. webull/core/vendored/requests/packages/urllib3/packages/__init__.py +19 -0
  149. webull/core/vendored/requests/packages/urllib3/packages/backports/__init__.py +0 -0
  150. webull/core/vendored/requests/packages/urllib3/packages/backports/makefile.py +67 -0
  151. webull/core/vendored/requests/packages/urllib3/packages/ordered_dict.py +273 -0
  152. webull/core/vendored/requests/packages/urllib3/packages/six.py +882 -0
  153. webull/core/vendored/requests/packages/urllib3/packages/socks.py +887 -0
  154. webull/core/vendored/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py +19 -0
  155. webull/core/vendored/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.py +170 -0
  156. webull/core/vendored/requests/packages/urllib3/poolmanager.py +467 -0
  157. webull/core/vendored/requests/packages/urllib3/request.py +164 -0
  158. webull/core/vendored/requests/packages/urllib3/response.py +721 -0
  159. webull/core/vendored/requests/packages/urllib3/util/__init__.py +68 -0
  160. webull/core/vendored/requests/packages/urllib3/util/connection.py +148 -0
  161. webull/core/vendored/requests/packages/urllib3/util/queue.py +35 -0
  162. webull/core/vendored/requests/packages/urllib3/util/request.py +132 -0
  163. webull/core/vendored/requests/packages/urllib3/util/response.py +101 -0
  164. webull/core/vendored/requests/packages/urllib3/util/retry.py +426 -0
  165. webull/core/vendored/requests/packages/urllib3/util/selectors.py +601 -0
  166. webull/core/vendored/requests/packages/urllib3/util/ssl_.py +396 -0
  167. webull/core/vendored/requests/packages/urllib3/util/timeout.py +256 -0
  168. webull/core/vendored/requests/packages/urllib3/util/url.py +252 -0
  169. webull/core/vendored/requests/packages/urllib3/util/wait.py +164 -0
  170. webull/core/vendored/requests/packages.py +28 -0
  171. webull/core/vendored/requests/sessions.py +750 -0
  172. webull/core/vendored/requests/status_codes.py +105 -0
  173. webull/core/vendored/requests/structures.py +119 -0
  174. webull/core/vendored/requests/utils.py +916 -0
  175. webull/core/vendored/six.py +905 -0
  176. webull/data/__init__.py +3 -0
  177. webull/data/common/__init__.py +0 -0
  178. webull/data/common/category.py +26 -0
  179. webull/data/common/connect_ack.py +29 -0
  180. webull/data/common/direction.py +25 -0
  181. webull/data/common/exchange_code.py +33 -0
  182. webull/data/common/exercise_style.py +22 -0
  183. webull/data/common/expiration_cycle.py +26 -0
  184. webull/data/common/instrument_status.py +23 -0
  185. webull/data/common/option_type.py +20 -0
  186. webull/data/common/subscribe_type.py +22 -0
  187. webull/data/common/timespan.py +29 -0
  188. webull/data/data_client.py +35 -0
  189. webull/data/data_streaming_client.py +89 -0
  190. webull/data/internal/__init__.py +0 -0
  191. webull/data/internal/default_retry_policy.py +84 -0
  192. webull/data/internal/exceptions.py +60 -0
  193. webull/data/internal/quotes_client.py +314 -0
  194. webull/data/internal/quotes_decoder.py +40 -0
  195. webull/data/internal/quotes_payload_decoder.py +35 -0
  196. webull/data/internal/quotes_topic.py +36 -0
  197. webull/data/quotes/__init__.py +0 -0
  198. webull/data/quotes/instrument.py +33 -0
  199. webull/data/quotes/market_data.py +187 -0
  200. webull/data/quotes/market_streaming_data.py +66 -0
  201. webull/data/quotes/subscribe/__init__.py +0 -0
  202. webull/data/quotes/subscribe/ask_bid_result.py +49 -0
  203. webull/data/quotes/subscribe/basic_result.py +45 -0
  204. webull/data/quotes/subscribe/broker_result.py +33 -0
  205. webull/data/quotes/subscribe/message_pb2.py +37 -0
  206. webull/data/quotes/subscribe/order_result.py +30 -0
  207. webull/data/quotes/subscribe/payload_type.py +19 -0
  208. webull/data/quotes/subscribe/quote_decoder.py +28 -0
  209. webull/data/quotes/subscribe/quote_result.py +47 -0
  210. webull/data/quotes/subscribe/snapshot_decoder.py +30 -0
  211. webull/data/quotes/subscribe/snapshot_result.py +69 -0
  212. webull/data/quotes/subscribe/tick_decoder.py +29 -0
  213. webull/data/quotes/subscribe/tick_result.py +47 -0
  214. webull/data/request/__init__.py +0 -0
  215. webull/data/request/get_batch_historical_bars_request.py +43 -0
  216. webull/data/request/get_corp_action_request.py +47 -0
  217. webull/data/request/get_eod_bars_request.py +32 -0
  218. webull/data/request/get_historical_bars_request.py +43 -0
  219. webull/data/request/get_instruments_request.py +30 -0
  220. webull/data/request/get_quotes_request.py +35 -0
  221. webull/data/request/get_snapshot_request.py +38 -0
  222. webull/data/request/get_tick_request.py +37 -0
  223. webull/data/request/subscribe_request.py +43 -0
  224. webull/data/request/unsubscribe_request.py +42 -0
  225. webull/trade/__init__.py +2 -0
  226. webull/trade/common/__init__.py +0 -0
  227. webull/trade/common/account_type.py +22 -0
  228. webull/trade/common/category.py +29 -0
  229. webull/trade/common/combo_ticker_type.py +23 -0
  230. webull/trade/common/combo_type.py +31 -0
  231. webull/trade/common/currency.py +24 -0
  232. webull/trade/common/forbid_reason.py +27 -0
  233. webull/trade/common/instrument_type.py +27 -0
  234. webull/trade/common/markets.py +27 -0
  235. webull/trade/common/order_entrust_type.py +21 -0
  236. webull/trade/common/order_side.py +23 -0
  237. webull/trade/common/order_status.py +25 -0
  238. webull/trade/common/order_tif.py +24 -0
  239. webull/trade/common/order_type.py +30 -0
  240. webull/trade/common/trade_policy.py +22 -0
  241. webull/trade/common/trading_date_type.py +24 -0
  242. webull/trade/common/trailing_type.py +23 -0
  243. webull/trade/events/__init__.py +0 -0
  244. webull/trade/events/default_retry_policy.py +64 -0
  245. webull/trade/events/events_pb2.py +43 -0
  246. webull/trade/events/events_pb2_grpc.py +66 -0
  247. webull/trade/events/signature_composer.py +61 -0
  248. webull/trade/events/types.py +21 -0
  249. webull/trade/request/__init__.py +0 -0
  250. webull/trade/request/cancel_order_request.py +28 -0
  251. webull/trade/request/get_account_balance_request.py +28 -0
  252. webull/trade/request/get_account_positions_request.py +30 -0
  253. webull/trade/request/get_account_profile_request.py +26 -0
  254. webull/trade/request/get_app_subscriptions.py +28 -0
  255. webull/trade/request/get_open_orders_request.py +30 -0
  256. webull/trade/request/get_order_detail_request.py +27 -0
  257. webull/trade/request/get_today_orders_request.py +31 -0
  258. webull/trade/request/get_trade_calendar_request.py +30 -0
  259. webull/trade/request/get_trade_instrument_detail_request.py +24 -0
  260. webull/trade/request/get_trade_security_detail_request.py +42 -0
  261. webull/trade/request/get_tradeable_instruments_request.py +27 -0
  262. webull/trade/request/palce_order_request.py +91 -0
  263. webull/trade/request/place_order_request_v2.py +58 -0
  264. webull/trade/request/replace_order_request.py +73 -0
  265. webull/trade/request/replace_order_request_v2.py +38 -0
  266. webull/trade/request/v2/__init__.py +0 -0
  267. webull/trade/request/v2/cancel_option_request.py +28 -0
  268. webull/trade/request/v2/cancel_order_request.py +28 -0
  269. webull/trade/request/v2/get_account_balance_request.py +28 -0
  270. webull/trade/request/v2/get_account_list.py +23 -0
  271. webull/trade/request/v2/get_account_positions_request.py +24 -0
  272. webull/trade/request/v2/get_order_detail_request.py +26 -0
  273. webull/trade/request/v2/get_order_history_request.py +35 -0
  274. webull/trade/request/v2/palce_order_request.py +87 -0
  275. webull/trade/request/v2/place_option_request.py +64 -0
  276. webull/trade/request/v2/preview_option_request.py +28 -0
  277. webull/trade/request/v2/preview_order_request.py +59 -0
  278. webull/trade/request/v2/replace_option_request.py +28 -0
  279. webull/trade/request/v2/replace_order_request.py +57 -0
  280. webull/trade/trade/__init__.py +0 -0
  281. webull/trade/trade/account_info.py +83 -0
  282. webull/trade/trade/order_operation.py +246 -0
  283. webull/trade/trade/trade_calendar.py +37 -0
  284. webull/trade/trade/trade_instrument.py +72 -0
  285. webull/trade/trade/v2/__init__.py +0 -0
  286. webull/trade/trade/v2/account_info_v2.py +55 -0
  287. webull/trade/trade/v2/order_operation_v2.py +206 -0
  288. webull/trade/trade_client.py +43 -0
  289. webull/trade/trade_events_client.py +233 -0
  290. webull_openapi_python_sdk-1.0.0.dist-info/METADATA +28 -0
  291. webull_openapi_python_sdk-1.0.0.dist-info/RECORD +295 -0
  292. webull_openapi_python_sdk-1.0.0.dist-info/WHEEL +5 -0
  293. webull_openapi_python_sdk-1.0.0.dist-info/licenses/LICENSE +202 -0
  294. webull_openapi_python_sdk-1.0.0.dist-info/licenses/NOTICE +56 -0
  295. webull_openapi_python_sdk-1.0.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,166 @@
1
+ # Copyright 2022 Webull
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # -*- coding: utf-8 -*-
16
+
17
+ """
18
+ requests.api
19
+ ~~~~~~~~~~~~
20
+
21
+ This module implements the Requests API.
22
+
23
+ :copyright: (c) 2012 by Kenneth Reitz.
24
+ :license: Apache2, see LICENSE for more details.
25
+ """
26
+
27
+ from . import sessions
28
+
29
+
30
+ def request(method, url, **kwargs):
31
+ """Constructs and sends a :class:`Request <Request>`.
32
+
33
+ :param method: method for the new :class:`Request` object.
34
+ :param url: URL for the new :class:`Request` object.
35
+ :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
36
+ :param data: (optional) Dictionary or list of tuples ``[(key, value)]`` (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
37
+ :param json: (optional) json data to send in the body of the :class:`Request`.
38
+ :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
39
+ :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
40
+ :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
41
+ ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
42
+ or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
43
+ defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
44
+ to add for the file.
45
+ :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
46
+ :param timeout: (optional) How many seconds to wait for the server to send data
47
+ before giving up, as a float, or a :ref:`(connect timeout, read
48
+ timeout) <timeouts>` tuple.
49
+ :type timeout: float or tuple
50
+ :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
51
+ :type allow_redirects: bool
52
+ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
53
+ :param verify: (optional) Either a boolean, in which case it controls whether we verify
54
+ the server's TLS certificate, or a string, in which case it must be a path
55
+ to a CA bundle to use. Defaults to ``True``.
56
+ :param stream: (optional) if ``False``, the response content will be immediately downloaded.
57
+ :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
58
+ :return: :class:`Response <Response>` object
59
+ :rtype: requests.Response
60
+
61
+ Usage::
62
+
63
+ >>> import requests
64
+ >>> req = requests.request('GET', 'http://httpbin.org/get')
65
+ <Response [200]>
66
+ """
67
+
68
+ # By using the 'with' statement we are sure the session is closed, thus we
69
+ # avoid leaving sockets open which can trigger a ResourceWarning in some
70
+ # cases, and look like a memory leak in others.
71
+ with sessions.Session() as session:
72
+ return session.request(method=method, url=url, **kwargs)
73
+
74
+
75
+ def get(url, params=None, **kwargs):
76
+ r"""Sends a GET request.
77
+
78
+ :param url: URL for the new :class:`Request` object.
79
+ :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
80
+ :param \*\*kwargs: Optional arguments that ``request`` takes.
81
+ :return: :class:`Response <Response>` object
82
+ :rtype: requests.Response
83
+ """
84
+
85
+ kwargs.setdefault('allow_redirects', True)
86
+ return request('get', url, params=params, **kwargs)
87
+
88
+
89
+ def options(url, **kwargs):
90
+ r"""Sends an OPTIONS request.
91
+
92
+ :param url: URL for the new :class:`Request` object.
93
+ :param \*\*kwargs: Optional arguments that ``request`` takes.
94
+ :return: :class:`Response <Response>` object
95
+ :rtype: requests.Response
96
+ """
97
+
98
+ kwargs.setdefault('allow_redirects', True)
99
+ return request('options', url, **kwargs)
100
+
101
+
102
+ def head(url, **kwargs):
103
+ r"""Sends a HEAD request.
104
+
105
+ :param url: URL for the new :class:`Request` object.
106
+ :param \*\*kwargs: Optional arguments that ``request`` takes.
107
+ :return: :class:`Response <Response>` object
108
+ :rtype: requests.Response
109
+ """
110
+
111
+ kwargs.setdefault('allow_redirects', False)
112
+ return request('head', url, **kwargs)
113
+
114
+
115
+ def post(url, data=None, json=None, **kwargs):
116
+ r"""Sends a POST request.
117
+
118
+ :param url: URL for the new :class:`Request` object.
119
+ :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
120
+ :param json: (optional) json data to send in the body of the :class:`Request`.
121
+ :param \*\*kwargs: Optional arguments that ``request`` takes.
122
+ :return: :class:`Response <Response>` object
123
+ :rtype: requests.Response
124
+ """
125
+
126
+ return request('post', url, data=data, json=json, **kwargs)
127
+
128
+
129
+ def put(url, data=None, **kwargs):
130
+ r"""Sends a PUT request.
131
+
132
+ :param url: URL for the new :class:`Request` object.
133
+ :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
134
+ :param json: (optional) json data to send in the body of the :class:`Request`.
135
+ :param \*\*kwargs: Optional arguments that ``request`` takes.
136
+ :return: :class:`Response <Response>` object
137
+ :rtype: requests.Response
138
+ """
139
+
140
+ return request('put', url, data=data, **kwargs)
141
+
142
+
143
+ def patch(url, data=None, **kwargs):
144
+ r"""Sends a PATCH request.
145
+
146
+ :param url: URL for the new :class:`Request` object.
147
+ :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
148
+ :param json: (optional) json data to send in the body of the :class:`Request`.
149
+ :param \*\*kwargs: Optional arguments that ``request`` takes.
150
+ :return: :class:`Response <Response>` object
151
+ :rtype: requests.Response
152
+ """
153
+
154
+ return request('patch', url, data=data, **kwargs)
155
+
156
+
157
+ def delete(url, **kwargs):
158
+ r"""Sends a DELETE request.
159
+
160
+ :param url: URL for the new :class:`Request` object.
161
+ :param \*\*kwargs: Optional arguments that ``request`` takes.
162
+ :return: :class:`Response <Response>` object
163
+ :rtype: requests.Response
164
+ """
165
+
166
+ return request('delete', url, **kwargs)
@@ -0,0 +1,307 @@
1
+ # Copyright 2022 Webull
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # -*- coding: utf-8 -*-
16
+
17
+ """
18
+ requests.auth
19
+ ~~~~~~~~~~~~~
20
+
21
+ This module contains the authentication handlers for Requests.
22
+ """
23
+
24
+ import os
25
+ import re
26
+ import time
27
+ import hashlib
28
+ import threading
29
+ import warnings
30
+
31
+ from base64 import b64encode
32
+
33
+ from .compat import urlparse, str, basestring
34
+ from .cookies import extract_cookies_to_jar
35
+ from ._internal_utils import to_native_string
36
+ from .utils import parse_dict_header
37
+
38
+ CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'
39
+ CONTENT_TYPE_MULTI_PART = 'multipart/form-data'
40
+
41
+
42
+ def _basic_auth_str(username, password):
43
+ """Returns a Basic Auth string."""
44
+
45
+ # "I want us to put a big-ol' comment on top of it that
46
+ # says that this behaviour is dumb but we need to preserve
47
+ # it because people are relying on it."
48
+ # - Lukasa
49
+ #
50
+ # These are here solely to maintain backwards compatibility
51
+ # for things like ints. This will be removed in 3.0.0.
52
+ if not isinstance(username, basestring):
53
+ warnings.warn(
54
+ "Non-string usernames will no longer be supported in Requests "
55
+ "3.0.0. Please convert the object you've passed in ({0!r}) to "
56
+ "a string or bytes object in the near future to avoid "
57
+ "problems.".format(username),
58
+ category=DeprecationWarning,
59
+ )
60
+ username = str(username)
61
+
62
+ if not isinstance(password, basestring):
63
+ warnings.warn(
64
+ "Non-string passwords will no longer be supported in Requests "
65
+ "3.0.0. Please convert the object you've passed in ({0!r}) to "
66
+ "a string or bytes object in the near future to avoid "
67
+ "problems.".format(password),
68
+ category=DeprecationWarning,
69
+ )
70
+ password = str(password)
71
+ # -- End Removal --
72
+
73
+ if isinstance(username, str):
74
+ username = username.encode('latin1')
75
+
76
+ if isinstance(password, str):
77
+ password = password.encode('latin1')
78
+
79
+ authstr = 'Basic ' + to_native_string(
80
+ b64encode(b':'.join((username, password))).strip()
81
+ )
82
+
83
+ return authstr
84
+
85
+
86
+ class AuthBase(object):
87
+ """Base class that all auth implementations derive from"""
88
+
89
+ def __call__(self, r):
90
+ raise NotImplementedError('Auth hooks must be callable.')
91
+
92
+
93
+ class HTTPBasicAuth(AuthBase):
94
+ """Attaches HTTP Basic Authentication to the given Request object."""
95
+
96
+ def __init__(self, username, password):
97
+ self.username = username
98
+ self.password = password
99
+
100
+ def __eq__(self, other):
101
+ return all([
102
+ self.username == getattr(other, 'username', None),
103
+ self.password == getattr(other, 'password', None)
104
+ ])
105
+
106
+ def __ne__(self, other):
107
+ return not self == other
108
+
109
+ def __call__(self, r):
110
+ r.headers['Authorization'] = _basic_auth_str(self.username, self.password)
111
+ return r
112
+
113
+
114
+ class HTTPProxyAuth(HTTPBasicAuth):
115
+ """Attaches HTTP Proxy Authentication to a given Request object."""
116
+
117
+ def __call__(self, r):
118
+ r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password)
119
+ return r
120
+
121
+
122
+ class HTTPDigestAuth(AuthBase):
123
+ """Attaches HTTP Digest Authentication to the given Request object."""
124
+
125
+ def __init__(self, username, password):
126
+ self.username = username
127
+ self.password = password
128
+ # Keep state in per-thread local storage
129
+ self._thread_local = threading.local()
130
+
131
+ def init_per_thread_state(self):
132
+ # Ensure state is initialized just once per-thread
133
+ if not hasattr(self._thread_local, 'init'):
134
+ self._thread_local.init = True
135
+ self._thread_local.last_nonce = ''
136
+ self._thread_local.nonce_count = 0
137
+ self._thread_local.chal = {}
138
+ self._thread_local.pos = None
139
+ self._thread_local.num_401_calls = None
140
+
141
+ def build_digest_header(self, method, url):
142
+ """
143
+ :rtype: str
144
+ """
145
+
146
+ realm = self._thread_local.chal['realm']
147
+ nonce = self._thread_local.chal['nonce']
148
+ qop = self._thread_local.chal.get('qop')
149
+ algorithm = self._thread_local.chal.get('algorithm')
150
+ opaque = self._thread_local.chal.get('opaque')
151
+ hash_utf8 = None
152
+
153
+ if algorithm is None:
154
+ _algorithm = 'MD5'
155
+ else:
156
+ _algorithm = algorithm.upper()
157
+ # lambdas assume digest modules are imported at the top level
158
+ if _algorithm == 'MD5' or _algorithm == 'MD5-SESS':
159
+ def md5_utf8(x):
160
+ if isinstance(x, str):
161
+ x = x.encode('utf-8')
162
+ return hashlib.md5(x).hexdigest()
163
+ hash_utf8 = md5_utf8
164
+ elif _algorithm == 'SHA':
165
+ def sha_utf8(x):
166
+ if isinstance(x, str):
167
+ x = x.encode('utf-8')
168
+ return hashlib.sha1(x).hexdigest()
169
+ hash_utf8 = sha_utf8
170
+
171
+ KD = lambda s, d: hash_utf8("%s:%s" % (s, d))
172
+
173
+ if hash_utf8 is None:
174
+ return None
175
+
176
+ # XXX not implemented yet
177
+ entdig = None
178
+ p_parsed = urlparse(url)
179
+ #: path is request-uri defined in RFC 2616 which should not be empty
180
+ path = p_parsed.path or "/"
181
+ if p_parsed.query:
182
+ path += '?' + p_parsed.query
183
+
184
+ A1 = '%s:%s:%s' % (self.username, realm, self.password)
185
+ A2 = '%s:%s' % (method, path)
186
+
187
+ HA1 = hash_utf8(A1)
188
+ HA2 = hash_utf8(A2)
189
+
190
+ if nonce == self._thread_local.last_nonce:
191
+ self._thread_local.nonce_count += 1
192
+ else:
193
+ self._thread_local.nonce_count = 1
194
+ ncvalue = '%08x' % self._thread_local.nonce_count
195
+ s = str(self._thread_local.nonce_count).encode('utf-8')
196
+ s += nonce.encode('utf-8')
197
+ s += time.ctime().encode('utf-8')
198
+ s += os.urandom(8)
199
+
200
+ cnonce = (hashlib.sha1(s).hexdigest()[:16])
201
+ if _algorithm == 'MD5-SESS':
202
+ HA1 = hash_utf8('%s:%s:%s' % (HA1, nonce, cnonce))
203
+
204
+ if not qop:
205
+ respdig = KD(HA1, "%s:%s" % (nonce, HA2))
206
+ elif qop == 'auth' or 'auth' in qop.split(','):
207
+ noncebit = "%s:%s:%s:%s:%s" % (
208
+ nonce, ncvalue, cnonce, 'auth', HA2
209
+ )
210
+ respdig = KD(HA1, noncebit)
211
+ else:
212
+ # XXX handle auth-int.
213
+ return None
214
+
215
+ self._thread_local.last_nonce = nonce
216
+
217
+ # XXX should the partial digests be encoded too?
218
+ base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \
219
+ 'response="%s"' % (self.username, realm, nonce, path, respdig)
220
+ if opaque:
221
+ base += ', opaque="%s"' % opaque
222
+ if algorithm:
223
+ base += ', algorithm="%s"' % algorithm
224
+ if entdig:
225
+ base += ', digest="%s"' % entdig
226
+ if qop:
227
+ base += ', qop="auth", nc=%s, cnonce="%s"' % (ncvalue, cnonce)
228
+
229
+ return 'Digest %s' % (base)
230
+
231
+ def handle_redirect(self, r, **kwargs):
232
+ """Reset num_401_calls counter on redirects."""
233
+ if r.is_redirect:
234
+ self._thread_local.num_401_calls = 1
235
+
236
+ def handle_401(self, r, **kwargs):
237
+ """
238
+ Takes the given response and tries digest-auth, if needed.
239
+
240
+ :rtype: requests.Response
241
+ """
242
+
243
+ # If response is not 4xx, do not auth
244
+ # See https://github.com/requests/requests/issues/3772
245
+ if not 400 <= r.status_code < 500:
246
+ self._thread_local.num_401_calls = 1
247
+ return r
248
+
249
+ if self._thread_local.pos is not None:
250
+ # Rewind the file position indicator of the body to where
251
+ # it was to resend the request.
252
+ r.request.body.seek(self._thread_local.pos)
253
+ s_auth = r.headers.get('www-authenticate', '')
254
+
255
+ if 'digest' in s_auth.lower() and self._thread_local.num_401_calls < 2:
256
+
257
+ self._thread_local.num_401_calls += 1
258
+ pat = re.compile(r'digest ', flags=re.IGNORECASE)
259
+ self._thread_local.chal = parse_dict_header(pat.sub('', s_auth, count=1))
260
+
261
+ # Consume content and release the original connection
262
+ # to allow our new request to reuse the same one.
263
+ r.content
264
+ r.close()
265
+ prep = r.request.copy()
266
+ extract_cookies_to_jar(prep._cookies, r.request, r.raw)
267
+ prep.prepare_cookies(prep._cookies)
268
+
269
+ prep.headers['Authorization'] = self.build_digest_header(
270
+ prep.method, prep.url)
271
+ _r = r.connection.send(prep, **kwargs)
272
+ _r.history.append(r)
273
+ _r.request = prep
274
+
275
+ return _r
276
+
277
+ self._thread_local.num_401_calls = 1
278
+ return r
279
+
280
+ def __call__(self, r):
281
+ # Initialize per-thread state, if needed
282
+ self.init_per_thread_state()
283
+ # If we have a saved nonce, skip the 401
284
+ if self._thread_local.last_nonce:
285
+ r.headers['Authorization'] = self.build_digest_header(r.method, r.url)
286
+ try:
287
+ self._thread_local.pos = r.body.tell()
288
+ except AttributeError:
289
+ # In the case of HTTPDigestAuth being reused and the body of
290
+ # the previous request was a file-like object, pos has the
291
+ # file position of the previous body. Ensure it's set to
292
+ # None.
293
+ self._thread_local.pos = None
294
+ r.register_hook('response', self.handle_401)
295
+ r.register_hook('response', self.handle_redirect)
296
+ self._thread_local.num_401_calls = 1
297
+
298
+ return r
299
+
300
+ def __eq__(self, other):
301
+ return all([
302
+ self.username == getattr(other, 'username', None),
303
+ self.password == getattr(other, 'password', None)
304
+ ])
305
+
306
+ def __ne__(self, other):
307
+ return not self == other
@@ -0,0 +1,34 @@
1
+ # Copyright 2022 Webull
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ #!/usr/bin/env python
16
+ # -*- coding: utf-8 -*-
17
+
18
+ """
19
+ requests.certs
20
+ ~~~~~~~~~~~~~~
21
+
22
+ This module returns the preferred default CA certificate bundle. There is
23
+ only one — the one from the certifi package.
24
+
25
+ If you are packaging Requests, e.g., for a Linux distribution or a managed
26
+ environment, you can change the definition of where() to return a separately
27
+ packaged CA bundle.
28
+ """
29
+ import os.path
30
+
31
+ from .packages.certifi import where
32
+
33
+ if __name__ == '__main__':
34
+ print(where())
@@ -0,0 +1,85 @@
1
+ # Copyright 2022 Webull
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # -*- coding: utf-8 -*-
16
+
17
+ """
18
+ requests.compat
19
+ ~~~~~~~~~~~~~~~
20
+
21
+ This module handles import compatibility issues between Python 2 and
22
+ Python 3.
23
+ """
24
+
25
+ from .packages import chardet
26
+
27
+ import sys
28
+
29
+ # -------
30
+ # Pythons
31
+ # -------
32
+
33
+ # Syntax sugar.
34
+ _ver = sys.version_info
35
+
36
+ #: Python 2.x?
37
+ is_py2 = (_ver[0] == 2)
38
+
39
+ #: Python 3.x?
40
+ is_py3 = (_ver[0] == 3)
41
+
42
+ try:
43
+ import simplejson as json
44
+ except ImportError:
45
+ import json
46
+
47
+ # ---------
48
+ # Specifics
49
+ # ---------
50
+
51
+ if is_py2:
52
+ from urllib import (
53
+ quote, unquote, quote_plus, unquote_plus, urlencode, getproxies,
54
+ proxy_bypass, proxy_bypass_environment, getproxies_environment)
55
+ from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
56
+ from urllib2 import parse_http_list
57
+ import cookielib
58
+ from Cookie import Morsel
59
+ from StringIO import StringIO
60
+ from collections import Callable, Mapping, MutableMapping
61
+
62
+ from .packages.urllib3.packages.ordered_dict import OrderedDict
63
+
64
+ builtin_str = str
65
+ bytes = str
66
+ str = unicode
67
+ basestring = basestring
68
+ numeric_types = (int, long, float)
69
+ integer_types = (int, long)
70
+
71
+ elif is_py3:
72
+ from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
73
+ from urllib.request import parse_http_list, getproxies, proxy_bypass, proxy_bypass_environment, getproxies_environment
74
+ from http import cookiejar as cookielib
75
+ from http.cookies import Morsel
76
+ from io import StringIO
77
+ from collections import OrderedDict
78
+ from collections.abc import Callable, Mapping, MutableMapping
79
+
80
+ builtin_str = str
81
+ str = str
82
+ bytes = bytes
83
+ basestring = (str, bytes)
84
+ numeric_types = (int, float)
85
+ integer_types = (int,)