|
| 1 | +package com.webull.openapi.samples.trade; |
| 2 | + |
| 3 | +import com.webull.openapi.core.http.HttpApiConfig; |
| 4 | +import com.webull.openapi.core.logger.Logger; |
| 5 | +import com.webull.openapi.core.logger.LoggerFactory; |
| 6 | +import com.webull.openapi.core.utils.CollectionUtils; |
| 7 | +import com.webull.openapi.core.utils.StringUtils; |
| 8 | +import com.webull.openapi.samples.config.Env; |
| 9 | +import com.webull.openapi.trade.TradeClientV3; |
| 10 | +import com.webull.openapi.trade.response.v3.Account; |
| 11 | +import com.webull.openapi.trade.response.v3.OrderExecution; |
| 12 | + |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +public class OrderExecutionClient { |
| 16 | + |
| 17 | + private static final Logger logger = LoggerFactory.getLogger(OrderExecutionClient.class); |
| 18 | + |
| 19 | + public static void main(String[] args) { |
| 20 | + HttpApiConfig apiConfig = HttpApiConfig.builder() |
| 21 | + .appKey(Env.APP_KEY) |
| 22 | + .appSecret(Env.APP_SECRET) |
| 23 | + .regionId(Env.REGION_ID) |
| 24 | +// .endpoint("<optional_api_endpoint>") |
| 25 | + .build(); |
| 26 | + TradeClientV3 apiService = new TradeClientV3(apiConfig); |
| 27 | + |
| 28 | + // Get account |
| 29 | + List<Account> accounts = apiService.listAccount(); |
| 30 | + logger.info("Accounts: {}", accounts); |
| 31 | + String accountId = null; |
| 32 | + if (CollectionUtils.isNotEmpty(accounts)) { |
| 33 | + accountId = accounts.get(0).getAccountId(); |
| 34 | + } |
| 35 | + if (StringUtils.isBlank(accountId)) { |
| 36 | + logger.info("Account id is empty."); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + // Get order executions filtered by date range |
| 41 | + List<OrderExecution> filteredExecutions = apiService.getOrderExecutions( |
| 42 | + accountId, null, "2026-06-20", "2026-06-22", null, null); |
| 43 | + logger.info("filteredOrderExecutions: {}", filteredExecutions); |
| 44 | + |
| 45 | + // Get order executions for a specific order |
| 46 | + List<OrderExecution> orderSpecific = apiService.getOrderExecutions( |
| 47 | + accountId, "<your_client_order_id>", null, null, null, null); |
| 48 | + logger.info("orderSpecificExecutions: {}", orderSpecific); |
| 49 | + |
| 50 | + // Cursor-based pagination example |
| 51 | + if (CollectionUtils.isNotEmpty(filteredExecutions)) { |
| 52 | + String lastId = filteredExecutions.get(filteredExecutions.size() - 1).getExecutionId(); |
| 53 | + List<OrderExecution> nextPage = apiService.getOrderExecutions( |
| 54 | + accountId, null, null, null, lastId, 10); |
| 55 | + logger.info("nextPageOrderExecutions: {}", nextPage); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments