Skip to content

Commit 83421e4

Browse files
author
方佳
committed
Merge branch 'main_merge_260725' into 'main'
feat:add option event subscribe See merge request webull/webull-openapi-java-sdk!40
2 parents b6d0bbc + fc43d43 commit 83421e4

14 files changed

Lines changed: 36 additions & 98 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ hs_err_pid*
2222
*.iws
2323
**/.idea/**
2424

25-
# 忽略token.txt文件
25+
# ignore
2626
token.txt

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<groupId>com.webull.openapi</groupId>
2222
<artifactId>webull-openapi-java-sdk-parent</artifactId>
2323
<packaging>pom</packaging>
24-
<version>1.1.16</version>
24+
<version>1.1.17</version>
2525

2626
<name>webull-openapi-java-sdk-parent</name>
2727
<url>https://github.com/webull-inc/webull-openapi-java-sdk/</url>
@@ -243,7 +243,7 @@
243243
<plugin>
244244
<groupId>org.apache.maven.plugins</groupId>
245245
<artifactId>maven-gpg-plugin</artifactId>
246-
<version>3.0.1</version> <!-- 可保留;若愿意可升到 3.2.x -->
246+
<version>3.0.1</version> <!-- Can be retained; It can be upgraded to 3.2.x if you wish -->
247247
<executions>
248248
<execution>
249249
<id>sign-artifacts</id>

‎webull-openapi-java-sdk-samples/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>com.webull.openapi</groupId>
2121
<artifactId>webull-openapi-java-sdk-parent</artifactId>
22-
<version>1.1.16</version>
22+
<version>1.1.17</version>
2323
</parent>
2424
<modelVersion>4.0.0</modelVersion>
2525

‎webull-openapi-java-sdk-samples/src/main/java/com/webull/openapi/samples/trade/CashActivityClient.java‎

Lines changed: 0 additions & 56 deletions
This file was deleted.

‎webull-openapi-java-sdk-samples/src/main/java/com/webull/openapi/samples/trade/TradeEventsClient.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ private static void handleEventMessage(SubscribeResponse response) {
5555
if (EventType.Position.getCode() == response.getEventType()) {
5656
logger.info("event payload:{}", payload);
5757
}
58+
59+
if (EventType.Option.getCode() == response.getEventType()) {
60+
logger.info("option payload:{}", payload);
61+
}
5862
}
5963
}
6064
}

‎webull-openapi-java-sdk/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.webull.openapi</groupId>
99
<artifactId>webull-openapi-java-sdk-parent</artifactId>
10-
<version>1.1.16</version>
10+
<version>1.1.17</version>
1111
</parent>
1212

1313
<artifactId>webull-openapi-java-sdk</artifactId>

‎webull-openapi-java-sdk/src/main/java/com/webull/openapi/core/config/ProjectReaderHelper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private ProjectReaderHelper() {
2424

2525
private static final String APPLICATION_VERSION = "application.version";
2626

27-
private static final String DEFAULT_APPLICATION_VERSION = "1.1.16";
27+
private static final String DEFAULT_APPLICATION_VERSION = "1.1.17";
2828

2929
private static final String APPLICATION_NAME = "application.name";
3030

‎webull-openapi-java-sdk/src/main/java/com/webull/openapi/core/http/HttpApiClient.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ private HttpResponse doRequest(HttpRequest request) {
145145
try {
146146
return retryable.retry(retryContext);
147147
} catch (RetriedFailedException ex) {
148-
// 异常情况用error,输出所有信息,反馈问题时提供所有信息
149148
logger.error("Http request error, Host:{}, SDK version:{}, Request:{}",
150149
request.getEndpoint(), ProjectReaderHelper.getClientSDKInfo(), JsonSerializer.toJson(request), ex);
151150
if (ex.getCause() instanceof ClientException) {

‎webull-openapi-java-sdk/src/main/java/com/webull/openapi/core/utils/SHA256Utils.java‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public final class SHA256Utils {
3030
private SHA256Utils() {
3131
}
3232

33-
// 将字节数组转换为16进制字符串
3433
public static String bytesToHex(byte[] bytes) {
3534
StringBuilder sb = new StringBuilder();
3635
for (byte b : bytes) {
@@ -41,13 +40,10 @@ public static String bytesToHex(byte[] bytes) {
4140

4241
public static String sha256(String body) {
4342
try {
44-
// 获取 SHA-256 实例
4543
MessageDigest digest = MessageDigest.getInstance("SHA-256");
4644

47-
// 计算 SHA-256
4845
byte[] hash = digest.digest(body.getBytes(StandardCharsets.UTF_8));
4946

50-
// 转成十六进制字符串返回
5147
return bytesToHex(hash);
5248
} catch (NoSuchAlgorithmException e) {
5349
throw new RuntimeException("SHA-256 algorithm is not available", e);
@@ -56,20 +52,11 @@ public static String sha256(String body) {
5652

5753
public static String sha256(byte[] body) {
5854
try {
59-
// 获取 SHA-256 实例
6055
MessageDigest digest = MessageDigest.getInstance("SHA-256");
61-
62-
// 计算 SHA-256
6356
byte[] hash = digest.digest(body);
64-
65-
// 转成十六进制字符串返回
6657
return bytesToHex(hash);
6758
} catch (NoSuchAlgorithmException e) {
6859
throw new RuntimeException("SHA-256 algorithm is not available", e);
6960
}
7061
}
71-
72-
public static void main(String[] args) {
73-
System.out.println(sha256("123456"));
74-
}
7562
}

‎webull-openapi-java-sdk/src/main/java/com/webull/openapi/trade/TradeClient.java‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,20 @@
5252
import com.webull.openapi.core.utils.Assert;
5353
import com.webull.openapi.core.utils.CollectionUtils;
5454
import com.webull.openapi.core.utils.StringUtils;
55-
55+
import com.webull.openapi.trade.http.ITradeClient;
5656
import java.lang.reflect.Type;
5757
import java.util.Arrays;
5858
import java.util.HashMap;
5959
import java.util.List;
6060
import java.util.Map;
6161
import java.util.Objects;
6262

63-
public class TradeClient implements com.webull.openapi.trade.http.ITradeClient {
63+
/**
64+
* @deprecated As of 1.x, replaced by {@link TradeClientV3}.
65+
* This class will be removed in a future major release. New integrations should use {@link TradeClientV3}.
66+
*/
67+
@Deprecated
68+
public class TradeClient implements ITradeClient {
6469

6570
private static final String ACCOUNT_ID_ARG = "accountId";
6671
private static final String STOCK_ORDER_ARG = "stockOrder";
@@ -88,7 +93,7 @@ public class TradeClient implements com.webull.openapi.trade.http.ITradeClient {
8893
private static final String CLIENT_ORDER_ID_PARAM = "client_order_id";
8994
private static final String LAST_CLIENT_ORDER_ID_PARAM = "last_client_order_id";
9095
private static final String INSTRUMENT_ID_PARAM = "instrument_id";
91-
private static final String LAST_SECURITY_ID = "last_security_id";
96+
private static final String LAST_SECURITY_ID_PARAM = "last_security_id";
9297
private static final String MARKET_PARAM = MARKET_ARG;
9398
private static final String START_PARAM = START_ARG;
9499
private static final String END_PARAM = END_ARG;
@@ -98,6 +103,7 @@ public class TradeClient implements com.webull.openapi.trade.http.ITradeClient {
98103
private static final String STRIKE_PRICE_PARAM = "strike_price";
99104
private static final String INIT_EXP_DATE_PARAM = "init_exp_date";
100105
private static final String START_TIME_PARAM = "start_date";
106+
private static final int DEFAULT_PAGE_SIZE = 10;
101107

102108
private final Region region;
103109
private final HttpApiClient apiClient;
@@ -156,7 +162,7 @@ public AccountPositions getAccountPositions(String accountId, Integer pageSize,
156162
HttpRequest request = new HttpRequest("/account/positions", Versions.V2, HttpMethod.GET);
157163
Map<String, Object> params = new HashMap<>();
158164
params.put(ACCOUNT_ID_PARAM, accountId);
159-
params.put(PAGE_SIZE_PARAM, pageSize == null ? 10 : pageSize);
165+
params.put(PAGE_SIZE_PARAM, pageSize == null ? DEFAULT_PAGE_SIZE : pageSize);
160166
if (StringUtils.isNotEmpty(lastId)) {
161167
params.put(LAST_INSTRUMENT_ID_PARAM, lastId);
162168
}
@@ -169,7 +175,7 @@ public OrderResponse placeOrder(String accountId, StockOrder stockOrder) {
169175
Assert.notBlank(ACCOUNT_ID_ARG, accountId);
170176
Assert.notNull(STOCK_ORDER_ARG, stockOrder);
171177
HttpRequest request = new HttpRequest("/trade/order/place", Versions.V2, HttpMethod.POST);
172-
addCustomHeaderFromContext(request);
178+
addCustomHeadersFromContext(request);
173179
Map<String, Object> params = new HashMap<>();
174180
params.put(ACCOUNT_ID_PARAM, accountId);
175181
params.put(STOCK_ORDER_PARAM, stockOrder);
@@ -222,7 +228,7 @@ private <T extends Order> Orders<T> getOrders(String uri, String accountId, Inte
222228
HttpRequest request = new HttpRequest(uri, Versions.V2, HttpMethod.GET);
223229
Map<String, Object> params = new HashMap<>();
224230
params.put(ACCOUNT_ID_PARAM, accountId);
225-
params.put(PAGE_SIZE_PARAM, pageSize == null ? 10 : pageSize);
231+
params.put(PAGE_SIZE_PARAM, pageSize == null ? DEFAULT_PAGE_SIZE : pageSize);
226232
if (StringUtils.isNotEmpty(lastClientOrderId)) {
227233
params.put(LAST_CLIENT_ORDER_ID_PARAM, lastClientOrderId);
228234
}
@@ -260,9 +266,9 @@ public TradableInstruments getTradeableInstruments(String lastSecurityId, Intege
260266
HttpRequest request = new HttpRequest("/trade/instrument/tradable/list", Versions.V2, HttpMethod.GET);
261267
Map<String, Object> params = new HashMap<>();
262268
if(StringUtils.isNotEmpty(lastSecurityId)){
263-
params.put(LAST_SECURITY_ID, lastSecurityId);
269+
params.put(LAST_SECURITY_ID_PARAM, lastSecurityId);
264270
}
265-
params.put(PAGE_SIZE_PARAM, pageSize == null ? 10 : pageSize);
271+
params.put(PAGE_SIZE_PARAM, pageSize == null ? DEFAULT_PAGE_SIZE : pageSize);
266272
request.setQuery(params);
267273
return apiClient.request(request).responseType(TradableInstruments.class).doAction();
268274
}
@@ -283,7 +289,7 @@ public List<TradeCalendar> getTradeCalendar(String market, String start, String
283289
public InstrumentInfo getSecurityInfo(String symbol, String market, String instrumentSuperType, String instrumentType, String strikePrice, String initExpDate) {
284290
Assert.notBlank(Arrays.asList(SYMBOL_ARG, MARKET_ARG, INSTRUMENT_SUPER_TYPE_ARG) , symbol, market, instrumentSuperType);
285291
Map<String, Object> params = new HashMap<>();
286-
if (instrumentSuperType.equals(InstrumentSuperType.OPTION.name())) {
292+
if (InstrumentSuperType.OPTION.name().equals(instrumentSuperType)) {
287293
Assert.notBlank(Arrays.asList(INSTRUMENT_TYPE_ARG, STRIKE_PRICE_ARG, INIT_EXP_DATE_ARG), instrumentType, strikePrice, initExpDate);
288294
params.put(INSTRUMENT_TYPE_PARAM, instrumentType);
289295
params.put(STRIKE_PRICE_PARAM, strikePrice);
@@ -336,7 +342,7 @@ public TradeOrderResponse placeOption(String accountId, OptionOrder optionOrder)
336342
Assert.notEmpty(NEW_ORDERS_ARG, optionOrder.getNewOrders());
337343
HttpRequest request = new HttpRequest("/openapi/account/orders/option/place", Versions.V2, HttpMethod.POST);
338344
addCustomHeadersFromOrder(request, optionOrder);
339-
addCustomHeaderFromContext(request);
345+
addCustomHeadersFromContext(request);
340346
Map<String, Object> queryMap = new HashMap<>();
341347
queryMap.put(ACCOUNT_ID_PARAM, accountId);
342348
request.setQuery(queryMap);
@@ -385,7 +391,7 @@ public void removeCustomHeaders() {
385391
RequestContextHolder.clear();
386392
}
387393

388-
private void addCustomHeaderFromContext(HttpRequest request){
394+
private void addCustomHeadersFromContext(HttpRequest request){
389395
try{
390396
Map<String, String> headersMap = RequestContextHolder.get();
391397
if(Objects.isNull(headersMap) || headersMap.isEmpty()){

0 commit comments

Comments
 (0)