Skip to content

For Developers Contributors

Jason E Rush edited this page Nov 17, 2023 · 3 revisions

Firstly, thank you for your contributions! Sorry that it takes some time to review or merge the codes because I am running this as my hobby.

For the developers/contributors, be careful not to upload sensitive information (your username, password, tokens, pins, etc) to this public repository. I recommend that you have a separate file outside of the Webull folder that looks something like this:

from webull.webull import webull
from webull.streamconn import StreamConn
from pytz import timezone

webull = webull()
webull.login('ted_chou@example.com', 'pa$$w0rd')
webull.get_trade_token('000000')

nyc = timezone('America/New_York')
def on_price_message(topic, data):
    print (data)
    print(f"Ticker: {topic['tickerId']}, Price: {data['deal']['price']}, Volume: {data['deal']['volume']}", end='', sep='')
    if 'tradeTime' in data:
        print(', tradeTime: ', data['tradeTime'])
    else:
        tradetime = data['deal']['tradeTime']
        current_dt = datetime.today().astimezone(nyc)
        ts = current_dt.replace(hour=int(tradetime[:2]), minute=int(tradetime[3:5]), second=0, microsecond=0)
        print(', tradeTime: ', ts)

def on_order_message(topic, data):
    print(data)


conn = StreamConn(debug_flg=True)
# set these to a processing callback where your algo logic is
conn.price_func = on_price_message
conn.order_func = on_order_message

if not webull.access_token is None and len(webull.access_token) > 1:
    conn.connect(webull.did, access_token=webull.access_token)
else:
    conn.connect(webull.did)

conn.subscribe(tId='913256135') #AAPL
conn.run_loop_once()
conn.run_blocking_loop() #never returns till script crashes or exits

This way, when you upload your push to the repository, you will not upload your credentials by accident. In addition, you can also use .gitignore and save the credentials there.