pyetrade icon indicating copy to clipboard operation
pyetrade copied to clipboard

missing kwargs exception error when executing preview_equity_order

Open mkfrancis01 opened this issue 4 years ago • 2 comments

Getting 'Missing required parameters' error below

if not all(param in kwargs for param in mandatory): --> 135 raise OrderException 136 137 if kwargs["priceType"] == "STOP" and "stopPrice" not in kwargs

Below is the kwargs dictionary I am using in SandBox environment kwargs = { "accountId":"6_Dpy0rmuQ9cu9IbTfvF2A", "symbol":"AAPL", "orderAction":"BUY", "clientOrderId": random.randint(10000000,99999999), "priceType":"MARKET", "allOrNone": True, "limitPrice":0, "stopPrice":0, }

Looked through the ETradeOrder module but couldn't find any issue in the self.check function for the kwargs. Does anyone know how to resolve this? Or will it work if I test code in production environment?

mkfrancis01 avatar Jun 01 '20 07:06 mkfrancis01

@mkfrancis01 where you able to resolve this issue?

jessecooper avatar Dec 10 '21 16:12 jessecooper

I'm a rookie dev so idk if i understand your problem. However, I was having the same issue.

TLDR I was failing the params check, it was because I was passing kwargs as a dict (i.e kwargs={'foo': 'bar'}).
This is wrong, kwargs needs to be passed like so foo='bar'

This blog post helped me understand the difference: https://realpython.com/python-kwargs-and-args/ TLDR

I couldn't pass params check with : response = orders.place_option_order("json", kwargs={'accountId': 'XXXXXX', 'symbol': 'AAPL', 'callOrPut': 'CALL', 'strikePrice': 150, 'expiryDate': '2023-06-16', 'orderAction': 'BUY_OPEN', 'priceType': 'MARKET', 'quantity': 1, 'orderTerm': 'GOOD_UNTIL_CANCEL', 'marketSession': 'REGULAR', 'clientOrderId': 'AAPL230616C00150000' } )

That's because passing kwargs as a dict leads to kwargs = {kwargs: {}} consequently params in check_order is just ["kwargs", "securityType"] and that's why you fail the check.

The way that I got around this was calling the method like this: response = orders.place_option_order("json", accountId = payload.get('accountId'), symbol = payload.get('symbol'), callPut = payload.get('callOrPut'), strikePrice = payload.get('strikePrice'), expiryDate = payload.get('expiryDate'), orderAction = payload.get('orderAction'), priceType = payload.get('priceType'), quantity = payload.get('quantity'), orderTerm = payload.get('orderTerm'), marketSession = payload.get('marketSession'), clientOrderId = payload.get('clientOrderId'), )

kwargs is now what you'd imagine and I am passing the check.

Hope this helps

choneface avatar Dec 29 '21 22:12 choneface