Domain
Endpoint refers to the network domain of the requested service, such as api.webull.hk
corresponding to the HTTP API service.
Different services will use different domain, such as quotes-api.webull.hk
corresponding to market data services.
The region_id
is also related to the Endpoint. For example, the region_id
corresponding to the above two domain is hk (representing Hong Kong).
In the process of using the SDK, the Endpoint has been managed by default. Generally, the developer only needs to set the region_id correctly, and there is no need to set the Endpoint separately.
HTTP API
Different ways for users to customize Endpoint
- Python
- Java
- Set through ApiClient and take effect globally. The sample code is as follows.
from webullsdkcore.client import ApiClient
client = ApiClient(app_key="<your_app_key>", app_secret="<your_app_secret>", region_id="<region_id>")
client.add_endpoint("<region_id>", "<endpoint>")
- Set by Request, and it only takes effect for the current Request. The sample code is as follows.
from webullsdkmdata.request.get_instruments_request import GetInstrumentsRequest
request = GetInstrumentsRequest()
request.set_endpoint("<endpoint>")
- Set through EndpointResolver and take effect globally. The sample code is as follows.
EndpointResolver.getDefault().addEndpoint("<region_id>", ApiModule.API, "<endpoint>");
- By setting HttpApiConfig, it only takes effect for the current Client/Service instance. The sample code is as follows.
HttpApiConfig apiConfig = HttpApiConfig.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.regionId("<region_id>")
.endpoint("<endpoint>")
.build();
// HttpApiClient client = new HttpApiClient(apiConfig);
TradeApiService apiService = new TradeHttpApiService(apiConfig);
- By setting HttpRequest, it is only valid for the current Request. The sample code is as follows.
HttpApiConfig apiConfig = HttpApiConfig.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.regionId("<region_id>")
.build();
HttpApiClient client = new HttpApiClient(apiConfig);
HttpRequest request = new HttpRequest("<endpoint>", "/trade/instrument", Versions.V1, HttpMethod.GET);
Map<String, Object> params = new HashMap<>();
params.put("instrument_id", instrumentId);
request.setQuery(params);
InstrumentInfo instrumentInfo = client.request(request).responseType(InstrumentInfo.class).doAction();
Quote Subscription
- Python
- Java
- By setting the api_endpoint parameter, the user can implement the Endpoint of the custom gRPC API. The sample code is as follows.
from webullsdkmdata.quotes.subscribe.default_client import DefaultQuotesClient
quotes_client = DefaultQuotesClient(
"<your_app_key>", "<your_app_secret>", "<region_id>", api_endpoint="<api_endpoint>")
- By setting the host and port parameters, the user can implement the Endpoint of the custom MQTT protocol. The sample code is as follows.
from webullsdkmdata.quotes.subscribe.default_client import DefaultQuotesClient
quotes_client = DefaultQuotesClient(
"<your_app_key>", "<your_app_secret>", "<region_id>")
quotes_client.connect_and_loop_start(host="<host>", port="<port>")
By setting the host, port and apiClient parameter, the user can implement the Endpoint of the custom gRPC API or MQTT protocol. The sample code is as follows.
QuotesApiClient quotesApiClient = QuotesApiClient.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.host("<api_endpoint>")
.port(443)
.build();
QuotesSubsClient quotesSubsClient = QuotesSubsClient.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.host("<host>")
.port(8883)
.apiClient(quotesApiClient)
.build();
Trade Events Subscription
By setting the parameters of host and port, the user can implement the endpoint of the custom gRPC protocol. The sample code is as follows.
- Python
- Java
from webullsdktradeeventscore.events_client import EventsClient
events_client = EventsClient("<your_app_key>", "<your_app_secret>",region_id="<region_id>", host="<host>", port="<port>")
EventClient client = EventClient.builder()
.appKey("<your_app_key>")
.appSecret("<your_app_secret>")
.host("<host>")
.port(443)
.build();