jessecooper / pyetrade

Python E-Trade API Wrapper
GNU General Public License v3.0
209 stars 97 forks source link

Preview Equity Order issue - requests.exceptions.HTTPError: 400 Client Error: Bad Request for url #48

Closed lopez1364 closed 3 years ago

lopez1364 commented 3 years ago

I've tried switching from accountKey to accountID and still the same response. I've tried XML and JSON. No changes.

CODE:

def OrderPreview(symbol,quantity,orderAction="BUY",priceType="MARKET",marketSession="REGULAR",orderTerm="GOOD_FOR_DAY"): client_order_id = random.randint(1000000000, 9999999999) accountID = AccountKey()

order_spec = {
        'resp_format': 'xml','accountId': str(accountID),
        'symbol': str(symbol),'orderAction': str(orderAction),
        'clientOrderId': str(client_order_id),'priceType': str(priceType),
        'quantity': int(quantity),'marketSession': str(marketSession),
        'orderTerm': str(orderTerm)
        }

orders = pyetrade.ETradeOrder(
        consumer_key,
        consumer_secret,
        tokens['oauth_token'],
        tokens['oauth_token_secret'],
        #dev=True
        dev=False
        )
orderpreview = orders.preview_equity_order(**order_spec)

ERROR: orderpreview = orders.preview_equity_order(**order_spec) File "/usr/local/lib/python3.6/dist-packages/pyetrade/order.py", line 322, in preview_equity_order return self.perform_request(self.session.post, resp_format, api_url, payload) File "/usr/local/lib/python3.6/dist-packages/pyetrade/order.py", line 201, in perform_request req.raise_for_status() File "/usr/local/lib/python3.6/dist-packages/requests/models.py", line 943, 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/XXXXXXXXXXXXXXXXX/orders/preview

lopez1364 commented 3 years ago

Disregard. This was an issue with purchasing penny stocks. Works as expected.