tedchou12 / webull

Unofficial APIs for Webull.
MIT License
597 stars 181 forks source link

get_activities #349

Closed shalli2 closed 7 months ago

shalli2 commented 1 year ago

Getting "405 response" for get_activities. get_history_orders() is also not working. get_account works with the same setup/tokens.

tedchou12 commented 1 year ago

It seems like I can get both of the endpoints working...

shalli2 commented 1 year ago

It seems like I can get both of the endpoints working...

can you post the code for get_activities or get_history_orders, get_account() works for me but not the other two? My code is below: wb = webull() f = None credential_data = None try:

if this fails, delete wb_token.txt and run again, enter MFA code sent to email. this will create new wb_token.txt

f = open("wb_token.txt", "r") credential_data = json.load(f) except: print("First time login to webull.") pass if credential_data is None:

If first time save login as token

print(wb.get_mfa(wb_user)) print(wb.get_security(wb_user)) mfa_code = input("MFA Code: ") credential_data = wb.login(...) f = open("wb_token.txt", "w") f.write(json.dumps(credential_data)) f.close() data = wb.get_account() else: wb._refresh_token = credential_data['refreshToken'] wb._access_token = credential_data['accessToken'] wb._token_expire = credential_data['tokenExpireTime'] wb._uuid = credential_data['uuid'] n_data = wb.refresh_login() credential_data['refreshToken'] = n_data['refreshToken'] credential_data['accessToken'] = n_data['accessToken'] credential_data['tokenExpireTime'] = n_data['tokenExpireTime'] if credential_data is not None: file = open('wb_token.txt', 'w') json.dump(credential_data, file) file.close() data_h = wb.get_history_orders() data_a = wb.get_account()

tedchou12 commented 1 year ago

can you format your code?

shalli2 commented 1 year ago

can you format your code?

Here it is.. sample-webull.py.txt

tedchou12 commented 1 year ago

you can get a output on line 36?

tedchou12 commented 1 year ago

you dont seem to have line 32 to 36 indented...

shalli2 commented 1 year ago

you dont seem to have line 32 to 36 indented...

Hi, I missed indentation there when I was sending it to you. That is not the problem, it works for get_account but not for other two.

tedchou12 commented 1 year ago

your code works for me. What is the output for get_account() ?

shalli2 commented 1 year ago

your code works for me. What is the output for get_account() ?

Output is the account details and positions. Can you post your code that is working for you? I am using Ubuntu 20.04 version

tedchou12 commented 1 year ago

The code:

import json
from webull_package.webull import webull

wb = webull()
f = None
credential_data = None
try:
    # if this fails, delete wb_token.txt and run again, enter MFA code sent to email. this will create new wb_token.txt
    f = open("webull_credentials.json", "r")
    credential_data = json.load(f)
except:
    print("First time login to webull.")
    pass

if credential_data is None:
    # If first time save login as token
    print(wb.get_mfa(wb_user))
    print(wb.get_security(wb_user))
    mfa_code = input("MFA Code: ")
    credential_data = wb.login(...)
    f = open("webull_credentials.json", "w")
    f.write(json.dumps(credential_data))
    f.close()
    data = wb.get_account()
else:
    wb._refresh_token = credential_data['refreshToken']
    wb._access_token = credential_data['accessToken']
    wb._token_expire = credential_data['tokenExpireTime']
    wb._uuid = credential_data['uuid']
    n_data = wb.refresh_login()
    credential_data['refreshToken'] = n_data['refreshToken']
    credential_data['accessToken'] = n_data['accessToken']
    credential_data['tokenExpireTime'] = n_data['tokenExpireTime']
    if credential_data is not None:
        file = open('webull_credentials.json', 'w')
        json.dump(credential_data, file)
        file.close()
        data_h = wb.get_history_orders()
        data_a = wb.get_account()

        print(data_h)
tedchou12 commented 1 year ago

output:

