Skip to content

Commit 10889b5

Browse files
author
方佳
committed
Merge branch 'main_merge_260704' into 'main'
[OpenAPI&FIX-260704 version]: Trading API新增接口:Get Account Cash Activities (支持connect 第三方客户需求) See merge request webull/webull-openapi-python-sdk!36
2 parents c85a32a + d588a54 commit 10889b5

9 files changed

Lines changed: 154 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__ = '2.0.12'
1+
__version__ = '2.0.13'

‎samples/trade/activities_client.py‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.client import ApiClient
18+
from webull.trade.trade_client import TradeClient
19+
20+
optional_api_endpoint = "<api_endpoint>"
21+
your_app_key = "<your_app_key>"
22+
your_app_secret = "<your_app_secret>"
23+
region_id = "<region_id>"
24+
account_id = "<your_account_id>"
25+
26+
api_client = ApiClient(your_app_key, your_app_secret, region_id)
27+
api_client.add_endpoint(region_id, optional_api_endpoint)
28+
29+
if __name__ == '__main__':
30+
trade_client = TradeClient(api_client)
31+
32+
# Query cash activities with default parameters
33+
res = trade_client.activity.get_activities(account_id)
34+
if res.status_code == 200:
35+
print('get activities:', res.json())
36+
37+
# Query cash activities with activity type filter
38+
res = trade_client.activity.get_activities(account_id, activity_types="TRADE,DEPOSIT")
39+
if res.status_code == 200:
40+
print('get activities by type:', res.json())
41+
42+
# Query cash activities with time range filter
43+
res = trade_client.activity.get_activities(
44+
account_id,
45+
start_time="2026-06-30T12:00:00.000Z",
46+
end_time="2026-07-03T12:00:00.000Z",
47+
page_size=20
48+
)
49+
if res.status_code == 200:
50+
print('get activities by time range:', res.json())
51+
52+
# Query cash activities with cursor-based pagination
53+
res = trade_client.activity.get_activities(
54+
account_id,
55+
last_activity_id="<last_activity_id_from_previous_page>",
56+
page_size=10
57+
)
58+
if res.status_code == 200:
59+
print('get activities next page:', res.json())

‎webull/__init__.py‎

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

‎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.12'
1+
__version__ = '2.0.13'
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.12'
3+
__version__ = '2.0.13'

‎webull/trade/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.0.12'
1+
__version__ = '2.0.13'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 GetActivitiesRequest(ApiRequest):
20+
def __init__(self):
21+
ApiRequest.__init__(self, "/openapi/trade/activities/cash", 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_activity_types(self, activity_types):
27+
self.add_query_param("activity_types", activity_types)
28+
29+
def set_start_time(self, start_time):
30+
self.add_query_param("start_time", start_time)
31+
32+
def set_end_time(self, end_time):
33+
self.add_query_param("end_time", end_time)
34+
35+
def set_last_activity_id(self, last_activity_id):
36+
self.add_query_param("last_activity_id", last_activity_id)
37+
38+
def set_page_size(self, page_size):
39+
self.add_query_param("page_size", page_size)

‎webull/trade/trade/activity.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.trade.request.get_activities_request import GetActivitiesRequest
18+
19+
20+
class Activity:
21+
def __init__(self, api_client):
22+
self.client = api_client
23+
24+
def get_activities(self, account_id, activity_types=None, start_time=None, end_time=None,
25+
last_activity_id=None, page_size=10):
26+
"""
27+
Query cash activities by type with pagination support.
28+
This interface is currently supported only for Webull US.
29+
30+
:param account_id: Account ID
31+
:param activity_types: Activity types filter, comma-separated string (optional)
32+
:param start_time: Start time filter (optional)
33+
:param end_time: End time filter (optional)
34+
:param last_activity_id: The last activity ID of the previous page for cursor-based pagination (optional)
35+
:param page_size: Number of entries per page, default value is 10
36+
"""
37+
get_activities_request = GetActivitiesRequest()
38+
get_activities_request.set_account_id(account_id)
39+
if activity_types is not None:
40+
get_activities_request.set_activity_types(activity_types)
41+
if start_time is not None:
42+
get_activities_request.set_start_time(start_time)
43+
if end_time is not None:
44+
get_activities_request.set_end_time(end_time)
45+
if last_activity_id is not None:
46+
get_activities_request.set_last_activity_id(last_activity_id)
47+
get_activities_request.set_page_size(page_size)
48+
response = self.client.get_response(get_activities_request)
49+
return response

‎webull/trade/trade_client.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from webull.core.http.initializer.client_initializer import ClientInitializer
1818
from webull.trade.trade.account_info import Account
19+
from webull.trade.trade.activity import Activity
1920
from webull.trade.trade.order_operation import OrderOperation
2021
from webull.trade.trade.trade_calendar import TradeCalendar
2122
from webull.trade.trade.trade_instrument import TradeInstrument
@@ -33,6 +34,7 @@ def __init__(self, api_client):
3334
self.order = OrderOperation(api_client)
3435
self.order_v2 = OrderOperationV2(api_client)
3536
self.order_v3 = OrderOperationV3(api_client)
37+
self.activity = Activity(api_client)
3638
self.trade_instrument = TradeInstrument(api_client)
3739
self.trade_calendar = TradeCalendar(api_client)
3840

0 commit comments

Comments
 (0)