Open arighna opened 3 years ago
https://apisb.etrade.com/docs/api/order/api-order-v1.html#/definition/orderPlace
make sure you are using the accountIdKey this area of code could use an update to align better with the terminology of V1 but it still works.
https://apisb.etrade.com/docs/api/order/api-order-v1.html#/definition/orderPlace
make sure you are using the accountIdKey this area of code could use an update to align better with the terminology of V1 but it still works.
Thank you for your response. I got passed the listing order section, thanks to your suggestion. I am more interested in the order placing post request though. Below is the error I am getting for the same.
AttributeError Traceback (most recent call last)
I accidentally closed the issue!
accountIdKey
is the 'accountIdKey' same as accountId?
'accountIdKey' and 'accountId' are different parameters on E-trade.
accountId | string | The user's account ID accountIdKey | string | The unique account key
Were you able to get the code to work?
'accountIdKey' and 'accountId' are different parameters on E-trade.
accountId | string | The user's account ID accountIdKey | string | The unique account key
Were you able to get the code to work?
I found the accountIdKey and I am able to list orders. However, I am not able to structure the payload dictionary. Below is what I am using to place the order.
api_url = f'https://apisb.etrade.com/v1/accounts/{account_id_key}/orders/place'
payload = { "accountId": str(account_id), "clientOrderId": str(clientOrderId), "limitPrice": str(limitPrice), "quantity": str(quantity), "symbol": symbol, "orderAction": orderAction, "priceType": "LIMIT", "marketSession": "REGULAR", "orderTerm": "GOOD_FOR_DAY" }
I am trying to place an equity order in the sandbox environment. I am able to list the accounts. However, I am probably going wrong with the payload. Below is the script I have put together for the same.
`
import pyetrade from requests_oauthlib import OAuth1Session
base_url = "https://apisb.etrade.com" account_id = 'account_id'
consumer_key = 'consumer_key' consumer_secret = 'consumer_secret'
oauth = pyetrade.ETradeOAuth(consumer_key, consumer_secret) print(oauth.get_request_token()) # Use the printed URL
verifier_code = input("Enter verification code: ") tokens = oauth.get_access_token(verifier_code) print(tokens)
accounts = pyetrade.ETradeAccounts( consumer_key, consumer_secret, tokens['oauth_token'], tokens['oauth_token_secret'] )
print(accounts.list_accounts())
orders = pyetrade.order.ETradeOrder(
consumer_key, consumer_secret, tokens['oauth_token'], tokens['oauth_token_secret'], dev=True )
account_id = 'account_id'
symbol = 'symbol'
orders.place_equity_order( accountId = account_id, symbol = symbol, orderAction="BUY", clientOrderId= "1a2b3c", priceType="MARKET", quantity=100, orderTerm="GOOD_UNTIL_CANCEL", marketSession="REGULAR", )
`
Below is the error I am getting.
`
HTTPError Traceback (most recent call last)