Skip to content

Commit d3193b4

Browse files
author
方佳
committed
Merge branch 'main_merge_260808' into 'main'
[20260808日常发布]: 【Market Data API】Instrument接口优化(增加标的sub_category) (link) See merge request webull/webull-openapi-python-sdk!40
2 parents 3aea548 + fa7f404 commit d3193b4

11 files changed

Lines changed: 174 additions & 7 deletions

File tree

‎samples/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.16'
1+
__version__ = '2.0.17'

‎samples/trade/trade_client_v3.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@
6060
# ============================================================
6161

6262
# normal equity order
63+
# normal equity order
64+
# leg_in_or_out: Currently, only the US market is supported.
65+
# Specifies whether this order is adding or removing a leg from an existing position.
66+
# LEG_IN: Add this leg to an existing position to form a multi-leg strategy.
67+
# LEG_OUT: Close this leg from an existing multi-leg strategy position.
68+
# position_id: Currently, only the US market is supported.
69+
# The unique position identifier of the target leg. Obtained from the Account Positions API.
70+
# Required when leg_in_or_out is specified.
71+
# leg_in_strategy: Currently, only the US market is supported.
72+
# The target strategy type expected after legging in. Only applicable when leg_in_or_out is LEG_IN.
73+
# (e.g., VERTICAL, CALENDAR, STRANGLE, STRADDLE, IRON_CONDOR, BUTTERFLY, CUSTOM).
6374
normal_equity_client_order_id = uuid.uuid4().hex
6475
print('client order id:', normal_equity_client_order_id)
6576
new_normal_equity_orders = [
@@ -76,6 +87,9 @@
7687
"side": "BUY",
7788
"time_in_force": "DAY",
7889
"entrust_type": "QTY",
90+
"leg_in_or_out": "LEG_IN",
91+
"position_id": "<your_position_id>",
92+
"leg_in_strategy": "VERTICAL",
7993
# Currently, only Webull JP is supported.
8094
# "account_tax_type":"GENERAL",
8195
# "margin_type": "ONE_DAY"
@@ -119,6 +133,9 @@
119133
if res.status_code == 200:
120134
print('get order detail res:', res.json())
121135

136+
res = trade_client.order_v3.get_order_executions(account_id, client_order_id= "", start_date="2026-01-20", end_date="2026-01-23")
137+
if res.status_code == 200:
138+
print('get order executions res:', res.json())
122139

123140

124141
# combo equity order
@@ -257,6 +274,15 @@
257274

258275
# normal option order
259276
# position_intent: Currently, only the US market is supported, and only options orders are allowed.
277+
# leg_in_or_out: Currently, only the US market is supported.
278+
# Specifies whether this leg is being legged into or legged out of an existing position.
279+
# LEG_IN: Add this leg to an existing position.
280+
# LEG_OUT: Close this leg from an existing multi-leg strategy position.
281+
# position_id: Currently, only the US market is supported.
282+
# The unique position identifier of the target leg to be legged in or legged out. Obtained from the Account Positions API. Required when leg_in_or_out is specified.
283+
# leg_in_strategy: Currently, only the US market is supported.
284+
# The target strategy type expected after legging in. Specifies what multi-leg strategy the position should become once this leg is added. Only applicable when leg_in_or_out is LEG_IN.
285+
# (e.g., VERTICAL, CALENDAR, STRANGLE, STRADDLE, IRON_CONDOR, BUTTERFLY, CUSTOM).
260286
normal_option_client_order_id = uuid.uuid4().hex
261287
new_normal_option_orders = [
262288
{
@@ -270,6 +296,9 @@
270296
"time_in_force": "GTC",
271297
"entrust_type": "QTY",
272298
"position_intent": "BUY_TO_OPEN",
299+
"leg_in_or_out": "LEG_IN",
300+
"position_id": "<your_position_id>",
301+
"leg_in_strategy": "VERTICAL",
273302
"legs": [
274303
{
275304
"side": "BUY",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
import unittest
16+
17+
from webull.core.client import ApiClient
18+
from webull.core.exception.exceptions import ServerException
19+
from webull.core.http.initializer.client_initializer import ClientInitializer
20+
from webull.trade.request.v2.get_order_executions_request import GetOrderExecutionsRequest
21+
22+
optional_api_endpoint = "<api_endpoint>"
23+
your_app_key = "<your_app_key>"
24+
your_app_secret = "<your_app_secret>"
25+
region_id = "<region_id>"
26+
account_id = "<your_account_id>"
27+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
28+
api_client.add_endpoint(region_id, optional_api_endpoint)
29+
ClientInitializer.initializer(api_client)
30+
31+
32+
class TestGetOrderExecutions(unittest.TestCase):
33+
def test_get_order_executions(self):
34+
request = GetOrderExecutionsRequest()
35+
request.set_endpoint(optional_api_endpoint)
36+
request.set_account_id(account_id)
37+
request.set_client_order_id("")
38+
request.set_start_date("2024-01-01")
39+
request.set_end_date("2024-01-31")
40+
request.set_page_size(10)
41+
params = request.get_query_params()
42+
print(params)
43+
try:
44+
response = api_client.get_response(request)
45+
print(json.dumps(response.json(), indent=4))
46+
47+
except ServerException as se:
48+
print(se.get_error_code(), ":", se.get_error_msg())

‎webull/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.16'
1+
__version__ = '2.0.17'

‎webull/core/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '2.0.16'
1+
__version__ = '2.0.17'
22

33
import logging
44

‎webull/data/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# coding=utf-8
22

3-
__version__ = '2.0.16'
3+
__version__ = '2.0.17'

‎webull/data/quotes/instrument.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,23 @@ class Instrument:
3232
def __init__(self, api_client):
3333
self.client = api_client
3434

35-
def get_instrument(self, symbols=None, category=Category.US_STOCK.name, status=None, last_instrument_id=None,
36-
page_size=1000):
35+
def get_instrument(self, symbols=None, category=Category.US_STOCK.name, status=None, sub_category=None,
36+
last_instrument_id=None, page_size=1000):
3737
"""
3838
Query the underlying information according to the security symbol list and security type.
3939
4040
:param symbols: Securities symbol, such as: 00700,00981.
4141
:param category: Security type, enumeration.
4242
:param status: Tradable status.
43+
:param sub_category: Security sub category.
4344
:param last_instrument_id: Last instrument id for pagination.
4445
:param page_size: Page size, default 1000.
4546
"""
4647
instruments_request = GetInstrumentsRequest()
4748
instruments_request.set_symbols(symbols)
4849
instruments_request.set_category(category)
4950
instruments_request.set_status(status)
51+
instruments_request.set_sub_category(sub_category)
5052
instruments_request.set_last_instrument_id(last_instrument_id)
5153
instruments_request.set_page_size(page_size)
5254
response = self.client.get_response(instruments_request)

‎webull/data/request/get_instruments_request.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def set_status(self, status):
3333
if status:
3434
self.add_query_param("status", status)
3535

36+
def set_sub_category(self, sub_category):
37+
if sub_category:
38+
self.add_query_param("sub_category", sub_category)
39+
3640
def set_last_instrument_id(self, last_instrument_id):
3741
if last_instrument_id:
3842
self.add_query_param("last_instrument_id", last_instrument_id)

‎webull/trade/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.16'
1+
__version__ = '2.0.17'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
from webull.core.request import ApiRequest
16+
17+
18+
class GetOrderExecutionsRequest(ApiRequest):
19+
def __init__(self):
20+
ApiRequest.__init__(self, "/trading/orders/executions/list", 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)
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_execution_id(self, last_execution_id):
35+
self.add_query_param("last_execution_id", last_execution_id)
36+
37+
def set_page_size(self, page_size):
38+
self.add_query_param("page_size", page_size)

0 commit comments

Comments
 (0)