This article will examine Webull and how we can use the Webull Python package.
Before we get into the specifics, we must know what an API is.
API or Application Programming Interface is an interface that allows the interaction between 2 applications without the need for user interference. An API consists of various functions and tasks. These API features can be effectively used through code. Therefore, an API is a code that allows 2 different programs to transfer information or data.
But what is Webull?
Webull LLC is a stockbroker company that provides users a platform for trading stocks, exchange-traded funds, cryptocurrencies, etc. This company powers the API within the Webull Module. The module provides analytical data for over 6000 stocks and various functions to purchase stocks.
What is the need for such automation?
Stock markets can be a volatile space. Buying or selling a certain stock at the right time could result in profits if done correctly.
Let’s see how much precision can be achieved using the Webull API and Python.
Installing the Package
This module is NOT a part of the Python Standard Library. Download the package manually using PIP. This package is an open-source project, refer to it here.
Installation Command for Webull 0.4.7
pip install webull
orpython3 -m pip install webull
Logging Into Your Webull Account
Standard Login
You must log in to your Webull account in order to perform any operation. Let’s refer to the following program.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
Mobile Login
For accounts associated with mobile numbers, run this command
from webull import webull # for paper trading, import 'paper_webull'
wb = webull()
wb.login('+91 1234567890', 'myPassword2022')
The phone number must be in the following format
+[country code]-[phone number]
How to Buy or Sell Stock Using Webull Python Package
Let’s look at how we can order stocks in the Webull platform using the module.
With the help of .place_order()
from the Webull python package, this is achieved. The function takes 3 parameters – stock, price, and qty
The stock parameter requires the company’s ticker or stock symbol (ex: AAPL – Apple Inc.)
The price parameter should mention the amount invested in ordering the stock. Expects a float
value.
The qty parameter represents the number of ordered stocks. Expects an int
value
NOTE: A valid Webull Trade Token is required for upcoming operations.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.place_order(stock='TSLA', price=90.0, qty=3)
To sell Stocks, set action
to SELL
. Specify ordertype
as LMT
(Limit Orders), MKT
(Market Orders) , STP
(Straight Through Processing) , STP LMT
(Stop Limit Order), or STP TRAIL
(Trailing Stop).
How To Buy Or Sell Cryptocurrencies Using Webull
Python Webull provides options to buy block-chain verified Cryptocurrencies. Let’s how this is achieved using the place_order_crypto()
function.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.place_order_crypto(stock='ETH-USD', price='1500.50', quant='1.5', action='BUY', entrust_type='QTY') # Buying Ethereum (USD)
To sell Crypto set action
to SELL
. Specify ordertype
as LMT
(Limit Orders) or MKT
(Market Orders) as well.
How To Verify Your Standing Orders in Webull Python Module
After ordering, you can view all your orders using .get_current_orders()
function.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
myOrders = wb.get_current_orders()
The myOrders
variable will consist of all information on current orders.
How to Modify Your Standing Orders in Webull Python Module
You can change the details of your standing orders using the modify_order()
function. Let’s refer to the following program.
Modifiable parameters are:
action
– BUY / SELLordertype
– LMT / MKT / STP / STP LMT / STP TRAILtimeinforce
– GTC / DAY / IOCoutsideRegularTradingHour
–True
/False
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725') # Example Token
wb.modify_order(order_id='ID_2232345', action='BUY', ordertype='MKT', timeinforce='GTC', outsideRegularTradingHour=True) # Example order_id
How To Call Off Your Standing Orders in Webull Python Module?
Cancel a standing order using cancel_order()
function. Expects only one parameter order_id
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.cancel_order(order_id='ID_2232345') # Example ID
NOTE: Only one order can be canceled per function call
If you’ve decided to cancel all standing orders, you can do so by using the .cancel_all_orders()
. Does NOT expect any parameters.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.cancel_all_orders()
How To Display ETF Holdings For Each Stock
Exchange Traded Funds(ETF) for each stock can be displayed using the get_etf_holding()
function. Let’s refer to the following program.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.get_etf_holding(stock='AAPL', has_num=0, count=20)
This will generate a list of ETF holdings for Apple Inc.
How To Display Institutional Holdings for Each Stock
Institutional Holdings are stocks owned by mutual funds, investment firms, insurance companies, private foundations, or other large corporations that manage funds. Using get_institutional_holding()
, we can display the information.
The function expects either a stock symbol or stock ID.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.get_institutional_holding(stock='AAPL')
This program generates a list of institutional holdings for Apple Inc.
How To Display Financial Information of a Stock
get_financials()
displays the financial information of stock. The function expects one parameter stock
or tId
.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.get_financials(stock='GOOGL')
Generates a dictionary of financial information for Alphabet Inc. shares.
How To Display Your Order History in Webull Python Module
get_history_orders()
provides information on all orders placed on your Webull account.
The orders can be filtered based on their current standing using status
. The options are:
- Canceled
- Filled
- Working
- Partially Filled
- Pending
- Failed
- All
count
represents the maximum number of orders to be displayed.
from webull import webull
wb = webull()
wb.login('[email protected]', 'myPassword2022')
wb.get_trade_token('220725')
wb.get_history_orders(status='All', count=20)
The program returns a JSON response consisting of a maximum of 20 order histories.
FAQs on Webull Python Package
cancel_order()
cancels a single order whereas cancel_all_orders()
cancels all standing orders.
alerts_add()
allows you to create alerts based on the financial information of a share. The frequency of the alert can be modified to your needs.
Conclusion
This article has gone through the Python Webull module. Webull provides an API that allows us to automate stock purchases and provides real-time information on the stock. This module can be essential in the stock markets as correctly timed purchases with accurate information are essential.