Skip to content

Commit 4579ecb

Browse files
author
方佳
committed
Merge branch 'main_merge_251128' into 'main'
feat: Optimize samples See merge request webull/webull-openapi-python-sdk!6
2 parents ef1296e + 94fee4c commit 4579ecb

9 files changed

Lines changed: 257 additions & 5 deletions

File tree

samples/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.3"
1+
__version__ = "1.0.4"

samples/account/account_client.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
import json
16+
import uuid
17+
from time import sleep
18+
19+
from webull.core.client import ApiClient
20+
from webull.trade.trade_client import TradeClient
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>" # hk or us
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+
30+
31+
if __name__ == '__main__':
32+
trade_client = TradeClient(api_client)
33+
34+
res = trade_client.account_v2.get_account_list()
35+
if res.status_code == 200:
36+
print('get account list:', res.json())

samples/assets/assets_client.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
import json
16+
import uuid
17+
from time import sleep
18+
19+
from webull.core.client import ApiClient
20+
from webull.trade.trade_client import TradeClient
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>" # hk or us
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+
30+
31+
if __name__ == '__main__':
32+
trade_client = TradeClient(api_client)
33+
34+
res = trade_client.account_v2.get_account_balance(account_id)
35+
if res.status_code == 200:
36+
print('get account balance info:', res.json())
37+
38+
res = trade_client.account_v2.get_account_position(account_id)
39+
if res.status_code == 200:
40+
print('get account positions info:', res.json())
41+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
import uuid
16+
from webull.core.client import ApiClient
17+
from webull.trade.trade_client import TradeClient
18+
19+
optional_api_endpoint = "<api_endpoint>"
20+
your_app_key = "<your_app_key>"
21+
your_app_secret = "<your_app_secret>"
22+
region_id = "<region_id>" # hk or us
23+
account_id = "<your_account_id>"
24+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
25+
api_client.add_endpoint(region_id, optional_api_endpoint)
26+
27+
if __name__ == '__main__':
28+
trade_client = TradeClient(api_client)
29+
30+
# Options
31+
# For option order inquiries, please use the V2 query interface: api.order_v2.get_order_detail(account_id, client_order_id).
32+
client_order_id = uuid.uuid4().hex
33+
option_new_orders = [
34+
{
35+
"client_order_id": client_order_id,
36+
"combo_type": "NORMAL",
37+
"order_type": "LIMIT",
38+
"quantity": "1",
39+
"limit_price": "21.25",
40+
"option_strategy": "SINGLE",
41+
"side": "BUY",
42+
"time_in_force": "GTC",
43+
"entrust_type": "QTY",
44+
"legs": [
45+
{
46+
"side": "BUY",
47+
"quantity": "1",
48+
"symbol": "TSLA",
49+
"strike_price": "400",
50+
"option_expire_date": "2025-12-26",
51+
"instrument_type": "OPTION",
52+
"option_type": "CALL",
53+
"market": "US"
54+
}
55+
]
56+
}
57+
]
58+
59+
# preview
60+
res = trade_client.order_v2.preview_option(account_id, option_new_orders)
61+
if res.status_code == 200:
62+
print("preview option res:", res.json())
63+
64+
# place
65+
res = trade_client.order_v2.place_option(account_id, option_new_orders)
66+
if res.status_code == 200:
67+
print("place option res:" , res.json())
68+
69+
option_modify_orders = [
70+
{
71+
"client_order_id": client_order_id,
72+
"quantity": "2",
73+
"limit_price": "21.25"
74+
}
75+
]
76+
res = trade_client.order_v2.replace_option(account_id, option_modify_orders)
77+
if res.status_code == 200:
78+
print("Replace option order res:" , res.json())
79+
80+
res = trade_client.order_v2.cancel_option(account_id, client_order_id)
81+
if res.status_code == 200:
82+
print("Cancel option order res:" , res.json())
83+
84+
res = trade_client.order_v2.get_order_detail(account_id, client_order_id)
85+
if res.status_code == 200:
86+
print("Option order detail order res:" , res.json())
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
import uuid
16+
from webull.core.client import ApiClient
17+
from webull.trade.trade_client import TradeClient
18+
19+
optional_api_endpoint = "<api_endpoint>"
20+
your_app_key = "<your_app_key>"
21+
your_app_secret = "<your_app_secret>"
22+
region_id = "<region_id>" # hk or us
23+
account_id = "<your_account_id>"
24+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
25+
api_client.add_endpoint(region_id, optional_api_endpoint)
26+
27+
28+
if __name__ == '__main__':
29+
trade_client = TradeClient(api_client)
30+
31+
32+
# simple order
33+
client_order_id = uuid.uuid4().hex
34+
print('client order id:', client_order_id)
35+
new_simple_orders = [
36+
{
37+
"client_order_id": client_order_id,
38+
"symbol": "BULL",
39+
"instrument_type": "EQUITY",
40+
"market": "US",
41+
"order_type": "LIMIT",
42+
"limit_price": "26",
43+
"quantity": "1",
44+
"support_trading_session": "CORE",
45+
"side": "BUY",
46+
"time_in_force": "DAY",
47+
"entrust_type": "QTY"
48+
}
49+
]
50+
new_hk_stock_simple_orders = [
51+
{
52+
"client_order_id": client_order_id,
53+
"symbol": "00700",
54+
"instrument_type": "EQUITY",
55+
"market": "HK",
56+
"order_type": "ENHANCED_LIMIT",
57+
"limit_price": "612",
58+
"quantity": "100",
59+
"side": "BUY",
60+
"time_in_force": "DAY",
61+
"entrust_type": "QTY"
62+
}
63+
]
64+
res = trade_client.order_v2.preview_order(account_id, new_simple_orders)
65+
if res.status_code == 200:
66+
print('preview order res:', res.json())
67+
68+
res = trade_client.order_v2.place_order(account_id, new_simple_orders)
69+
if res.status_code == 200:
70+
print('place order res:', res.json())
71+
72+
modify_simple_orders = [
73+
{
74+
"client_order_id": client_order_id,
75+
"quantity": "2",
76+
"limit_price": "25"
77+
}
78+
]
79+
res = trade_client.order_v2.replace_order(account_id, modify_simple_orders)
80+
if res.status_code == 200:
81+
print('replace order res:', res.json())
82+
83+
res = trade_client.order_v2.cancel_order(account_id, client_order_id)
84+
if res.status_code == 200:
85+
print('cancel order res:', res.json())
86+
87+
res = trade_client.order_v2.get_order_detail(account_id, client_order_id)
88+
if res.status_code == 200:
89+
print('order detail:', res.json())

webull/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.3"
1+
__version__ = "1.0.4"

webull/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.0.3"
1+
__version__ = "1.0.4"
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__ = '1.0.3'
3+
__version__ = '1.0.4'

webull/trade/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "1.0.3"
1+
__version__ = "1.0.4"
22

0 commit comments

Comments
 (0)