tedchou12 / webull

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

Crypto order session expired #199

Closed fredflynn closed 2 years ago

fredflynn commented 3 years ago

Ted, this is a great piece of work, loving it for stocks! When I tried to buy/sell crypto I get the following, even though I was able to initialize, log in and pull positions right before this:

code: crypto_order = wb.place_order_crypto(stock="BTCUSD", price=45000, action='BUY', orderType='MKT', enforce='DAY', entrust_type='CASH', quant=1000, outsideRegularTradingHour=True)

result: {'msg': 'Your session has expired, please login again.', 'traceId': 'ad2f58b528864f6bb7b608380bb11ace', 'code': 'trade.token.expire', 'data': {}, 'success': False}

during init I am seeing positive login: 03/06/2021, 10:21:30 - Logging in to WeBull... say hello

Do I need to separate crypto to use a different login token?

PageMastr commented 3 years ago

Do you have a refresh loop in your code? Webull refreshes the token from time to time so its beneficial to have a loop so that while your using the software it refreshes the token every 5 minutes or so, to keep the login current. At least thats what has been working for me.

On Sat, Mar 6, 2021 at 9:31 AM fredflynn notifications@github.com wrote:

Ted, this is a great piece of work, loving it for stocks! When I tried to buy/sell crypto I get the following, even though I was able to initialize, log in and pull positions right before this:

code: crypto_order = wb.place_order_crypto(stock="BTCUSD", price=45000, action='BUY', orderType='MKT', enforce='DAY', entrust_type='CASH', quant=1000, outsideRegularTradingHour=True)

result: {'msg': 'Your session has expired, please login again.', 'traceId': 'ad2f58b528864f6bb7b608380bb11ace', 'code': 'trade.token.expire', 'data': {}, 'success': False}

during init I am seeing positive login: 03/06/2021, 10:21:30 - Logging in to WeBull... say hello

Do I need to separate crypto to use a different login token?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tedchou12/webull/issues/199, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACKJKQHFN6J5R7T5ZAAK7Z3TCJDD3ANCNFSM4YW2Q6AQ .

fredflynn commented 3 years ago

thanks for the hint, really appreciate it, but I dont think its a stale login. I did a simple script of logging in, executing a crypto trade and then a stock trade. The crypto fails, while stock works

code: crypto_order = wb.place_order_crypto(stock="BTCUSD", price=45000, action='BUY', orderType='MKT', enforce='DAY', entrust_type='CASH', quant=1000, outsideRegularTradingHour=True) stock_order = wb.place_order(stock='AMD', action='BUY', orderType='MKT', price=50, enforce='DAY', quant=50) print(crypto_order) print(stock_order)

output: {'msg': 'Your session has expired, please login again.', 'traceId': 'db1304d8054f478f99f9e63230bb4fba', 'code': 'trade.token.expire', 'data': {}, 'success': False} {'orderId': 33666761}

its just something about the crypto place order it doesn't like - I am going to keep digging!

tedchou12 commented 3 years ago

interesting. I just gave this a try, seems like there is no issue at all.

result = wb.place_order_crypto(stock='BTC', price=20000, action='BUY', orderType='LMT', enforce='GTC', quant=1)
print(result)

{'success': False, 'code': 'trade.webull.PRICE_TOO_FAR_THROUGH_MARKET', 'msg': 'The order price is more than 15% away from the mid price of this cryptocurrency. Please modify the order price to be closer.', 'data': {'lastSerialId': '6048f011c53xxxxxxxx8f'}}