Skip to content

Commit 5aa2891

Browse files
author
袁鸥
committed
Merge branch 'main_merge_251122' into 'main'
feat: Supports Webull HK and Webull US See merge request webull/webull-openapi-java-sdk!3
2 parents c441b28 + 08fad88 commit 5aa2891

29 files changed

Lines changed: 1435 additions & 298 deletions

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ Subscription to real-time information: Subscribe to order status changes, market
1616

1717
- Please first generate the app key and app secret on the Webull official website.
1818

19-
| Broker | Link |
20-
|-----------|-----------------------|
21-
| Webull HK | https://www.webull.hk |
19+
| Broker | Link |
20+
|-----------|-------------------------------------------------|
21+
| Webull HK | https://www.webull.hk/open-api |
22+
| Webull US | https://www.webull.com/center#openApiManagement |
2223

2324
- Requires JDK 8 and above.
2425

@@ -34,6 +35,7 @@ The bottom layer of Webull OpenAPI provides three protocols, HTTP / GRPC / MQTT,
3435

3536
## Developer documentation
3637

37-
| Broker | Link |
38-
|-----------|---------------------------------------|
39-
| Webull HK | https://developer.webull.hk/apis/docs |
38+
| Broker | Link |
39+
|-----------|----------------------------------------|
40+
| Webull HK | https://developer.webull.hk/apis/docs |
41+
| Webull US | https://developer.webull.com/apis/docs |

pom.xml

Lines changed: 1 addition & 1 deletion
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.0.1</version>
24+
<version>1.0.2</version>
2525

2626
<name>webull-openapi-java-sdk-parent</name>
2727
<url>https://github.com/webull-inc/webull-openapi-java-sdk/</url>

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.0.1</version>
22+
<version>1.0.2</version>
2323
</parent>
2424
<modelVersion>4.0.0</modelVersion>
2525

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

Lines changed: 175 additions & 53 deletions
Large diffs are not rendered by default.

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.0.1</version>
10+
<version>1.0.2</version>
1111
</parent>
1212

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

webull-openapi-java-sdk/src/main/java/com/webull/openapi/core/common/DefaultHost.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public final class DefaultHost {
2020
private DefaultHost() {}
2121

2222
public static final String API_US = "api.webull.com";
23-
public static final String QUOTES_US = "usquotes-api.webullfintech.com";
23+
public static final String QUOTES_US = "data-api.webull.com";
2424
public static final String EVENTS_US = "events-api.webull.com";
2525

2626
public static final String API_HK = "api.webull.hk";

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.0.1";
27+
private static final String DEFAULT_APPLICATION_VERSION = "1.0.2";
2828

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

webull-openapi-java-sdk/src/main/java/com/webull/openapi/core/execption/ErrorCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ private ErrorCode() {}
3737

3838
public static final String TIMEOUT = "Timeout";
3939

40+
public static final String GET_CONFIG_ERROR = "GetConfigError";
41+
4042
public static final String INIT_TOKEN_ERROR = "InitTokenError";
4143

4244
public static final String LOAD_TOKEN_ERROR = "LoadTokenError";

webull-openapi-java-sdk/src/main/java/com/webull/openapi/core/http/initializer/ClientInitializer.java

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515
*/
1616
package com.webull.openapi.core.http.initializer;
1717

18+
import com.google.api.client.util.Lists;
1819
import com.webull.openapi.core.common.Region;
20+
import com.webull.openapi.core.execption.ClientException;
21+
import com.webull.openapi.core.execption.ErrorCode;
22+
import com.webull.openapi.core.http.HttpApiClient;
23+
import com.webull.openapi.core.http.initializer.config.ConfigService;
24+
import com.webull.openapi.core.http.initializer.config.bean.ApiConfig;
25+
import com.webull.openapi.core.http.initializer.token.TokenManager;
1926
import com.webull.openapi.core.logger.Logger;
2027
import com.webull.openapi.core.logger.LoggerFactory;
2128
import com.webull.openapi.core.utils.StringUtils;
22-
import com.webull.openapi.core.http.HttpApiClient;
23-
import com.webull.openapi.core.http.initializer.token.TokenManager;
2429

2530
import java.util.ArrayList;
2631
import java.util.List;
@@ -44,7 +49,14 @@ public static void init(HttpApiClient apiClient){
4449
*/
4550
private static void initToken(HttpApiClient apiClient){
4651

47-
if(!checkRegionTokenEnable(apiClient)){
52+
List<String> disableConfigRegionIds = new ArrayList<>();
53+
disableConfigRegionIds.add(Region.hk.name());
54+
String regionId = Objects.nonNull(apiClient) && Objects.nonNull(apiClient.getConfig()) ? apiClient.getConfig().getRegionId() : null;
55+
if(disableConfigRegionIds.contains(regionId)){
56+
if(!checkRegionTokenEnable(apiClient)){
57+
return;
58+
}
59+
}else if(!checkTokenEnable(apiClient)){
4860
return;
4961
}
5062

@@ -81,4 +93,28 @@ private static boolean checkRegionTokenEnable(HttpApiClient apiClient){
8193
logger.info("CheckRegionTokenEnable result is {}, enable regionIds is {}.", result, enableRegionIds);
8294
return result;
8395
}
96+
97+
/**
98+
* Check whether token checking is enabled
99+
* @param apiClient
100+
* @return
101+
*/
102+
private static boolean checkTokenEnable(HttpApiClient apiClient){
103+
if(Objects.isNull(apiClient)){
104+
logger.warn("checkTokenEnable apiClient is null return false");
105+
return false;
106+
}
107+
108+
ConfigService configService = new ConfigService(apiClient);
109+
ApiConfig apiConfig = configService.getConfig();
110+
if(Objects.isNull(apiConfig)){
111+
String msg = "checkTokenEnable apiConfig is null error.";
112+
logger.warn(msg);
113+
throw new ClientException(ErrorCode.GET_CONFIG_ERROR, msg);
114+
}
115+
116+
boolean result = Boolean.TRUE.equals(apiConfig.getTokenCheckEnabled());
117+
logger.info("checkTokenEnable result is {}", result);
118+
return result;
119+
}
84120
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2022 Webull
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.webull.openapi.core.http.initializer.config;
17+
18+
import com.webull.openapi.core.common.Versions;
19+
import com.webull.openapi.core.http.HttpApiClient;
20+
import com.webull.openapi.core.http.HttpApiConfig;
21+
import com.webull.openapi.core.http.HttpRequest;
22+
import com.webull.openapi.core.http.common.HttpMethod;
23+
import com.webull.openapi.core.http.initializer.config.bean.ApiConfig;
24+
import com.webull.openapi.core.http.initializer.token.bean.AccessToken;
25+
26+
public class ConfigService {
27+
28+
private final HttpApiClient apiClient;
29+
30+
public ConfigService(HttpApiConfig config) {
31+
this(new HttpApiClient(config));
32+
}
33+
34+
public ConfigService(HttpApiClient apiClient) {
35+
this.apiClient = apiClient;
36+
}
37+
38+
/**
39+
* get config
40+
* @return
41+
*/
42+
public ApiConfig getConfig() {
43+
44+
HttpRequest request = new HttpRequest("/openapi/config", Versions.V2, HttpMethod.GET);
45+
return apiClient.request(request).responseType(ApiConfig.class).doAction();
46+
47+
}
48+
}

0 commit comments

Comments
 (0)