mac@TeddeMBP webull_demo % python3 sample-webull.py
[{'comboTickerType': 'stock', 'outsideRegularTradingHour': False, 'orders': [{'orderId': 5232419828886612120, 'tickerType': 'EQUITY', 'ticker': {'tickerId': 913256135, 'symbol': 'AAPL', 'name': 'Apple Inc', 'tinyName': 'Apple Inc', 'listStatus': 1, 'exchangeCode': 'NSQ', 'exchangeId': 96, 'type': 2, 'regionId': 6, 'currencyId': 247, 'currencyCode': 'USD', 'secType': [61], 'disExchangeCode': 'NASDAQ', 'disSymbol': 'AAPL'}, 'action': 'BUY', 'orderType': 'MKT', 'totalQuantity': '0.01', 'tickerId': 913256135, 'timeInForce': 'DAY', 'optionExercisePrice': '0.00', 'filledQuantity': '0', 'entrustType': 'QTY', 'placeAmount': '0', 'filledAmount': '0', 'remainAmount': '0', 'statusCode': 'Failed', 'statusStr': 'Failed', 'symbol': 'AAPL', 'optionContractMultiplier': '0', 'optionContractDeli...}

which looked fine

shalli2 commented 1 year ago

output:

mac@TeddeMBP webull_demo % python3 sample-webull.py
[{'comboTickerType': 'stock', 'outsideRegularTradingHour': False, 'orders': [{'orderId': 5232419828886612120, 'tickerType': 'EQUITY', 'ticker': {'tickerId': 913256135, 'symbol': 'AAPL', 'name': 'Apple Inc', 'tinyName': 'Apple Inc', 'listStatus': 1, 'exchangeCode': 'NSQ', 'exchangeId': 96, 'type': 2, 'regionId': 6, 'currencyId': 247, 'currencyCode': 'USD', 'secType': [61], 'disExchangeCode': 'NASDAQ', 'disSymbol': 'AAPL'}, 'action': 'BUY', 'orderType': 'MKT', 'totalQuantity': '0.01', 'tickerId': 913256135, 'timeInForce': 'DAY', 'optionExercisePrice': '0.00', 'filledQuantity': '0', 'entrustType': 'QTY', 'placeAmount': '0', 'filledAmount': '0', 'remainAmount': '0', 'statusCode': 'Failed', 'statusStr': 'Failed', 'symbol': 'AAPL', 'optionContractMultiplier': '0', 'optionContractDeli...}

which looked fine

What is your setup? OS and versions?

shalli2 commented 1 year ago

output:

mac@TeddeMBP webull_demo % python3 sample-webull.py
[{'comboTickerType': 'stock', 'outsideRegularTradingHour': False, 'orders': [{'orderId': 5232419828886612120, 'tickerType': 'EQUITY', 'ticker': {'tickerId': 913256135, 'symbol': 'AAPL', 'name': 'Apple Inc', 'tinyName': 'Apple Inc', 'listStatus': 1, 'exchangeCode': 'NSQ', 'exchangeId': 96, 'type': 2, 'regionId': 6, 'currencyId': 247, 'currencyCode': 'USD', 'secType': [61], 'disExchangeCode': 'NASDAQ', 'disSymbol': 'AAPL'}, 'action': 'BUY', 'orderType': 'MKT', 'totalQuantity': '0.01', 'tickerId': 913256135, 'timeInForce': 'DAY', 'optionExercisePrice': '0.00', 'filledQuantity': '0', 'entrustType': 'QTY', 'placeAmount': '0', 'filledAmount': '0', 'remainAmount': '0', 'statusCode': 'Failed', 'statusStr': 'Failed', 'symbol': 'AAPL', 'optionContractMultiplier': '0', 'optionContractDeli...}

which looked fine

What is your setup? OS and versions?

Can you also send your webull.py and endpoints.py files?

tedchou12 commented 1 year ago

I don't think OS makes a difference.

The files I have used are the latest files in the package, just update it is fine.