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.
- samples/__init__.py +1 -0
- samples/data/__init__.py +1 -0
- samples/data/data_client.py +57 -0
- samples/data/data_streaming_client.py +86 -0
- samples/data/data_streaming_client_async.py +101 -0
- samples/trade/__init__.py +0 -0
- samples/trade/trade_client.py +163 -0
- samples/trade/trade_client_v2.py +181 -0
- samples/trade/trade_event_client.py +47 -0
- webull/__init__.py +1 -0
- webull/core/__init__.py +12 -0
- webull/core/auth/__init__.py +0 -0
- webull/core/auth/algorithm/__init__.py +0 -0
- webull/core/auth/algorithm/sha_hmac1.py +65 -0
- webull/core/auth/algorithm/sha_hmac256.py +75 -0
- webull/core/auth/composer/__init__.py +0 -0
- webull/core/auth/composer/default_signature_composer.py +125 -0
- webull/core/auth/credentials.py +46 -0
- webull/core/auth/signers/__init__.py +0 -0
- webull/core/auth/signers/app_key_signer.py +72 -0
- webull/core/auth/signers/signer.py +48 -0
- webull/core/auth/signers/signer_factory.py +58 -0
- webull/core/cache/__init__.py +225 -0
- webull/core/client.py +410 -0
- webull/core/common/__init__.py +0 -0
- webull/core/common/api_type.py +19 -0
- webull/core/common/easy_enum.py +35 -0
- webull/core/common/region.py +7 -0
- webull/core/compat.py +85 -0
- webull/core/context/__init__.py +0 -0
- webull/core/context/request_context_holder.py +33 -0
- webull/core/data/endpoints.json +22 -0
- webull/core/data/retry_config.json +15 -0
- webull/core/endpoint/__init__.py +8 -0
- webull/core/endpoint/chained_endpoint_resolver.py +57 -0
- webull/core/endpoint/default_endpoint_resolver.py +60 -0
- webull/core/endpoint/local_config_regional_endpoint_resolver.py +77 -0
- webull/core/endpoint/resolver_endpoint_request.py +46 -0
- webull/core/endpoint/user_customized_endpoint_resolver.py +55 -0
- webull/core/exception/__init__.py +0 -0
- webull/core/exception/error_code.py +23 -0
- webull/core/exception/error_msg.py +21 -0
- webull/core/exception/exceptions.py +53 -0
- webull/core/headers.py +57 -0
- webull/core/http/__init__.py +0 -0
- webull/core/http/initializer/__init__.py +0 -0
- webull/core/http/initializer/client_initializer.py +79 -0
- webull/core/http/initializer/token/__init__.py +0 -0
- webull/core/http/initializer/token/bean/__init__.py +0 -0
- webull/core/http/initializer/token/bean/access_token.py +40 -0
- webull/core/http/initializer/token/bean/check_token_request.py +44 -0
- webull/core/http/initializer/token/bean/create_token_request.py +45 -0
- webull/core/http/initializer/token/bean/refresh_token_request.py +44 -0
- webull/core/http/initializer/token/token_manager.py +208 -0
- webull/core/http/initializer/token/token_operation.py +72 -0
- webull/core/http/method_type.py +43 -0
- webull/core/http/protocol_type.py +43 -0
- webull/core/http/request.py +121 -0
- webull/core/http/response.py +166 -0
- webull/core/request.py +278 -0
- webull/core/retry/__init__.py +0 -0
- webull/core/retry/backoff_strategy.py +102 -0
- webull/core/retry/retry_condition.py +214 -0
- webull/core/retry/retry_policy.py +63 -0
- webull/core/retry/retry_policy_context.py +51 -0
- webull/core/utils/__init__.py +0 -0
- webull/core/utils/common.py +62 -0
- webull/core/utils/data.py +25 -0
- webull/core/utils/desensitize.py +33 -0
- webull/core/utils/validation.py +49 -0
- webull/core/vendored/__init__.py +0 -0
- webull/core/vendored/requests/__init__.py +94 -0
- webull/core/vendored/requests/__version__.py +28 -0
- webull/core/vendored/requests/_internal_utils.py +56 -0
- webull/core/vendored/requests/adapters.py +539 -0
- webull/core/vendored/requests/api.py +166 -0
- webull/core/vendored/requests/auth.py +307 -0
- webull/core/vendored/requests/certs.py +34 -0
- webull/core/vendored/requests/compat.py +85 -0
- webull/core/vendored/requests/cookies.py +555 -0
- webull/core/vendored/requests/exceptions.py +136 -0
- webull/core/vendored/requests/help.py +134 -0
- webull/core/vendored/requests/hooks.py +48 -0
- webull/core/vendored/requests/models.py +960 -0
- webull/core/vendored/requests/packages/__init__.py +17 -0
- webull/core/vendored/requests/packages/certifi/__init__.py +17 -0
- webull/core/vendored/requests/packages/certifi/__main__.py +16 -0
- webull/core/vendored/requests/packages/certifi/cacert.pem +4433 -0
- webull/core/vendored/requests/packages/certifi/core.py +51 -0
- webull/core/vendored/requests/packages/chardet/__init__.py +53 -0
- webull/core/vendored/requests/packages/chardet/big5freq.py +400 -0
- webull/core/vendored/requests/packages/chardet/big5prober.py +61 -0
- webull/core/vendored/requests/packages/chardet/chardistribution.py +247 -0
- webull/core/vendored/requests/packages/chardet/charsetgroupprober.py +120 -0
- webull/core/vendored/requests/packages/chardet/charsetprober.py +159 -0
- webull/core/vendored/requests/packages/chardet/cli/__init__.py +1 -0
- webull/core/vendored/requests/packages/chardet/cli/chardetect.py +99 -0
- webull/core/vendored/requests/packages/chardet/codingstatemachine.py +102 -0
- webull/core/vendored/requests/packages/chardet/compat.py +48 -0
- webull/core/vendored/requests/packages/chardet/cp949prober.py +63 -0
- webull/core/vendored/requests/packages/chardet/enums.py +90 -0
- webull/core/vendored/requests/packages/chardet/escprober.py +115 -0
- webull/core/vendored/requests/packages/chardet/escsm.py +260 -0
- webull/core/vendored/requests/packages/chardet/eucjpprober.py +106 -0
- webull/core/vendored/requests/packages/chardet/euckrfreq.py +209 -0
- webull/core/vendored/requests/packages/chardet/euckrprober.py +61 -0
- webull/core/vendored/requests/packages/chardet/euctwfreq.py +401 -0
- webull/core/vendored/requests/packages/chardet/euctwprober.py +60 -0
- webull/core/vendored/requests/packages/chardet/gb2312freq.py +297 -0
- webull/core/vendored/requests/packages/chardet/gb2312prober.py +60 -0
- webull/core/vendored/requests/packages/chardet/hebrewprober.py +306 -0
- webull/core/vendored/requests/packages/chardet/jisfreq.py +339 -0
- webull/core/vendored/requests/packages/chardet/jpcntx.py +247 -0
- webull/core/vendored/requests/packages/chardet/langbulgarianmodel.py +242 -0
- webull/core/vendored/requests/packages/chardet/langcyrillicmodel.py +347 -0
- webull/core/vendored/requests/packages/chardet/langgreekmodel.py +239 -0
- webull/core/vendored/requests/packages/chardet/langhebrewmodel.py +214 -0
- webull/core/vendored/requests/packages/chardet/langhungarianmodel.py +239 -0
- webull/core/vendored/requests/packages/chardet/langthaimodel.py +213 -0
- webull/core/vendored/requests/packages/chardet/langturkishmodel.py +207 -0
- webull/core/vendored/requests/packages/chardet/latin1prober.py +159 -0
- webull/core/vendored/requests/packages/chardet/mbcharsetprober.py +105 -0
- webull/core/vendored/requests/packages/chardet/mbcsgroupprober.py +68 -0
- webull/core/vendored/requests/packages/chardet/mbcssm.py +586 -0
- webull/core/vendored/requests/packages/chardet/sbcharsetprober.py +146 -0
- webull/core/vendored/requests/packages/chardet/sbcsgroupprober.py +87 -0
- webull/core/vendored/requests/packages/chardet/sjisprober.py +106 -0
- webull/core/vendored/requests/packages/chardet/universaldetector.py +300 -0
- webull/core/vendored/requests/packages/chardet/utf8prober.py +96 -0
- webull/core/vendored/requests/packages/chardet/version.py +23 -0
- webull/core/vendored/requests/packages/urllib3/__init__.py +114 -0
- webull/core/vendored/requests/packages/urllib3/_collections.py +346 -0
- webull/core/vendored/requests/packages/urllib3/connection.py +405 -0
- webull/core/vendored/requests/packages/urllib3/connectionpool.py +910 -0
- webull/core/vendored/requests/packages/urllib3/contrib/__init__.py +0 -0
- webull/core/vendored/requests/packages/urllib3/contrib/_appengine_environ.py +44 -0
- webull/core/vendored/requests/packages/urllib3/contrib/_securetransport/__init__.py +0 -0
- webull/core/vendored/requests/packages/urllib3/contrib/_securetransport/bindings.py +607 -0
- webull/core/vendored/requests/packages/urllib3/contrib/_securetransport/low_level.py +360 -0
- webull/core/vendored/requests/packages/urllib3/contrib/appengine.py +303 -0
- webull/core/vendored/requests/packages/urllib3/contrib/ntlmpool.py +125 -0
- webull/core/vendored/requests/packages/urllib3/contrib/pyopenssl.py +484 -0
- webull/core/vendored/requests/packages/urllib3/contrib/securetransport.py +818 -0
- webull/core/vendored/requests/packages/urllib3/contrib/socks.py +206 -0
- webull/core/vendored/requests/packages/urllib3/exceptions.py +260 -0
- webull/core/vendored/requests/packages/urllib3/fields.py +192 -0
- webull/core/vendored/requests/packages/urllib3/filepost.py +112 -0
- webull/core/vendored/requests/packages/urllib3/packages/__init__.py +19 -0
- webull/core/vendored/requests/packages/urllib3/packages/backports/__init__.py +0 -0
- webull/core/vendored/requests/packages/urllib3/packages/backports/makefile.py +67 -0
- webull/core/vendored/requests/packages/urllib3/packages/ordered_dict.py +273 -0
- webull/core/vendored/requests/packages/urllib3/packages/six.py +882 -0
- webull/core/vendored/requests/packages/urllib3/packages/socks.py +887 -0
- webull/core/vendored/requests/packages/urllib3/packages/ssl_match_hostname/__init__.py +19 -0
- webull/core/vendored/requests/packages/urllib3/packages/ssl_match_hostname/_implementation.py +170 -0
- webull/core/vendored/requests/packages/urllib3/poolmanager.py +467 -0
- webull/core/vendored/requests/packages/urllib3/request.py +164 -0
- webull/core/vendored/requests/packages/urllib3/response.py +721 -0
- webull/core/vendored/requests/packages/urllib3/util/__init__.py +68 -0
- webull/core/vendored/requests/packages/urllib3/util/connection.py +148 -0
- webull/core/vendored/requests/packages/urllib3/util/queue.py +35 -0
- webull/core/vendored/requests/packages/urllib3/util/request.py +132 -0
- webull/core/vendored/requests/packages/urllib3/util/response.py +101 -0
- webull/core/vendored/requests/packages/urllib3/util/retry.py +426 -0
- webull/core/vendored/requests/packages/urllib3/util/selectors.py +601 -0
- webull/core/vendored/requests/packages/urllib3/util/ssl_.py +396 -0
- webull/core/vendored/requests/packages/urllib3/util/timeout.py +256 -0
- webull/core/vendored/requests/packages/urllib3/util/url.py +252 -0
- webull/core/vendored/requests/packages/urllib3/util/wait.py +164 -0
- webull/core/vendored/requests/packages.py +28 -0
- webull/core/vendored/requests/sessions.py +750 -0
- webull/core/vendored/requests/status_codes.py +105 -0
- webull/core/vendored/requests/structures.py +119 -0
- webull/core/vendored/requests/utils.py +916 -0
- webull/core/vendored/six.py +905 -0
- webull/data/__init__.py +3 -0
- webull/data/common/__init__.py +0 -0
- webull/data/common/category.py +26 -0
- webull/data/common/connect_ack.py +29 -0
- webull/data/common/direction.py +25 -0
- webull/data/common/exchange_code.py +33 -0
- webull/data/common/exercise_style.py +22 -0
- webull/data/common/expiration_cycle.py +26 -0
- webull/data/common/instrument_status.py +23 -0
- webull/data/common/option_type.py +20 -0
- webull/data/common/subscribe_type.py +22 -0
- webull/data/common/timespan.py +29 -0
- webull/data/data_client.py +35 -0
- webull/data/data_streaming_client.py +89 -0
- webull/data/internal/__init__.py +0 -0
- webull/data/internal/default_retry_policy.py +84 -0
- webull/data/internal/exceptions.py +60 -0
- webull/data/internal/quotes_client.py +314 -0
- webull/data/internal/quotes_decoder.py +40 -0
- webull/data/internal/quotes_payload_decoder.py +35 -0
- webull/data/internal/quotes_topic.py +36 -0
- webull/data/quotes/__init__.py +0 -0
- webull/data/quotes/instrument.py +33 -0
- webull/data/quotes/market_data.py +187 -0
- webull/data/quotes/market_streaming_data.py +66 -0
- webull/data/quotes/subscribe/__init__.py +0 -0
- webull/data/quotes/subscribe/ask_bid_result.py +49 -0
- webull/data/quotes/subscribe/basic_result.py +45 -0
- webull/data/quotes/subscribe/broker_result.py +33 -0
- webull/data/quotes/subscribe/message_pb2.py +37 -0
- webull/data/quotes/subscribe/order_result.py +30 -0
- webull/data/quotes/subscribe/payload_type.py +19 -0
- webull/data/quotes/subscribe/quote_decoder.py +28 -0
- webull/data/quotes/subscribe/quote_result.py +47 -0
- webull/data/quotes/subscribe/snapshot_decoder.py +30 -0
- webull/data/quotes/subscribe/snapshot_result.py +69 -0
- webull/data/quotes/subscribe/tick_decoder.py +29 -0
- webull/data/quotes/subscribe/tick_result.py +47 -0
- webull/data/request/__init__.py +0 -0
- webull/data/request/get_batch_historical_bars_request.py +43 -0
- webull/data/request/get_corp_action_request.py +47 -0
- webull/data/request/get_eod_bars_request.py +32 -0
- webull/data/request/get_historical_bars_request.py +43 -0
- webull/data/request/get_instruments_request.py +30 -0
- webull/data/request/get_quotes_request.py +35 -0
- webull/data/request/get_snapshot_request.py +38 -0
- webull/data/request/get_tick_request.py +37 -0
- webull/data/request/subscribe_request.py +43 -0
- webull/data/request/unsubscribe_request.py +42 -0
- webull/trade/__init__.py +2 -0
- webull/trade/common/__init__.py +0 -0
- webull/trade/common/account_type.py +22 -0
- webull/trade/common/category.py +29 -0
- webull/trade/common/combo_ticker_type.py +23 -0
- webull/trade/common/combo_type.py +31 -0
- webull/trade/common/currency.py +24 -0
- webull/trade/common/forbid_reason.py +27 -0
- webull/trade/common/instrument_type.py +27 -0
- webull/trade/common/markets.py +27 -0
- webull/trade/common/order_entrust_type.py +21 -0
- webull/trade/common/order_side.py +23 -0
- webull/trade/common/order_status.py +25 -0
- webull/trade/common/order_tif.py +24 -0
- webull/trade/common/order_type.py +30 -0
- webull/trade/common/trade_policy.py +22 -0
- webull/trade/common/trading_date_type.py +24 -0
- webull/trade/common/trailing_type.py +23 -0
- webull/trade/events/__init__.py +0 -0
- webull/trade/events/default_retry_policy.py +64 -0
- webull/trade/events/events_pb2.py +43 -0
- webull/trade/events/events_pb2_grpc.py +66 -0
- webull/trade/events/signature_composer.py +61 -0
- webull/trade/events/types.py +21 -0
- webull/trade/request/__init__.py +0 -0
- webull/trade/request/cancel_order_request.py +28 -0
- webull/trade/request/get_account_balance_request.py +28 -0
- webull/trade/request/get_account_positions_request.py +30 -0
- webull/trade/request/get_account_profile_request.py +26 -0
- webull/trade/request/get_app_subscriptions.py +28 -0
- webull/trade/request/get_open_orders_request.py +30 -0
- webull/trade/request/get_order_detail_request.py +27 -0
- webull/trade/request/get_today_orders_request.py +31 -0
- webull/trade/request/get_trade_calendar_request.py +30 -0
- webull/trade/request/get_trade_instrument_detail_request.py +24 -0
- webull/trade/request/get_trade_security_detail_request.py +42 -0
- webull/trade/request/get_tradeable_instruments_request.py +27 -0
- webull/trade/request/palce_order_request.py +91 -0
- webull/trade/request/place_order_request_v2.py +58 -0
- webull/trade/request/replace_order_request.py +73 -0
- webull/trade/request/replace_order_request_v2.py +38 -0
- webull/trade/request/v2/__init__.py +0 -0
- webull/trade/request/v2/cancel_option_request.py +28 -0
- webull/trade/request/v2/cancel_order_request.py +28 -0
- webull/trade/request/v2/get_account_balance_request.py +28 -0
- webull/trade/request/v2/get_account_list.py +23 -0
- webull/trade/request/v2/get_account_positions_request.py +24 -0
- webull/trade/request/v2/get_order_detail_request.py +26 -0
- webull/trade/request/v2/get_order_history_request.py +35 -0
- webull/trade/request/v2/palce_order_request.py +87 -0
- webull/trade/request/v2/place_option_request.py +64 -0
- webull/trade/request/v2/preview_option_request.py +28 -0
- webull/trade/request/v2/preview_order_request.py +59 -0
- webull/trade/request/v2/replace_option_request.py +28 -0
- webull/trade/request/v2/replace_order_request.py +57 -0
- webull/trade/trade/__init__.py +0 -0
- webull/trade/trade/account_info.py +83 -0
- webull/trade/trade/order_operation.py +246 -0
- webull/trade/trade/trade_calendar.py +37 -0
- webull/trade/trade/trade_instrument.py +72 -0
- webull/trade/trade/v2/__init__.py +0 -0
- webull/trade/trade/v2/account_info_v2.py +55 -0
- webull/trade/trade/v2/order_operation_v2.py +206 -0
- webull/trade/trade_client.py +43 -0
- webull/trade/trade_events_client.py +233 -0
- webull_openapi_python_sdk-1.0.0.dist-info/METADATA +28 -0
- webull_openapi_python_sdk-1.0.0.dist-info/RECORD +295 -0
- webull_openapi_python_sdk-1.0.0.dist-info/WHEEL +5 -0
- webull_openapi_python_sdk-1.0.0.dist-info/licenses/LICENSE +202 -0
- webull_openapi_python_sdk-1.0.0.dist-info/licenses/NOTICE +56 -0
- webull_openapi_python_sdk-1.0.0.dist-info/top_level.txt +2 -0
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TradeableInstrumentRequest(ApiRequest):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
ApiRequest.__init__(self, "/trade/instrument/tradable/list", version='v2', method="GET", query_params={})
|
|
22
|
+
|
|
23
|
+
def set_last_instrument_id(self, last_security_id):
|
|
24
|
+
self.add_query_param("last_security_id", last_security_id)
|
|
25
|
+
|
|
26
|
+
def set_page_size(self, page_size):
|
|
27
|
+
self.add_query_param("page_size", page_size)
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
import inspect
|
|
17
|
+
import json
|
|
18
|
+
|
|
19
|
+
from webull.core.context.request_context_holder import RequestContextHolder
|
|
20
|
+
from webull.core.request import ApiRequest
|
|
21
|
+
|
|
22
|
+
class PlaceOrderRequest(ApiRequest):
|
|
23
|
+
def __init__(self):
|
|
24
|
+
ApiRequest.__init__(self, "/trade/order/place", version='v2', method="POST", body_params={})
|
|
25
|
+
self._stock_order = {}
|
|
26
|
+
self.add_body_params("stock_order", self._stock_order)
|
|
27
|
+
|
|
28
|
+
def add_stock_order_params(self, k, v):
|
|
29
|
+
self._stock_order[k] = v
|
|
30
|
+
|
|
31
|
+
def set_category(self, category):
|
|
32
|
+
self.add_body_params("category", category)
|
|
33
|
+
|
|
34
|
+
def set_account_id(self, account_id):
|
|
35
|
+
self.add_body_params("account_id", account_id)
|
|
36
|
+
|
|
37
|
+
def set_client_order_id(self, client_order_id):
|
|
38
|
+
self.add_stock_order_params("client_order_id", client_order_id)
|
|
39
|
+
|
|
40
|
+
def set_side(self, side):
|
|
41
|
+
self.add_stock_order_params("side", side)
|
|
42
|
+
|
|
43
|
+
def set_tif(self, tif):
|
|
44
|
+
self.add_stock_order_params("tif", tif)
|
|
45
|
+
|
|
46
|
+
def set_extended_hours_trading(self, extended_hours_trading):
|
|
47
|
+
self.add_stock_order_params("extended_hours_trading", extended_hours_trading)
|
|
48
|
+
|
|
49
|
+
def set_instrument_id(self, instrument_id):
|
|
50
|
+
self.add_stock_order_params("instrument_id", instrument_id)
|
|
51
|
+
|
|
52
|
+
def set_order_type(self, order_type):
|
|
53
|
+
self.add_stock_order_params("order_type", order_type)
|
|
54
|
+
|
|
55
|
+
def set_limit_price(self, limit_price):
|
|
56
|
+
self.add_stock_order_params("limit_price", limit_price)
|
|
57
|
+
|
|
58
|
+
def set_qty(self, quantity):
|
|
59
|
+
self.add_stock_order_params("qty", quantity)
|
|
60
|
+
|
|
61
|
+
def set_stop_price(self, stop_price):
|
|
62
|
+
self.add_stock_order_params("stop_price", stop_price)
|
|
63
|
+
|
|
64
|
+
def set_trailing_type(self, trailing_type):
|
|
65
|
+
self.add_stock_order_params("trailing_type", trailing_type)
|
|
66
|
+
|
|
67
|
+
def set_trailing_stop_step(self, trailing_stop_step):
|
|
68
|
+
self.add_stock_order_params("trailing_stop_step", trailing_stop_step)
|
|
69
|
+
|
|
70
|
+
def set_stock_order(self, client_order_id, instrument_id, qty, side, tif, extended_hours_trading,
|
|
71
|
+
order_type, limit_price, stop_price, trailing_type,trailing_stop_step):
|
|
72
|
+
self._stock_order.update({k: v for k, v in locals().items() if v is not None and k != 'self'})
|
|
73
|
+
|
|
74
|
+
def add_custom_headers_from_context(self):
|
|
75
|
+
try:
|
|
76
|
+
headers_map = RequestContextHolder.get()
|
|
77
|
+
if not headers_map:
|
|
78
|
+
return
|
|
79
|
+
for key, value in headers_map.items():
|
|
80
|
+
self.add_header(key, value)
|
|
81
|
+
finally:
|
|
82
|
+
RequestContextHolder.clear()
|
|
83
|
+
|
|
84
|
+
def add_custom_headers(self, headers_map):
|
|
85
|
+
if not headers_map:
|
|
86
|
+
return
|
|
87
|
+
for key, value in headers_map.items():
|
|
88
|
+
self.add_header(key, value)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
from webull.core.context.request_context_holder import RequestContextHolder
|
|
18
|
+
from webull.core.request import ApiRequest
|
|
19
|
+
|
|
20
|
+
class PlaceOrderRequestV2(ApiRequest):
|
|
21
|
+
def __init__(self):
|
|
22
|
+
ApiRequest.__init__(self, "/trade/order/place", version='v2', method="POST", body_params={})
|
|
23
|
+
self._stock_order = {}
|
|
24
|
+
self.add_body_params("stock_order", self._stock_order)
|
|
25
|
+
|
|
26
|
+
def add_stock_order_params(self, k, v):
|
|
27
|
+
self._stock_order[k] = v
|
|
28
|
+
|
|
29
|
+
def set_account_id(self, account_id):
|
|
30
|
+
self.add_body_params("account_id", account_id)
|
|
31
|
+
|
|
32
|
+
def set_close_contracts(self, close_contracts):
|
|
33
|
+
if isinstance(close_contracts, list) and all(isinstance(item, dict) for item in close_contracts):
|
|
34
|
+
self.add_stock_order_params("close_contracts", close_contracts)
|
|
35
|
+
|
|
36
|
+
def set_stock_order(self, stock_order):
|
|
37
|
+
self._stock_order.update({k: v for k, v in stock_order.items() if v is not None and k != 'self'})
|
|
38
|
+
if 'close_contracts' in stock_order and stock_order['close_contracts'] is not None:
|
|
39
|
+
self.set_close_contracts(stock_order['close_contracts'])
|
|
40
|
+
|
|
41
|
+
def add_custom_headers_from_context(self):
|
|
42
|
+
try:
|
|
43
|
+
headers_map = RequestContextHolder.get()
|
|
44
|
+
if not headers_map:
|
|
45
|
+
return
|
|
46
|
+
for key, value in headers_map.items():
|
|
47
|
+
self.add_header(key, value)
|
|
48
|
+
finally:
|
|
49
|
+
RequestContextHolder.clear()
|
|
50
|
+
|
|
51
|
+
def add_custom_headers(self, headers_map):
|
|
52
|
+
if not headers_map:
|
|
53
|
+
return
|
|
54
|
+
for key, value in headers_map.items():
|
|
55
|
+
self.add_header(key, value)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ReplaceOrderRequest(ApiRequest):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
ApiRequest.__init__(self, "/trade/order/replace", version='v2', method="POST", body_params={})
|
|
22
|
+
self._stock_order = {}
|
|
23
|
+
self.add_body_params("stock_order", self._stock_order)
|
|
24
|
+
|
|
25
|
+
def add_stock_order_params(self, k, v):
|
|
26
|
+
self._stock_order[k] = v
|
|
27
|
+
|
|
28
|
+
def set_account_id(self, account_id):
|
|
29
|
+
self.add_body_params("account_id", account_id)
|
|
30
|
+
|
|
31
|
+
def set_client_order_id(self, client_order_id):
|
|
32
|
+
self.add_stock_order_params("client_order_id", client_order_id)
|
|
33
|
+
|
|
34
|
+
def set_side(self, side):
|
|
35
|
+
self.add_stock_order_params("side", side)
|
|
36
|
+
|
|
37
|
+
def set_tif(self, tif):
|
|
38
|
+
self.add_stock_order_params('tif', tif)
|
|
39
|
+
|
|
40
|
+
def set_extended_hours_trading(self, extended_hours_trading):
|
|
41
|
+
self.add_stock_order_params("extended_hours_trading", extended_hours_trading)
|
|
42
|
+
|
|
43
|
+
def set_instrument_id(self, instrument_id):
|
|
44
|
+
self.add_stock_order_params("instrument_id", instrument_id)
|
|
45
|
+
|
|
46
|
+
def set_order_type(self, order_type):
|
|
47
|
+
self.add_stock_order_params("order_type", order_type)
|
|
48
|
+
|
|
49
|
+
def set_limit_price(self, limit_price):
|
|
50
|
+
self.add_stock_order_params("limit_price", limit_price)
|
|
51
|
+
|
|
52
|
+
def set_qty(self, qty):
|
|
53
|
+
self.add_stock_order_params("qty", qty)
|
|
54
|
+
|
|
55
|
+
def set_stop_price(self, stop_price):
|
|
56
|
+
self.add_stock_order_params("stop_price", stop_price)
|
|
57
|
+
|
|
58
|
+
def set_trailing_type(self, trailing_type):
|
|
59
|
+
self.add_stock_order_params("trailing_type", trailing_type)
|
|
60
|
+
|
|
61
|
+
def set_trailing_stop_step(self, trailing_stop_step):
|
|
62
|
+
self.add_stock_order_params("trailing_stop_step", trailing_stop_step)
|
|
63
|
+
|
|
64
|
+
def set_stock_order(self, client_order_id, instrument_id, qty, order_type, extended_hours_trading, side, tif,
|
|
65
|
+
limit_price, stop_price, trailing_type, trailing_stop_step):
|
|
66
|
+
self._stock_order.update({k: v for k, v in locals().items() if v is not None and k != 'self'})
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ReplaceOrderRequestV2(ApiRequest):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
ApiRequest.__init__(self, "/trade/order/replace", version='v2', method="POST", body_params={})
|
|
22
|
+
self._stock_order = {}
|
|
23
|
+
self.add_body_params("stock_order", self._stock_order)
|
|
24
|
+
|
|
25
|
+
def add_stock_order_params(self, k, v):
|
|
26
|
+
self._stock_order[k] = v
|
|
27
|
+
|
|
28
|
+
def set_account_id(self, account_id):
|
|
29
|
+
self.add_body_params("account_id", account_id)
|
|
30
|
+
|
|
31
|
+
def set_close_contracts(self, close_contracts):
|
|
32
|
+
if isinstance(close_contracts, list) and all(isinstance(item, dict) for item in close_contracts):
|
|
33
|
+
self.add_stock_order_params("close_contracts", close_contracts)
|
|
34
|
+
|
|
35
|
+
def set_stock_order(self, stock_order):
|
|
36
|
+
self._stock_order.update({k: v for k, v in stock_order.items() if v is not None and k != 'self'})
|
|
37
|
+
if 'close_contracts' in stock_order and stock_order['close_contracts'] is not None:
|
|
38
|
+
self.set_close_contracts(stock_order['close_contracts'])
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class CancelOptionRequest(ApiRequest):
|
|
21
|
+
def __init__(self):
|
|
22
|
+
super().__init__("/openapi/account/orders/option/cancel", version='v2', method="POST", body_params={})
|
|
23
|
+
|
|
24
|
+
def set_client_order_id(self, client_order_id):
|
|
25
|
+
self.add_body_params("client_order_id", client_order_id)
|
|
26
|
+
|
|
27
|
+
def set_account_id(self, account_id):
|
|
28
|
+
self.add_query_param("account_id", account_id)
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CancelOrderRequest(ApiRequest):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
ApiRequest.__init__(self, "/openapi/account/orders/cancel", version='v2', method="POST", body_params={})
|
|
22
|
+
|
|
23
|
+
def set_account_id(self, account_id):
|
|
24
|
+
self.add_query_param("account_id", account_id)
|
|
25
|
+
|
|
26
|
+
def set_client_order_id(self, client_order_id):
|
|
27
|
+
self.add_body_params("client_order_id", client_order_id)
|
|
28
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AccountBalanceRequest(ApiRequest):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
ApiRequest.__init__(self, "/openapi/account/balance", version='v2', method="GET", query_params={})
|
|
22
|
+
|
|
23
|
+
def set_account_id(self, account_id):
|
|
24
|
+
self.add_query_param("account_id", account_id)
|
|
25
|
+
|
|
26
|
+
def set_total_asset_currency(self, total_asset_currency="HKD"):
|
|
27
|
+
self.add_query_param("total_asset_currency", total_asset_currency)
|
|
28
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class GetAccountList(ApiRequest):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
ApiRequest.__init__(self, "/openapi/account/list", version='v2', method="GET", query_params={})
|
|
22
|
+
|
|
23
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class AccountPositionsRequest(ApiRequest):
|
|
20
|
+
def __init__(self):
|
|
21
|
+
ApiRequest.__init__(self, "/openapi/account/positions", version='v2', method="GET", query_params={})
|
|
22
|
+
|
|
23
|
+
def set_account_id(self, account_id):
|
|
24
|
+
self.add_query_param("account_id", account_id)
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class OrderDetailRequest(ApiRequest):
|
|
19
|
+
def __init__(self):
|
|
20
|
+
ApiRequest.__init__(self, "/openapi/account/orders/detail", version='v2', method="GET", query_params={})
|
|
21
|
+
|
|
22
|
+
def set_account_id(self, account_id):
|
|
23
|
+
self.add_query_param("account_id", account_id)
|
|
24
|
+
|
|
25
|
+
def set_client_order_id(self, client_order_id):
|
|
26
|
+
self.add_query_param("client_order_id", client_order_id)
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class OrderHistoryRequest(ApiRequest):
|
|
19
|
+
def __init__(self):
|
|
20
|
+
ApiRequest.__init__(self, "/openapi/account/orders/history", version='v2', method="GET", query_params={})
|
|
21
|
+
|
|
22
|
+
def set_account_id(self, account_id):
|
|
23
|
+
self.add_query_param("account_id", account_id)
|
|
24
|
+
|
|
25
|
+
def set_page_size(self, page_size):
|
|
26
|
+
self.add_query_param("page_size", page_size)
|
|
27
|
+
|
|
28
|
+
def set_start_date(self, start_date):
|
|
29
|
+
self.add_query_param("start_date", start_date)
|
|
30
|
+
|
|
31
|
+
def set_end_date(self, end_date):
|
|
32
|
+
self.add_query_param("end_date", end_date)
|
|
33
|
+
|
|
34
|
+
def set_last_client_order_id(self, last_client_order_id):
|
|
35
|
+
self.add_query_param("last_client_order_id", last_client_order_id)
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
import json
|
|
15
|
+
# coding=utf-8
|
|
16
|
+
from typing import List
|
|
17
|
+
|
|
18
|
+
from webull.core.context.request_context_holder import RequestContextHolder
|
|
19
|
+
from webull.core.request import ApiRequest
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class CloseContract:
|
|
23
|
+
def __init__(self, contract_id: str, quantity: str):
|
|
24
|
+
self.contract_id = contract_id
|
|
25
|
+
self.quantity = quantity
|
|
26
|
+
|
|
27
|
+
def to_dict(self):
|
|
28
|
+
return {
|
|
29
|
+
"contract_id": self.contract_id,
|
|
30
|
+
"quantity": self.quantity
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class PlaceOrderRequest(ApiRequest):
|
|
34
|
+
def __init__(self):
|
|
35
|
+
super().__init__("/openapi/account/orders/place", version='v2', method="POST", body_params={})
|
|
36
|
+
self._new_orders = []
|
|
37
|
+
self._current_order = {}
|
|
38
|
+
self.add_body_params("new_orders", self._new_orders)
|
|
39
|
+
|
|
40
|
+
def add_new_order_params(self, key, value):
|
|
41
|
+
self._current_order[key] = value
|
|
42
|
+
|
|
43
|
+
def set_account_id(self, account_id):
|
|
44
|
+
self.add_query_param("account_id", account_id)
|
|
45
|
+
|
|
46
|
+
def set_close_contracts(self, close_contracts: List[CloseContract]):
|
|
47
|
+
if not isinstance(close_contracts, list):
|
|
48
|
+
raise TypeError("close_contracts must be a list of CloseContract objects.")
|
|
49
|
+
self.add_new_order_params("close_contracts", [contract.to_dict() for contract in close_contracts])
|
|
50
|
+
|
|
51
|
+
def set_new_orders(self, current_order):
|
|
52
|
+
self._current_order.update({k: v for k, v in current_order.items() if v is not None and k != 'self'})
|
|
53
|
+
if 'close_contracts' in current_order and current_order['close_contracts'] is not None:
|
|
54
|
+
self.set_close_contracts(current_order['close_contracts'])
|
|
55
|
+
|
|
56
|
+
def finalize_order(self):
|
|
57
|
+
if self._current_order:
|
|
58
|
+
self._new_orders.append(self._current_order)
|
|
59
|
+
self._current_order = {}
|
|
60
|
+
else:
|
|
61
|
+
raise ValueError("No order fields have been set.")
|
|
62
|
+
|
|
63
|
+
def add_custom_headers_from_order(self, new_orders):
|
|
64
|
+
if not new_orders:
|
|
65
|
+
return
|
|
66
|
+
|
|
67
|
+
if not isinstance(new_orders, (list, tuple)):
|
|
68
|
+
market = new_orders.get("market")
|
|
69
|
+
category = market + "_" + "STOCK"
|
|
70
|
+
if category is not None:
|
|
71
|
+
self.add_header("category", category)
|
|
72
|
+
|
|
73
|
+
def add_custom_headers_from_context(self):
|
|
74
|
+
try:
|
|
75
|
+
headers_map = RequestContextHolder.get()
|
|
76
|
+
if not headers_map:
|
|
77
|
+
return
|
|
78
|
+
for key, value in headers_map.items():
|
|
79
|
+
self.add_header(key, value)
|
|
80
|
+
finally:
|
|
81
|
+
RequestContextHolder.clear()
|
|
82
|
+
|
|
83
|
+
def add_custom_headers(self, headers_map):
|
|
84
|
+
if not headers_map:
|
|
85
|
+
return
|
|
86
|
+
for key, value in headers_map.items():
|
|
87
|
+
self.add_header(key, value)
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
import json
|
|
15
|
+
|
|
16
|
+
from webull.core.context.request_context_holder import RequestContextHolder
|
|
17
|
+
# coding=utf-8
|
|
18
|
+
|
|
19
|
+
from webull.core.request import ApiRequest
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class PlaceOptionRequest(ApiRequest):
|
|
23
|
+
def __init__(self):
|
|
24
|
+
super().__init__("/openapi/account/orders/option/place", version='v2', method="POST", body_params={})
|
|
25
|
+
|
|
26
|
+
def set_new_orders(self, new_orders):
|
|
27
|
+
self.add_body_params("new_orders", new_orders)
|
|
28
|
+
|
|
29
|
+
def set_account_id(self, account_id):
|
|
30
|
+
self.add_query_param("account_id", account_id)
|
|
31
|
+
|
|
32
|
+
def add_custom_headers_from_order(self, new_orders):
|
|
33
|
+
|
|
34
|
+
if not new_orders:
|
|
35
|
+
return
|
|
36
|
+
|
|
37
|
+
if isinstance(new_orders, list) and new_orders[0]:
|
|
38
|
+
first_order = new_orders[0]
|
|
39
|
+
orders_list = first_order.get("orders", [])
|
|
40
|
+
if isinstance(orders_list, list):
|
|
41
|
+
for sub_order in orders_list:
|
|
42
|
+
if (sub_order and isinstance(sub_order, dict)
|
|
43
|
+
and sub_order.get("instrument_type") == "OPTION"):
|
|
44
|
+
instrument_type = sub_order.get("instrument_type")
|
|
45
|
+
market = sub_order.get("market")
|
|
46
|
+
category = market + "_" + instrument_type
|
|
47
|
+
if category is not None:
|
|
48
|
+
self.add_header("category", category)
|
|
49
|
+
|
|
50
|
+
def add_custom_headers_from_context(self):
|
|
51
|
+
try:
|
|
52
|
+
headers_map = RequestContextHolder.get()
|
|
53
|
+
if not headers_map:
|
|
54
|
+
return
|
|
55
|
+
for key, value in headers_map.items():
|
|
56
|
+
self.add_header(key, value)
|
|
57
|
+
finally:
|
|
58
|
+
RequestContextHolder.clear()
|
|
59
|
+
|
|
60
|
+
def add_custom_headers(self, headers_map):
|
|
61
|
+
if not headers_map:
|
|
62
|
+
return
|
|
63
|
+
for key, value in headers_map.items():
|
|
64
|
+
self.add_header(key, value)
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
from webull.core.request import ApiRequest
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class PreviewOptionRequest(ApiRequest):
|
|
21
|
+
def __init__(self):
|
|
22
|
+
super().__init__("/openapi/account/orders/option/preview", version='v2', method="POST", body_params={})
|
|
23
|
+
|
|
24
|
+
def set_new_orders(self, new_orders):
|
|
25
|
+
self.add_body_params("new_orders", new_orders)
|
|
26
|
+
|
|
27
|
+
def set_account_id(self, account_id):
|
|
28
|
+
self.add_query_param("account_id", account_id)
|