|
15 | 15 | from tigeropen.trade.trade_client import TradeClient |
16 | 16 | from tigeropen.common.response import TigerResponse |
17 | 17 | from tigeropen.common.request import OpenApiRequest |
18 | | -from tigeropen.common.consts import Currency, SecurityType |
| 18 | +from tigeropen.common.consts import Currency, SecurityType, OrderSortBy |
19 | 19 | from tigeropen.common.util.contract_utils import stock_contract, option_contract_by_symbol, future_contract, \ |
20 | 20 | war_contract_by_symbol, iopt_contract_by_symbol |
21 | 21 | from tigeropen.common.util.order_utils import limit_order, limit_order_with_legs, order_leg, algo_order_params, \ |
@@ -71,6 +71,30 @@ def get_account_apis(): |
71 | 71 | openapi_client.get_analytics_asset(start_date='2021-12-01', end_date='2021-12-07') |
72 | 72 |
|
73 | 73 |
|
| 74 | +def test_get_orders_by_page(): |
| 75 | + """分页获取订单""" |
| 76 | + trade_client = TradeClient(client_config) |
| 77 | + result = list() |
| 78 | + # 每次返回数量(需 <= 300) |
| 79 | + limit = 300 |
| 80 | + conditions = { |
| 81 | + 'limit': limit, |
| 82 | + 'start_time': '2024-12-01', |
| 83 | + 'end_time': '2025-02-12', |
| 84 | + # 返回数据是按照时间逆序,即最新的数据在前。此处按照下单时间 order_time 排序 |
| 85 | + 'sort_by': OrderSortBy.LATEST_CREATED, |
| 86 | + } |
| 87 | + orders_page = trade_client.get_orders(**conditions) |
| 88 | + result.extend(orders_page) |
| 89 | + while len(orders_page) == limit: |
| 90 | + next_order_time = orders_page[-1].order_time |
| 91 | + conditions.pop('end_time', None) |
| 92 | + orders_page = trade_client.get_orders(**conditions, end_time=next_order_time) |
| 93 | + result.extend(orders_page) |
| 94 | + print(f'total order size: {len(result)}') |
| 95 | + return result |
| 96 | + |
| 97 | + |
74 | 98 | def trade_apis(): |
75 | 99 | account = client_config.account |
76 | 100 | openapi_client = TradeClient(client_config, logger=logger) |
|
0 commit comments