I'm trying to preview (and later on place) an equity order.
It seems authentication runs and I'm getting tokens.
This is the code I'm running (somehow code envioement scrambles the code):
oauth = pyetrade.ETradeOAuth(consumer_key1, consumer_secret1)
authorize_url = oauth.get_request_token()
webbrowser.open(authorize_url)
text_code = input('Please accept agreement and enter text code from browser: ')
token1 = oauth.get_access_token(text_code)
client_order_id = random.randint(1000000000, 9999999999)
order = pyetrade.ETradeOrder(consumer_key1,
consumer_secret1,
token1['oauth_token'],
token1['oauth_token_secret'], dev=False)
data = order.preview_equity_order(resp_format='json', accountId=account_id_key1, symbol='F',
orderAction='BUY', clientOrderId=client_order_id,
priceType='LIMIT', limitPrice=2.1, quantity=3,
marketSession='REGULAR',
orderTerm='GOOD_UNTIL_CANCEL')
and I'm getting this Traceback:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1448, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/Owner/PycharmProjects/stacky/etrade_api.py", line 94, in
data = order.preview_equity_order(resp_format='json', accountId=account_id_key1, symbol='F',
File "C:\Users\Owner\PycharmProjects\stacky\venv\lib\site-packages\pyetrade\order.py", line 485, in preview_equity_order
return self.perform_request(self.session.post, resp_format, api_url, payload)
File "C:\Users\Owner\PycharmProjects\stacky\venv\lib\site-packages\pyetrade\order.py", line 197, in perform_request
req.raise_for_status()
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.etrade.com/v1/accounts/_lSY20dXKIHRGpiJ6faoEQ/orders/preview
Hi,
I'm trying to preview (and later on place) an equity order. It seems authentication runs and I'm getting tokens. This is the code I'm running (somehow code envioement scrambles the code):
oauth = pyetrade.ETradeOAuth(consumer_key1, consumer_secret1) authorize_url = oauth.get_request_token() webbrowser.open(authorize_url) text_code = input('Please accept agreement and enter text code from browser: ') token1 = oauth.get_access_token(text_code) client_order_id = random.randint(1000000000, 9999999999) order = pyetrade.ETradeOrder(consumer_key1, consumer_secret1, token1['oauth_token'], token1['oauth_token_secret'], dev=False) data = order.preview_equity_order(resp_format='json', accountId=account_id_key1, symbol='F', orderAction='BUY', clientOrderId=client_order_id, priceType='LIMIT', limitPrice=2.1, quantity=3, marketSession='REGULAR', orderTerm='GOOD_UNTIL_CANCEL')
and I'm getting this Traceback:
Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1448, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/Owner/PycharmProjects/stacky/etrade_api.py", line 94, in
data = order.preview_equity_order(resp_format='json', accountId=account_id_key1, symbol='F',
File "C:\Users\Owner\PycharmProjects\stacky\venv\lib\site-packages\pyetrade\order.py", line 485, in preview_equity_order
return self.perform_request(self.session.post, resp_format, api_url, payload)
File "C:\Users\Owner\PycharmProjects\stacky\venv\lib\site-packages\pyetrade\order.py", line 197, in perform_request
req.raise_for_status()
File "C:\Users\Owner\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.etrade.com/v1/accounts/_lSY20dXKIHRGpiJ6faoEQ/orders/preview
Your help will be greatly appreciated.