Skip to content

Commit 1cc418d

Browse files
author
方佳
committed
Merge branch 'main_merge_250116' into 'main'
[OpenAPI]: Add support for stock short selling and single-leg options See merge request webull/openapi-python-sdk!9
2 parents ce59799 + ecb1829 commit 1cc418d

File tree

25 files changed

+601
-19
lines changed

25 files changed

+601
-19
lines changed

webull-python-sdk-core/webullsdkcore/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.1.10"
1+
__version__ = "0.1.11"
22

33
import logging
44

webull-python-sdk-demos/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
LONG_DESCRIPTION = fp.read()
1616

1717
requires = [
18-
"webull-python-sdk-mdata==0.1.10",
19-
"webull-python-sdk-trade==0.1.10"
18+
"webull-python-sdk-mdata==0.1.11",
19+
"webull-python-sdk-trade==0.1.11"
2020
]
2121

2222
setup_args = {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 webullsdkcore.client import ApiClient
18+
from webullsdkcore.exception.exceptions import ServerException
19+
from webullsdktrade.request.v2.cancel_option_request import CancelOptionRequest
20+
21+
optional_api_endpoint = "<api_endpoint>"
22+
optional_api_region_id = "<api_region_id>"
23+
your_app_key = "<your_app_key>"
24+
your_app_secret = "<your_app_secret>"
25+
account_id = "<your_account_id>"
26+
api_client = ApiClient(your_app_key, your_app_secret)
27+
api_client.add_endpoint(optional_api_region_id, optional_api_endpoint)
28+
29+
client_order_id = "e1890d630d5542b48fe50d82e0d7b13f"
30+
31+
class TestOptionOperation(unittest.TestCase):
32+
def test_preview_order(self):
33+
request = CancelOptionRequest()
34+
request.set_endpoint(optional_api_endpoint)
35+
request.set_account_id(account_id)
36+
request.set_client_order_id(client_order_id)
37+
post_body = request.get_body_params()
38+
print(json.dumps(post_body, indent=4))
39+
params = request.get_query_params()
40+
print(params)
41+
42+
try:
43+
response = api_client.get_response(request)
44+
print(response.json())
45+
46+
except ServerException as se:
47+
print(se.get_error_code(), ":", se.get_error_msg())
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
import uuid
17+
18+
from webullsdkcore.client import ApiClient
19+
from webullsdkcore.exception.exceptions import ServerException
20+
from webullsdktrade.request.v2.place_option_request import PlaceOptionRequest
21+
22+
optional_api_endpoint = "<api_endpoint>"
23+
optional_api_region_id = "<api_region_id>"
24+
your_app_key = "<your_app_key>"
25+
your_app_secret = "<your_app_secret>"
26+
account_id = "<your_account_id>"
27+
api_client = ApiClient(your_app_key, your_app_secret)
28+
api_client.add_endpoint(optional_api_region_id, optional_api_endpoint)
29+
30+
client_order_id = uuid.uuid4().hex
31+
new_orders = [
32+
{
33+
"client_order_id": client_order_id,
34+
"combo_type": "NORMAL",
35+
"order_type": "LIMIT",
36+
"quantity": "1",
37+
"limit_price": "11.25",
38+
"option_strategy": "SINGLE",
39+
"side": "BUY",
40+
"time_in_force": "GTC",
41+
"entrust_type": "QTY",
42+
"orders": [
43+
{
44+
"side": "BUY",
45+
"quantity": "1",
46+
"symbol": "AAPL",
47+
"strike_price": "250.0",
48+
"init_exp_date": "2025-08-15",
49+
"instrument_type": "OPTION",
50+
"option_type": "CALL",
51+
"market": "US"
52+
}
53+
]
54+
}
55+
]
56+
57+
58+
class TestOptionOperation(unittest.TestCase):
59+
def test_preview_order(self):
60+
request = PlaceOptionRequest()
61+
request.set_endpoint(optional_api_endpoint)
62+
request.set_account_id(account_id)
63+
request.set_new_orders(new_orders)
64+
post_body = request.get_body_params()
65+
print(json.dumps(post_body, indent=4))
66+
params = request.get_query_params()
67+
print(params)
68+
69+
try:
70+
response = api_client.get_response(request)
71+
print(response.json())
72+
73+
except ServerException as se:
74+
print(se.get_error_code(), ":", se.get_error_msg())
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
import uuid
17+
18+
from webullsdkcore.client import ApiClient
19+
from webullsdkcore.exception.exceptions import ServerException
20+
from webullsdktrade.request.v2.preview_option_request import PreviewOptionRequest
21+
22+
23+
optional_api_endpoint = "<api_endpoint>"
24+
optional_api_region_id = "<api_region_id>"
25+
your_app_key = "<your_app_key>"
26+
your_app_secret = "<your_app_secret>"
27+
account_id = "<your_account_id>"
28+
api_client = ApiClient(your_app_key, your_app_secret)
29+
api_client.add_endpoint(optional_api_region_id, optional_api_endpoint)
30+
31+
client_order_id = uuid.uuid4().hex
32+
new_orders = [
33+
{
34+
"client_order_id": client_order_id,
35+
"combo_type": "NORMAL",
36+
"order_type": "LIMIT",
37+
"quantity": "1",
38+
"limit_price": "11.25",
39+
"option_strategy": "SINGLE",
40+
"side": "BUY",
41+
"time_in_force": "DAY",
42+
"entrust_type": "QTY",
43+
"orders": [
44+
{
45+
"side": "BUY",
46+
"quantity": "1",
47+
"symbol": "AAPL",
48+
"strike_price": "250.0",
49+
"init_exp_date": "2025-08-15",
50+
"instrument_type": "OPTION",
51+
"option_type": "CALL",
52+
"market": "US"
53+
}
54+
]
55+
}
56+
]
57+
58+
59+
class TestOptionOperation(unittest.TestCase):
60+
def test_preview_order(self):
61+
request = PreviewOptionRequest()
62+
request.set_endpoint(optional_api_endpoint)
63+
request.set_account_id(account_id)
64+
request.set_new_orders(new_orders)
65+
post_body = request.get_body_params()
66+
print(json.dumps(post_body, indent=4))
67+
params = request.get_query_params()
68+
print(params)
69+
70+
try:
71+
response = api_client.get_response(request)
72+
print(response.json())
73+
74+
except ServerException as se:
75+
print(se.get_error_code(), ":", se.get_error_msg())
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 webullsdkcore.client import ApiClient
18+
from webullsdkcore.exception.exceptions import ServerException
19+
from webullsdktrade.request.v2.replace_option_request import ReplaceOptionRequest
20+
21+
22+
optional_api_endpoint = "<api_endpoint>"
23+
optional_api_region_id = "<api_region_id>"
24+
your_app_key = "<your_app_key>"
25+
your_app_secret = "<your_app_secret>"
26+
account_id = "<your_account_id>"
27+
api_client = ApiClient(your_app_key, your_app_secret)
28+
api_client.add_endpoint(optional_api_region_id, optional_api_endpoint)
29+
30+
client_order_id = "e1890d630d5542b48fe50d82e0d7b13f"
31+
modify_orders = [
32+
{
33+
"client_order_id": client_order_id,
34+
"quantity": "2",
35+
"limit_price": "11.3",
36+
"orders": [
37+
{
38+
"client_order_id": client_order_id,
39+
"quantity": "2"
40+
}
41+
]
42+
}
43+
]
44+
45+
46+
class TestOptionOperation(unittest.TestCase):
47+
def test_preview_order(self):
48+
request = ReplaceOptionRequest()
49+
request.set_endpoint(optional_api_endpoint)
50+
request.set_account_id(account_id)
51+
request.set_modify_orders(modify_orders)
52+
post_body = request.get_body_params()
53+
print(json.dumps(post_body, indent=4))
54+
params = request.get_query_params()
55+
print(params)
56+
57+
try:
58+
response = api_client.get_response(request)
59+
print(response.json())
60+
61+
except ServerException as se:
62+
print(se.get_error_code(), ":", se.get_error_msg())
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 webullsdkcore.client import ApiClient
18+
from webullsdkcore.exception.exceptions import ServerException
19+
from webullsdktrade.request.v2.get_order_detail_request import OrderDetailRequest
20+
21+
22+
optional_api_endpoint = "<api_endpoint>"
23+
optional_api_region_id = "<api_region_id>"
24+
your_app_key = "<your_app_key>"
25+
your_app_secret = "<your_app_secret>"
26+
account_id = "<your_account_id>"
27+
api_client = ApiClient(your_app_key, your_app_secret)
28+
api_client.add_endpoint(optional_api_region_id, optional_api_endpoint)
29+
30+
# Replace with the client_order_id to be queried.
31+
client_order_id = "<your_client_order_id>"
32+
33+
class TestOrderOperation(unittest.TestCase):
34+
def test_order_open(self):
35+
request = OrderDetailRequest()
36+
request.set_endpoint(optional_api_endpoint)
37+
request.set_account_id(account_id)
38+
request.set_client_order_id(client_order_id)
39+
params = request.get_query_params()
40+
print(params)
41+
try:
42+
response = api_client.get_response(request)
43+
print(json.dumps(response.json(), indent=4))
44+
45+
except ServerException as se:
46+
print(se.get_error_code(), ":", se.get_error_msg())

0 commit comments

Comments
 (0)