How to use webull - 7 common examples

To help you get started, we’ve selected a few webull examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tedchou12 / webull / tests / test_webull.py View on Github external
def test_login(self):
        webull_obj = webull.webull()
        assert True == webull_obj.login_prompt()
github tedchou12 / webull / tests / test_webull.py View on Github external
def test_logout(self):
        webull_obj = webull.webull()
        print("Login success: {}".format(webull_obj.login_prompt()))
        assert True == webull_obj.logout()
github tedchou12 / webull / webull / webull.py View on Github external
def __init__(self):
        self._session = requests.session()
        self._headers = {
            'Accept': '*/*',
            'Accept-Encoding': 'gzip, deflate',
            'Content-Type': 'application/json',
        }
        self._access_token = ''
        self._account_id = ''
        self._refresh_token = ''
        self._token_expire = ''
        self._trade_token = ''
        self._uuid = ''
        self._did = self._get_did()
        self._urls = endpoints.urls()
github tedchou12 / webull / webull / webull.py View on Github external
headers = self.build_req_headers()

        response = requests.get(self._urls.social_home(topic, num), headers=headers)
        result = response.json()
        return result


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Interface with Webull. Paper trading is not the default.')
    parser.add_argument('-p', '--use-paper', help='Use paper account instead.', action='store_true')
    args = parser.parse_args()

    if args.use_paper:
        wb = paper_webull()
    else:
        wb = webull()
github tedchou12 / webull / webull / webull.py View on Github external
response = requests.get(self._urls.rankings(), params=params, headers=headers)
        result = response.json()[0].get('data')
        if extendTrading:
            for data in result:
                if data['id'] == 'latestActivityPc.faList':
                    rank = data['data']
        else:
            for data in result:
                if data['id'] == 'latestActivityPc.5minutes':
                    rank = data['data']
        return rank



''' Paper support '''
class paper_webull(webull):

    def __init__(self):
        super().__init__()

    def get_account(self):
        ''' Get important details of paper account '''
        headers = self.build_req_headers()
        response = requests.get(self._urls.paper_account(self._account_id), headers=headers)
        return response.json()

    def get_account_id(self):
        ''' Get paper account id: call this before paper account actions'''
        headers = self.build_req_headers()
        response = requests.get(self._urls.paper_account_id(), headers=headers)
        result = response.json()
        id = result[0]['id']
github tedchou12 / webull / webull / streamconn.py View on Github external
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
github tedchou12 / webull / webull / webull.py View on Github external
def get_social_home(self, topic, num=100):
        headers = self.build_req_headers()

        response = requests.get(self._urls.social_home(topic, num), headers=headers)
        result = response.json()
        return result


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Interface with Webull. Paper trading is not the default.')
    parser.add_argument('-p', '--use-paper', help='Use paper account instead.', action='store_true')
    args = parser.parse_args()

    if args.use_paper:
        wb = paper_webull()
    else:
        wb = webull()

webull

The unofficial python interface for the WeBull API

MIT
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis