|
| 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()) |
0 commit comments