Quick Start
Requirements
- Please first generate the app key and app secret on the Webull official website.
- 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 to use market subscription products.
webull-python-sdk-quotes-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-quotes-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.0</version>
</dependency>
<dependency>
<groupId>com.webull.openapi</groupId>
<artifactId>webull-java-sdk-trade-events</artifactId>
<version>0.2.0</version>
</dependency>
<dependency>
<groupId>com.webull.openapi</groupId>
<artifactId>webull-java-sdk-trade</artifactId>
<version>0.2.0</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.
The push address for the market news is used for receiving the pushes for real-time market news.
Production Environment
HTTP API: api.webull.com
Trading news push: events-api.webull.com
Market news push: usquotes-api.webullfintech.com
Examples of API Calls
caution
The following interfaces are listed, and the default connection address is the production environment.
Http Interface List
- Python
- Java
from webullsdkcore.client import ApiClient
from webullsdktrade.api import API
from webullsdkcore.common.region import Region
your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
api_client = ApiClient(your_app_key, your_app_secret, Region.US.value)
api = API(api_client)
if __name__ == '__main__':
res = 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")
import com.webull.openapi.common.Region;
import com.webull.openapi.example.config.Env;
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.utils.CollectionUtils;
import com.webull.openapi.utils.StringUtils;
import java.util.List;
public class TradeAccountId {
private static final Logger logger = LoggerFactory.getLogger(TradeAccountId.class);
public static void main(String[] args) {
HttpApiConfig apiConfig = HttpApiConfig.builder()
.appKey(Env.APP_KEY)
.appSecret(Env.APP_SECRET)
.regionId(Region.us.name())
.build();
TradeApiService apiService = new TradeHttpApiService(apiConfig);
List<Account> accounts = apiService.getAccountList("");
if (CollectionUtils.isNotEmpty(accounts)) {
String accountId = accounts.get(0).getAccountId();
if (StringUtils.isNotBlank(accountId)) {
logger.info("Account id: {}", accountId);
return;
}
}
logger.info("Account id is empty.");
}
}
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.US.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.example.config.Env;
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;
public class TradeEvents {
private static final Logger logger = LoggerFactory.getLogger(TradeEvents.class);
public static void main(String[] args) {
try (EventClient client = EventClient.builder()
.appKey(Env.APP_KEY)
.appSecret(Env.APP_SECRET)
.regionId(Region.us.name())
.onMessage(TradeEvents::handleEventMessage)
.build()) {
SubscribeRequest request = new SubscribeRequest("<your_account_id>");
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());
}
}
Push List of Market News
- Python
- Java
from webullsdkmdata.common.category import Category
from webullsdkmdata.common.subscribe_type import SubscribeType
from webullsdkmdata.quotes.subscribe.default_client import DefaultQuotesClient
from webullsdkcore.common.region import Region
your_app_key = "<your_app_key>"
your_app_secret = "<your_app_secret>"
def pt_logs(client, userdata, level, buf):
print("userdata:%s, level:%s, buf:%s" % (userdata, level, buf))
def on_message(client, userdata, message):
print("Received message '" + str(message.payload) + "' on topic '"
+ message.topic + "' with QoS " + str(message.qos))
if __name__ == '__main__':
client = DefaultQuotesClient(your_app_key, your_app_secret, Region.US.value)
client.init_default_settings('AAPL', Category.US_STOCK.name, SubscribeType.SNAPSHOT.name)
client.on_log = pt_logs
client.on_message = on_message
client.connect_and_loop_forever()
import com.webull.openapi.common.Region;
import com.webull.openapi.common.dict.Category;
import com.webull.openapi.common.dict.SubscribeType;
import com.webull.openapi.example.config.Env;
import com.webull.openapi.logger.Logger;
import com.webull.openapi.logger.LoggerFactory;
import com.webull.openapi.quotes.subsribe.QuotesSubsClient;
import com.webull.openapi.quotes.subsribe.message.MarketData;
import com.webull.openapi.serialize.JsonSerializer;
import java.util.HashSet;
import java.util.Set;
public class QuotesSubscribe {
private static final Logger logger = LoggerFactory.getLogger(QuotesSubscribe.class);
public static void main(String[] args) {
Set<String> symbols = new HashSet<>();
symbols.add("AAPL");
Set<String> subTypes = new HashSet<>();
subTypes.add(SubscribeType.SNAPSHOT.name());
try (QuotesSubsClient client = QuotesSubsClient.builder()
.appKey(Env.APP_KEY)
.appSecret(Env.APP_SECRET)
.regionId(Region.us.name())
.onMessage(QuotesSubscribe::handleMarketData)
.addSubscription(symbols, Category.US_STOCK.name(), subTypes)
.build()) {
client.connectBlocking();
client.subscribeBlocking();
} catch (Exception ex) {
logger.error("Subscribe market data error", ex);
}
}
private static void handleMarketData(MarketData marketData) {
logger.info("Received market data: {}", JsonSerializer.toJson(marketData));
}
}
Feedback and Communication
You can contact us through the Webull API service email address: api@webull-us.com