Quick Start
Requirements
- Please first generate the app key and app secret on the OpenAPI登録.
- Requirements for Programming language version:
- Python
- Java
Requires Python 3.7 and above.
JDK 8 or above needs to be installed.
SDK Description
Package Dependency Description
- Python
- Java
Packages that must be installed regardless of which product's development kit is used.
webull-python-sdk-core
Packages that must be installed when subscribing to products using trade events.
webull-python-sdk-trade-events-core
Packages that need to be installed by default for the complete use of quotes SDK.
webull-python-sdk-core
webull-python-sdk-mdata
Packages that need to be installed by default for the complete use of the trading SDK.
webull-python-sdk-core
webull-python-sdk-trade-events-core
webull-python-sdk-trade
Libraries that must be added for the complete use of quotes SDK.
webull-java-sdk-quotes
Libraries that must be added when subscribing to products using trade events.
webull-java-sdk-trade-events
Libraries that need to be added by default for the complete use of the trading SDK.
webull-java-sdk-trade-events
webull-java-sdk-trade
SDK Installation
- Python
- Java
Install via pip
pip3 install --upgrade webull-python-sdk-core
pip3 install --upgrade webull-python-sdk-quotes-core
pip3 install --upgrade webull-python-sdk-mdata
pip3 install --upgrade webull-python-sdk-trade-events-core
pip3 install --upgrade webull-python-sdk-trade
Maven configuration
<dependencies>
<dependency>
<groupId>com.webull.openapi</groupId>
<artifactId>webull-java-sdk-quotes</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>com.webull.openapi</groupId>
<artifactId>webull-java-sdk-trade-events</artifactId>
<version>0.2.9</version>
</dependency>
<dependency>
<groupId>com.webull.openapi</groupId>
<artifactId>webull-java-sdk-trade</artifactId>
<version>0.2.9</version>
</dependency>
</dependencies>
API Host
tip
The Http API address is used for normal Http requests.
The trading alerts is used for real-time pushes such as order status changes.
Production Environment
HTTP API: api.webull.co.jp
Trading news push: events-api.webull.co.jp
Examples of API calls
caution
The following interfaces are listed, and the default connection address is the production environment.
Http interface list
- Python
- Java
import uuid
from webullsdkcore.client import ApiClient
from webullsdktrade.api import API
from webullsdkcore.common.region import Region
optional_api_endpoint = "jp-openapi-alb.uat.webullbroker.com"
your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
api_client = ApiClient(your_app_key, your_app_secret, Region.JP.value)
api_client.add_endpoint(Region.JP.value, optional_api_endpoint)
class TestOrder(object):
def __init__(self):
self.api = API(api_client)
def order(self):
res = self.api.account.get_app_subscriptions()
account_id = None
if res.status_code == 200:
print('app subscriptions:', res.json())
result = res.json()
account_id = result[0]['account_id']
print("account id:", account_id)
if account_id is None:
print("account id is null")
return
client_order_id = uuid.uuid4().hex
print('client order id:', client_order_id)
stock_order = {
"client_order_id": "2343512312312312",
"instrument_id": "913255598",
"side": "SELL",
"tif": "DAY",
"order_type": "LIMIT",
"limit_price": "485.100",
"extended_hours_trading": False,
"trade_currency": "USD",
"account_tax_type": "GENERAL",
"margin_type": "ONE_DAY",
"close_contracts": [
{
"contract_id": "MCH6VT35A9OFA4DVNOBGEE98JA",
"qty": "2"
}
]
}
res = self.api.order.place_order_v2(account_id, stock_order)
if res.status_code == 200:
print('place order res:', res.json())
if __name__ == '__main__':
openapi = TestOrder()
openapi.order()
import com.webull.openapi.common.Region;
import com.webull.openapi.common.dict.OrderSide;
import com.webull.openapi.common.dict.OrderTIF;
import com.webull.openapi.common.dict.OrderType;
import com.webull.openapi.http.HttpApiConfig;
import com.webull.openapi.trade.api.TradeApiService;
import com.webull.openapi.trade.api.http.TradeHttpApiService;
import com.webull.openapi.trade.api.request.StockOrder;
import com.webull.openapi.trade.api.response.Account;
import com.webull.openapi.trade.api.response.OrderResponse;
import com.webull.openapi.logger.Logger;
import com.webull.openapi.logger.LoggerFactory;
import com.webull.openapi.serialize.JsonSerializer;
import com.webull.openapi.utils.CollectionUtils;
import com.webull.openapi.utils.GUID;
import com.webull.openapi.utils.StringUtils;
import java.util.List;
public class HttpApi {
private static final Logger logger = LoggerFactory.getLogger(HttpApi.class);
public static void main(String[] args) {
HttpApiConfig apiConfig = HttpApiConfig.builder()
.appKey("8adaccd222bced60420814f0c0585bdd")
.appSecret("45c597c1e21af91829b3959ebeac57dc")
.regionId(Region.jp.name())
.endpoint("jp-openapi-alb.uat.webullbroker.com")
.build();
TradeApiService apiService = new TradeHttpApiService(apiConfig);
List<Account> accounts = apiService.getAccountList("");
String accountId = null;
if (CollectionUtils.isNotEmpty(accounts)) {
accountId = accounts.get(0).getAccountId();
logger.info("Account id: {}", accountId);
}
if (StringUtils.isBlank(accountId)) {
logger.info("Account id is empty.");
return;
}
String clientOrderId = GUID.get();
StockOrder stockOrder = new StockOrder();
stockOrder.setClientOrderId(clientOrderId);
stockOrder.setInstrumentId("913256409");
stockOrder.setSide(OrderSide.BUY.name());
stockOrder.setTif(OrderTIF.DAY.name());
stockOrder.setOrderType(OrderType.LIMIT.name());
stockOrder.setQty("1");
stockOrder.setExtendedHoursTrading(false);
OrderResponse response = apiService.placeOrder(accountId, stockOrder);
logger.info("Place order: {}", JsonSerializer.toJson(response));
}
}
Examples of trading pushes
- Python
- Java
import logging
from webullsdktradeeventscore.events_client import EventsClient
from webullsdkcore.common.region import Region
your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
account_id = "<your_account_id>"
def _on_log(level, log_content):
print(logging.getLevelName(level), log_content)
if __name__ == '__main__':
client = EventsClient(your_app_key, your_app_secret, Region.JP.value)
client.on_log = _on_log
print("subscribe account", [account_id])
client.do_subscribe([account_id])
import com.webull.openapi.common.Region;
import com.webull.openapi.http.HttpApiConfig;
import com.webull.openapi.trade.api.TradeApiService;
import com.webull.openapi.trade.api.http.TradeHttpApiService;
import com.webull.openapi.trade.api.response.Account;
import com.webull.openapi.logger.Logger;
import com.webull.openapi.logger.LoggerFactory;
import com.webull.openapi.trade.events.subscribe.EventClient;
import com.webull.openapi.trade.events.subscribe.Subscription;
import com.webull.openapi.trade.events.subscribe.message.SubscribeRequest;
import com.webull.openapi.trade.events.subscribe.message.SubscribeResponse;
import com.webull.openapi.utils.CollectionUtils;
import com.webull.openapi.utils.StringUtils;
import java.util.List;
public class GrpcApi {
private static final Logger logger = LoggerFactory.getLogger(GrpcApi.class);
private static final String appKey = "8adaccd222bced60420814f0c0585bdd";
private static final String appSecret = "45c597c1e21af91829b3959ebeac57dc";
private static final String apiEndpoint = "jp-openapi-alb.uat.webullbroker.com";
private static final String eventHost = "jp-openapi-events.uat.webullbroker.com";
public static void main(String[] args) {
HttpApiConfig apiConfig = HttpApiConfig.builder()
.appKey(appKey)
.appSecret(appSecret)
.regionId(Region.jp.name())
.endpoint(apiEndpoint)
.build();
TradeApiService apiService = new TradeHttpApiService(apiConfig);
List<Account> accounts = apiService.getAccountList("");
String accountId = null;
if (CollectionUtils.isNotEmpty(accounts)) {
accountId = accounts.get(0).getAccountId();
logger.info("Account id: {}", accountId);
}
if (StringUtils.isBlank(accountId)) {
logger.info("Account id is empty.");
return;
}
try (EventClient client = EventClient.builder()
.appKey(appKey)
.appSecret(appSecret)
.host(eventHost)
.onMessage(GrpcApi::handleEventMessage)
.build()) {
SubscribeRequest request = new SubscribeRequest(accountId);
Subscription subscription = client.subscribe(request);
subscription.blockingAwait();
} catch (Exception ex) {
logger.error("Subscribe trade events error", ex);
}
}
private static void handleEventMessage(SubscribeResponse response) {
logger.info("Received trade event={}", response.getPayload());
}
}