Timeout Mechanism
HTTP API
The timeout setting of the HTTP API is relatively flexible. The priority of the settings decreases in turn: Request object -> Client object -> Default value.
The default connection timeout is 5 seconds and the read timeout is 10 seconds.
The following code demonstrates how to customize the timeout setting.
- Python
- Java
from webullsdkcore.client import ApiClient
from webullsdkmdata.request.get_instruments_request import GetInstrumentsRequest
# Set the connection timeout to 3 seconds and the read timeout to 6 seconds.
client = ApiClient(app_key="<your_app_key>", app_secret="<your_app_secret>", region_id="<region_id>", connect_timeout=3,
timeout=6)
request = GetInstrumentsRequest()
# Set the connection timeout of the request to 2 seconds and the read timeout to 4 seconds, only valid for the current request.
request.set_connect_timeout(2)
request.set_read_timeout(4)
HttpApiConfig apiConfig = HttpApiConfig.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.regionId(Region.us.name())
// Set the connection timeout to 3 seconds and the read timeout to 6 seconds.
.runtimeOptions(new RuntimeOptions().connectTimeout(3, TimeUnit.SECONDS).readTimeout(6, TimeUnit.SECONDS))
.build();
HttpApiClient client = new HttpApiClient(apiConfig);
HttpRequest request = new HttpRequest("/app/subscriptions/list", Versions.V1, HttpMethod.GET);
// Set the connection timeout of the request to 2 seconds and the read timeout to 4 seconds, only valid for the current request.
request.setRuntimeOptions(new RuntimeOptions().connectTimeout(2, TimeUnit.SECONDS).readTimeout(4, TimeUnit.SECONDS));
List<Account> accounts = client.request(request).responseType(new TypeToken<List<Account>>() {}.getType()).doAction();
Quote Subscription
Market subscription is a persistent connection based on MQTT v3.1.1
. The default connection timeout is 5 seconds, and the read timeout is 60 seconds (the connection will be maintained through the heartbeat packet within 60 seconds).
- Python
- Java
Currently, there is no method for customizing the timeout configuration.
QuotesSubsClient client = QuotesSubsClient.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.regionId(Region.us.name())
// Set the connection timeout to 10 seconds and the read timeout to 60 seconds.
.connectTimeout(10000)
.readTimeout(60000)
.build()
Trade Events Subscription / Quotes API
The trading events subscription is based on the persistent connection of Server Streaming
implemented by gRPC
. Currently, there is no way to customize the timeout configuration.
- Python
- Java
The timeout is managed by Python's gRPC libs by default.
The timeout is managed by Java's gRPC libs by default.