Skip to content

Commit ce59799

Browse files
author
方佳
committed
Merge branch 'main_merge_250104' into 'main'
feat: Added support for webull JP client v2 API, currently limited to webull jp CASH accounts. See merge request webull/openapi-python-sdk!8
2 parents dd3dc58 + 1fdfbc9 commit ce59799

37 files changed

+1030
-40
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.9"
1+
__version__ = "0.1.10"
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.9",
19-
"webull-python-sdk-trade==0.1.9"
18+
"webull-python-sdk-mdata==0.1.10",
19+
"webull-python-sdk-trade==0.1.10"
2020
]
2121

2222
setup_args = {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
import unittest
16+
17+
from webullsdkcore.client import ApiClient
18+
from webullsdkcore.exception.exceptions import ServerException
19+
from webullsdktrade.request.v2.get_account_list import GetAccountList
20+
21+
optional_api_endpoint = "<api_endpoint>"
22+
your_app_key = "<your_app_key>"
23+
your_app_secret = "<your_app_secret>"
24+
api_client = ApiClient(your_app_key, your_app_secret)
25+
26+
27+
class TestGetSubscriptions(unittest.TestCase):
28+
def test_get_app_subscriptions(self):
29+
request = GetAccountList()
30+
request.set_endpoint(optional_api_endpoint)
31+
try:
32+
response = api_client.get_response(request)
33+
print(response.json())
34+
except ServerException as se:
35+
print(se.get_error_code(), ":", se.get_error_msg())

webull-python-sdk-demos/tests/trade/request/test_order_operation.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,3 @@ def test_order_operation(self):
8181
res = order_operation.cancel_order(account_id, cancel_client_order_id)
8282
if res.status_code == 200:
8383
print('cancel order response:', res.json())
84-
85-
86-
87-
88-
89-

webull-python-sdk-demos/tests/trade/request/v2/__init__.py

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 unittest
15+
16+
from webullsdkcore.client import ApiClient
17+
from webullsdktrade.trade.v2.account_info_v2 import AccountV2
18+
19+
optional_api_endpoint = "<api_endpoint>"
20+
your_app_key = "<your_app_key>"
21+
your_app_secret = "<your_app_secret>"
22+
account_id = "<your_account_id>"
23+
#'jp'
24+
region_id = "<region_id>"
25+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
26+
api_client.add_endpoint(region_id, optional_api_endpoint)
27+
28+
29+
class TestAccountInfo(unittest.TestCase):
30+
def test_account_info(self):
31+
account = AccountV2(api_client)
32+
res = account.get_account_list()
33+
if res.status_code == 200:
34+
print('account list:', res.json())
35+
36+
res = account.get_account_balance(account_id)
37+
if res.status_code == 200:
38+
print('account balance:', res.json())
39+
40+
res = account.get_account_position(account_id)
41+
if res.status_code == 200:
42+
print('account position:', res.json())
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_order_request import CancelOrderRequest
20+
21+
optional_api_endpoint = "<api_endpoint>"
22+
your_app_key = "<your_app_key>"
23+
your_app_secret = "<your_app_secret>"
24+
account_id = "<your_account_id>"
25+
#'jp'
26+
region_id = "<region_id>"
27+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
28+
api_client.add_endpoint(region_id, optional_api_endpoint)
29+
client_order_id = "88a0b06eb35b448b8aacd9f2ae4d2deb"
30+
31+
32+
class TestOrderOperation(unittest.TestCase):
33+
def test_cancel_order(self):
34+
request = CancelOrderRequest()
35+
request.set_endpoint(optional_api_endpoint)
36+
request.set_account_id(account_id)
37+
request.set_client_order_id(client_order_id)
38+
post_body = request.get_body_params()
39+
print(json.dumps(post_body, indent=4))
40+
params = request.get_query_params()
41+
print(params)
42+
try:
43+
response = api_client.get_response(request)
44+
print(json.dumps(response.json(), indent=4))
45+
46+
except ServerException as se:
47+
print(se.get_error_code(), ":", se.get_error_msg())
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 unittest
16+
17+
from webullsdkcore.client import ApiClient
18+
from webullsdkcore.exception.exceptions import ServerException
19+
from webullsdktrade.request.v2.get_account_balance_request import AccountBalanceRequest
20+
21+
optional_api_endpoint = "<api_endpoint>"
22+
your_app_key = "<your_app_key>"
23+
your_app_secret = "<your_app_secret>"
24+
account_id = "<your_account_id>"
25+
#'jp'
26+
region_id = "<region_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+
class TestAccountBalanceRequest(unittest.TestCase):
32+
def test_get_account_balance(self):
33+
request = AccountBalanceRequest()
34+
request.set_endpoint(optional_api_endpoint)
35+
request.set_account_id(account_id)
36+
request.set_total_asset_currency()
37+
try:
38+
response = api_client.get_response(request)
39+
print(response.json())
40+
except ServerException as se:
41+
print(se.get_error_code(), ":", se.get_error_msg())
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 unittest
16+
17+
from webullsdkcore.client import ApiClient
18+
from webullsdkcore.exception.exceptions import ServerException
19+
from webullsdktrade.request.v2.get_account_positions_request import AccountPositionsRequest
20+
21+
optional_api_endpoint = "<api_endpoint>"
22+
your_app_key = "<your_app_key>"
23+
your_app_secret = "<your_app_secret>"
24+
account_id = "<your_account_id>"
25+
#'jp'
26+
region_id = "<region_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+
class TestAccountPositionsRequest(unittest.TestCase):
32+
def test_get_account_positions(self):
33+
request = AccountPositionsRequest()
34+
request.set_endpoint(optional_api_endpoint)
35+
request.set_account_id(account_id)
36+
try:
37+
response = api_client.get_response(request)
38+
print(response.json())
39+
except ServerException as se:
40+
print(se.get_error_code(), ":", se.get_error_msg())
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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_history_request import OrderHistoryRequest
20+
21+
optional_api_endpoint = "<api_endpoint>"
22+
your_app_key = "<your_app_key>"
23+
your_app_secret = "<your_app_secret>"
24+
account_id = "<your_account_id>"
25+
#'jp'
26+
region_id = "<region_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+
class TestOrderOperation(unittest.TestCase):
32+
def test_order_history(self):
33+
request = OrderHistoryRequest()
34+
request.set_endpoint(optional_api_endpoint)
35+
request.set_account_id(account_id)
36+
params = request.get_query_params()
37+
print(params)
38+
try:
39+
response = api_client.get_response(request)
40+
print(json.dumps(response.json(), indent=4))
41+
42+
except ServerException as se:
43+
print(se.get_error_code(), ":", se.get_error_msg())
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
import unittest
16+
import uuid
17+
18+
from webullsdkcore.client import ApiClient
19+
from webullsdkcore.exception.exceptions import ServerException
20+
from webullsdktrade.request.v2.palce_order_request import PlaceOrderRequest
21+
22+
optional_api_endpoint = "<api_endpoint>"
23+
your_app_key = "<your_app_key>"
24+
your_app_secret = "<your_app_secret>"
25+
account_id = "<your_account_id>"
26+
#'jp'
27+
region_id = "<region_id>"
28+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
29+
api_client.add_endpoint(region_id, optional_api_endpoint)
30+
client_order_id = uuid.uuid4().hex
31+
new_orders = {
32+
"client_order_id": client_order_id,
33+
"symbol": "7011",
34+
"instrument_type": "EQUITY",
35+
"market": "JP",
36+
"order_type": "LIMIT",
37+
"limit_price": "2080",
38+
"quantity": "100",
39+
"support_trading_session": "N",
40+
"side": "BUY",
41+
"time_in_force": "DAY",
42+
"entrust_type": "QTY",
43+
"account_tax_type": "GENERAL"
44+
}
45+
46+
47+
class TestOrderOperation(unittest.TestCase):
48+
def test_place_order(self):
49+
request = PlaceOrderRequest()
50+
request.set_endpoint(optional_api_endpoint)
51+
request.set_account_id(account_id)
52+
request.set_new_orders(new_orders)
53+
request.finalize_order()
54+
post_body = request.get_body_params()
55+
print(json.dumps(post_body, indent=4))
56+
params = request.get_query_params()
57+
print(params)
58+
59+
try:
60+
response = api_client.get_response(request)
61+
print(response.json())
62+
63+
except ServerException as se:
64+
print(se.get_error_code(), ":", se.get_error_msg())

0 commit comments

Comments
 (0)