pyetrade package¶
Submodules¶
pyetrade.accounts module¶
- class pyetrade.accounts.ETradeAccounts(client_key: str, client_secret: str, resource_owner_key: str, resource_owner_secret: str, dev: bool = True)[source]¶
Bases:
object
- Description:
Accounts object to access account information
- Parameters:
client_key (str, required) – Client key provided by Etrade
client_secret (str, required) – Client secret provided by Etrade
resource_owner_key (str, required) – Resource key from
pyetrade.authorization.ETradeOAuth
resource_owner_secret (str, required) – Resource secret from
pyetrade.authorization.ETradeOAuth
dev (bool, optional) – Defines Sandbox (True) or Live (False) ETrade, defaults to True
- EtradeRef:
https://apisb.etrade.com/docs/api/account/api-account-v1.html
- get_account_balance(account_id_key: str, account_type: str = None, real_time: bool = True, resp_format: str = 'xml') dict [source]¶
- Description:
Retrieves account balance for an account
- Parameters:
account_id_key (str, required) – AccountIDkey retrieved from
list_accounts
account_type (str, optional) – The registered account type, defaults to None
real_time (bool, optional) – Use real time balance or not, defaults to True
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
Balance of account with key
account_id_key
- Return type:
xml or json based on
resp_format
- EtradeRef:
https://apisb.etrade.com/docs/api/account/api-balance-v1.html
- get_account_portfolio(account_id_key: str, count: int = 50, sort_by: str = None, sort_order: str = 'DESC', page_number: int = None, market_session: str = 'REGULAR', totals_required: bool = False, lots_required: bool = False, view: str = 'QUICK', resp_format: str = 'xml') dict [source]¶
- Description:
Retrieves account portfolio for an account
- Parameters:
account_id_key (str, required) – AccountIDkey retrieved from
list_accounts
count (int, optional) – The number of positions to return in the response, defaults to 50
sort_by (str, optional) – Sorting done based on the column specified in the query parameter.
sort_order (str, optional) – Sort orders (ASC or DESC), defaults to DESC
page_number (int, optional) – The specific page that in the list that is to be returned. Each page has a default count of 50 positions.
market_session (str, optional) – The market session, defaults to REGULAR
totals_required (bool, optional) – It gives the total values of the portfolio, defaults to False
lots_required (bool, optional) – It gives position lots for positions, defaults to False
view (str, optional) – The view query, defaults to QUICK.
resp_format (str, optional) – Desired Response format, defaults to xml
- Market_session values:
REGULAR
EXTENDED
- View values:
PERFORMANCE
FUNDAMENTAL
OPTIONSWATCH
QUICK
COMPLETE
- Returns:
Account portfolio of account with key
account_id_key
- Return type:
xml or json based on
resp_format
- EtradeRef:
https://apisb.etrade.com/docs/api/account/api-portfolio-v1.html
- get_portfolio_position_lot(symbol: str, account_id_key: str, resp_format: str = 'xml') dict [source]¶
- Description:
Retrieves account portfolio position lot based on provided symbol
- Parameters:
symbol (str, required) – Desired equity symbol to search for position lots in desired account portfolio
account_id_key (str, required) – AccountIDkey retrieved from
list_accounts
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
PositionLot of
symbol
in account portfolio of account with keyaccount_id_key
- Return type:
xml or json based on
resp_format
- EtradeRef:
https://apisb.etrade.com/docs/api/account/api-portfolio-v1.html
- list_accounts(resp_format: str = 'xml') dict [source]¶
- Description:
Lists accounts in Etrade
- Parameters:
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
List of accounts
- Return type:
xml or json based on
resp_format
- EtradeRef:
https://apisb.etrade.com/docs/api/account/api-account-v1.html
- list_transaction_details(account_id_key: str, transaction_id: int, store_id: any = None, resp_format: str = 'xml') dict [source]¶
- Description:
Retrieves transaction details for an account
- Parameters:
account_id_key (str, required) – AccountIDKey retrieved from
list_accounts
transaction_id (int, required) – Numeric transaction ID obtained from
list_transactions
store_id (Unknown, optional) – storage location for older transactions
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
Transaction Details for
transaction_id
for account keyaccount_id_key
- Return type:
xml or json based on
resp_format
- EtradeRef:
https://apisb.etrade.com/docs/api/account/api-transaction-v1.html
- list_transactions(account_id_key: str, start_date: datetime = None, end_date: datetime = None, sort_order: str = 'DESC', marker: str = None, count: int = 50, resp_format: str = 'xml') dict [source]¶
- Description:
Retrieves transactions for an account
- Parameters:
account_id_key (str, required) – AccountIDKey retrieved from
list_accounts
start_date (datetime obj, optional) – The earliest date to include in the date range (history is available for two years), defaults to None
end_date (datetime obj, optional) – The latest date to include in the date range (history is available for two years), defaults to None
sort_order (str, optional) – The sort order request (ASC or DESC), default is DESC
marker (str, optional) – Specifies the desired starting point of the set of items to return (used for paging), default is None
count (int, optional) – Number of transactions to return in the response, default is 50
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
Transactions list for account with key
account_id_key
- Return type:
xml or json based on
resp_format
- EtradeRef:
https://apisb.etrade.com/docs/api/account/api-transaction-v1.html
pyetrade.alerts module¶
Alerts - ETrade Alerts API
- class pyetrade.alerts.ETradeAlerts(client_key: str, client_secret: str, resource_owner_key: str, resource_owner_secret: str, dev: bool = True)[source]¶
Bases:
object
- Description:
Object to retrieve alerts
- Parameters:
client_key (str, required) – Client key provided by Etrade
client_secret (str, required) – Client secret provided by Etrade
resource_owner_key (str, required) – Resource key from
pyetrade.authorization.ETradeOAuth
resource_owner_secret (str, required) – Resource secret from
pyetrade.authorization.ETradeOAuth
dev (bool, optional) – Defines Sandbox (True) or Live (False) ETrade, defaults to True
- EtradeRef:
- delete_alert(alert_id: int, resp_format: str = 'xml') dict [source]¶
- Description:
Deletes specified alert
- Parameters:
alert_id (int, required) – Alert ID obtained from
list_alerts
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
List of alert details
- Return type:
xml or json based on
resp_format
- EtradeRef:
- list_alert_details(alert_id: int, html_tags: bool = False, resp_format: str = 'xml') dict [source]¶
- Description:
Provides details for an alert
- Parameters:
alert_id (int, required) – Alert ID obtained from
list_alerts
html_tags (bool, optional) – The HTML tags on the alert, defaults to false. If set to true, it returns the alert details msgText with html tags.
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
List of alert details
- Return type:
xml or json based on
resp_format
- EtradeRef:
- list_alerts(count: int = 25, sort_order: str = 'DESC', resp_format: str = 'xml') dict [source]¶
- Description:
Lists alerts in Etrade
- Parameters:
count (int, optional) – The alert count, defaults to 25 (max 300)
sort_order (str, optional) – Sorting is done based on the createDate (ASC or DESC), defaults to DESC
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
List of alerts
- Return type:
xml
orjson
based onresp_format
- EtradeRef:
pyetrade.maket module¶
Market - ETrade Market API V1
- TODO:
move logger into object under self.logger
- class pyetrade.market.ETradeMarket(client_key: str, client_secret: str, resource_owner_key: str, resource_owner_secret: str, dev: bool = True)[source]¶
Bases:
object
- Description:
Performs Market functions
- Parameters:
client_key (str, required) – Client key provided by Etrade
client_secret (str, required) – Client secret provided by Etrade
resource_owner_key (str, required) – Resource key from
pyetrade.authorization.ETradeOAuth
resource_owner_secret (str, required) – Resource secret from
pyetrade.authorization.ETradeOAuth
dev (bool, optional) – Defines Sandboxi (True) or Live (False) ETrade, defaults to True
- EtradeRef:
- get_option_chains(underlier: str, expiry_date: ~.datetime.date, skip_adjusted: str = None, chain_type: str = None, strike_price_near: int = None, no_of_strikes: int = None, option_category: str = None, price_type: str = None, resp_format: str = 'xml') dict [source]¶
- Description:
Returns the option chain information for the requested expiry_date and chain-type in the desired format. This should be a list of dictionaries, one for each option chain.
- Parameters:
underlier (str, required) – Market Symbol
expiry_date (datetime.date(year, month, day), optional) – Contract expiration date, None produces closest to today
skip_adjusted (str, optional) – Specifies whether to show (True) or not show (False) adjusted options, defaults to True
chain_type (str, optional) – Type of option chain, defaults to call/put
strike_price_near (int, optional) – Option chains fetched will have strike price close to this value
no_of_strikes (int, optional) – Indicates number of strikes for which the option chain needs to be fetched, defaults to None
option_category (str, optional) – The option category, defaults to
standard
price_type (str, optional) – The price type, defaults to
atnm
resp_format (str, optional) – Desired Response format, defaults to
xml
- Returns:
Returns list of option chains for a specific underlying instrument
- Return type:
xml or json based on
resp_format
- Chain_type values:
put
call
call/put (default)
- Option_category values:
standard (default)
all
mini
- Price_type values:
atnm
all
- SampleURL:
- EtradeRef:
- get_option_expire_date(symbol: str, resp_format: str = 'xml') dict [source]¶
- Description:
Returns a list of dates suitable for structuring an option table display
- Parameters:
symbol (str, required) – Market Symbol
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
Returns expiry of options for symbol
- Return type:
xml or json based on
resp_format
- SampleURL:
https://api.etrade.com/v1/market/optionexpiredate?symbol=GOOG&expiryType=ALL
- EtradeRef:
- get_quote(symbols: list[str], detail_flag: str = None, require_earnings_date: str = None, skip_mini_options_check: str = None, resp_format: str = 'xml') dict [source]¶
- Description:
Get quote data on symbols provided in the list args.
- Parameters:
symbols (list[str], required) – Symbols in list args format. Limit 25.
detail_flag (str, optional) – Market fields returned from a quote request, defaults to None
require_earnings_date (str, optional) – Provides Earnings date if True, defaults to None
skip_mini_options_check (str, optional) – Skips mini options check if True, defaults to None
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
Returns quote data on symbols provided
- Return type:
xml or json based on
resp_format
- Symbols values:
Limited to 25. If exceeded, first 25 will be processed with warnings
Equities format -
symbol
name sufficient, e.g. GOOGL.Options format -
underlier:year:month:day:optionType:strikePrice
- Detailflag values:
fundamental - Instrument fundamentals and latest price
intraday - Performance for the current of most recent trading day
options - Information on a given option offering
week_52 - 52-week high and low (highest high and lowest low)
mf_detail - MutualFund structure gets displayed
all (default) - All of the above information and more
None - Defaults to all.
- SkipMiniOptionsCheck values:
True - Call is NOT made to check whether the symbol has mini options
False - Call is made to check whether the symbol has mini options
None - Call is made to check whether the symbol has mini options (default)
- EtradeRef:
- look_up_product(search_str: str, resp_format: str = 'xml') dict [source]¶
- Description:
Performs a look-up product
- Parameters:
search_str (str, required) – Full or partial name of the company.
resp_format (str, optional) – Desired Response format, defaults to xml
- Returns:
Product lookup
- Return type:
xml
orjson
as defined byresp_format
- Note:
Etrade abbreviates common words such as company, industry and systems and generally skips punctuation.
- EtradeRef:
https://apisb.etrade.com/docs/api/market/api-market-v1.html#/definition/Lookup
pyetrade.order module¶
- class pyetrade.order.ETradeOrder(client_key: str, client_secret: str, resource_owner_key: str, resource_owner_secret: str, dev: bool = True, timeout: int = 30)[source]¶
Bases:
object
- Description:
Object to perform Orders
- Parameters:
client_key (str, required) – Client key provided by Etrade
client_secret (str, required) – Client secret provided by Etrade
resource_owner_key (str, required) – Resource key from
pyetrade.authorization.ETradeOAuth
resource_owner_secret (str, required) – Resource secret from :class: pyetrade.authorization.ETradeOAuth
dev (bool, optional) – Defines Sandbox (True) or Live (False) ETrade, defaults to True
timeout (int, optional) – Timeout value for OAuth, defaults to 30
- EtradeRef:
- static build_order_payload(order_type: str, **kwargs) dict [source]¶
- Description:
Builds the POST payload of a preview or place order (Used internally)
- Parameters:
order_type (str, required) – PreviewOrderRequest or PlaceOrderRequest
- SecurityType:
EQ or OPTN
- OrderAction:
for OPTN: BUY_OPEN, SELL_CLOSE
- CallPut:
CALL or PUT
- ExpiryDate:
string, e.g. “2022-02-18”
- Returns:
Builds Order Payload
- Return type:
xml
orjson
based onresp_format
- EtradeRef:
- cancel_order(account_id_key: str, order_num: int, resp_format: str = 'xml') dict [source]¶
- Description:
Cancels a specific order for a given account
- Parameters:
account_id_key (str, required) – AccountIDkey retrieved from
pyetrade.accounts.ETradeAccounts.list_accounts
order_num (int, required) – Numeric id for this order listed in
list_orders
resp_format (str, required) – Desired Response format, defaults to xml
- Returns:
Confirmation of cancellation
- Return type:
dict/json
- EtradeRef:
- change_preview_equity_order(account_id_key: str, order_id: str, **kwargs) dict [source]¶
- Description:
Same as
preview_equity_order
with orderId- Parameters:
order_id (str, required) – order_id to modify, refer
list_orders
account_id_key (str, required) – account_id_key retrieved from
list_accounts
- Returns:
Previews Changed order with orderId for account with account_id_key
- Return type:
dict/json
- EtradeRef:
- static check_order(**kwargs)[source]¶
- Description:
Check that required params for preview or place order are there and correct
(Used internally)
- find_option_orders(account_id_key: str, symbol: str, call_put: str, expiry_date: str, strike_price: float) list [source]¶
- Description:
Lists option orders for a specific account ID Key
- Parameters:
account_id_key (str, required) – AccountIDKey from
pyetrade.accounts.ETradeAccounts.list_accounts
symbol (str, required) – ticker symbol for options chain
call_put (str, required) – whether the option is a call or put
expiry_date (str, required) – desired expiry of option (ex: 12-05-2021)
strike_price (str, required) – strike price of desired option
- Returns:
List of matching option orders in an account
- list_order_details(account_id_key: str, order_id: int, resp_format: str = 'json')[source]¶
- Description:
Lists order details of a specific account ID Key and order ID
- Parameters:
account_id_key (int, required) – AccountIDKey from
pyetrade.accounts.ETradeAccounts.list_accounts
order_id – Order ID of placed order, order IDs can be retrieved from calling the list_orders() function
resp_format (str, optional) – Desired Response format, defaults to json
- Returns:
List of orders for an account
- Return type:
xml
orjson
based onresp_format
- EtradeRef:
- list_orders(account_id_key: str, marker: str = None, count: int = 25, status: str = None, from_date: datetime = None, to_date: datetime = None, symbols: list[str] = None, security_type: str = None, transaction_type: str = None, market_session: str = 'REGULAR', resp_format: str = 'json') dict [source]¶
- Description:
Lists orders for a specific account ID Key
- Parameters:
account_id_key (str, required) – AccountIDKey from
pyetrade.accounts.ETradeAccounts.list_accounts
marker (str, optional) – Specifies the desired starting point of the set of items to return (defaults to None)
count (int, optional) – Number of transactions to return, defaults to 25 (max 100)
status (str, optional) – Order status (defaults to None)
from_date (datetime obj, optional) – The earliest date to include in the date range (history is available for two years). Both fromDate and toDate should be used together, toDate should be greater than fromDate. (defaults to None)
to_date (datetime obj, optional) – The latest date to include in the date range (history is available for two years). Both fromDate and toDate should be used together, toDate should be greater than fromDate. (defaults to None)
symbols (list[str], optional) – The market symbol(s) for the security being bought or sold. (defaults to None, Max 25 symbols)
security_type (str, optional) – The security type (defaults to None - Returns all types)
transaction_type (str, optional) – Type of transaction (defaults to None - Returns all types)
market_session (str, optional) – The market session, defaults to REGULAR
resp_format (str, optional) – Desired Response format, defaults to json
- Status values:
OPEN
EXECUTED
CANCELLED
INDIVIDUAL_FILLS
CANCEL_REQUESTED
EXPIRED
REJECTED
- Security_type values:
EQ
OPTN
MF
MMF
- Transaction_type values:
ATNM
BUY
SELL
SELL_SHORT
BUY_TO_COVER
MF_EXCHANGE
- Market_session values:
REGULAR
EXTENDED
- Returns:
List of orders for an account
- Return type:
xml
orjson
based onresp_format
- EtradeRef:
- perform_request(method, api_url: str, payload: dict | str, resp_format: str = 'xml') dict [source]¶
- Description:
POST or PUT request with json or xml used by preview, place and cancel
- Parameters:
method (session, required) – PUT or POST method
resp_format (str, required) – Desired Response format, defaults to xml
api_url (str, required) – API URL
payload (json/dict or str xml, required) – Payload
- Returns:
Return request
- Return type:
xml or json based on
resp_format
- EtradeRef:
- place_changed_equity_order(**kwargs) dict [source]¶
- Description:
Places changes to equity orders NOTE: the ETrade server will actually cancel the old orderId, and create a new orderId
- Parameters:
kwargs (
**kwargs
, required) – Parameters for api, referchange_preview_equity_order
- Returns:
Returns confirmation similar to
preview_equity_order
- Return type:
xml or json based on
resp_format
- EtradeRef:
- place_changed_option_order(**kwargs) dict [source]¶
- Description:
Places Option Order, only single leg CALL or PUT is supported for now
- Returns:
Returns confirmation of the equity order
- place_equity_order(**kwargs) dict [source]¶
- Description:
Places Equity Order
- Parameters:
kwargs (
**kwargs
, required) – Parameters for api, referpreview_equity_order
- Returns:
Returns confirmation of the equity order
- Return type:
xml or json based on
resp_format
- EtradeRef:
- place_option_order(**kwargs) dict [source]¶
- Description:
Places Option Order, only single leg CALL or PUT is supported for now
- Returns:
Returns confirmation of the equity order
- preview_equity_order(**kwargs) dict [source]¶
API is used to submit an order request for preview before placing it
- Parameters:
accountIdKey (str, required) – AccountIDkey retrieved from
list_accounts
symbol (str) – Market symbol for the security being bought or sold
orderAction (str, required) – Action that the broker is requested to perform
previewId (long, conditional) – Required only if order was previewed. Numeric preview ID from preview. Note - Other parameters much match that of preview
clientOrderId (str, required) – Reference number generated by developer. Used to ensure duplicate order is not submitted. Value can be of 20 alphanmeric characters or less Must be uniquewithin this account. Does not appear in any API responses.
priceType (str, required) – Type of pricing specified in equity order
limitPrice (double, conditional) – Highest to buy or lowest to sell. Required if priceType is STOP or STOP_LIMIT
stopPrice (double, conditional) – Price to buy or sell if specified in a stop order. Required if priceType is STOP or STOP_LIMIT
allOrNone (bool, optional) – Specifies if order must be executed all at once. TRUE triggers allOrNone, defaults to FALSE
quantity (int, required) – Number of shares to buy or sell
reserveOrder (bool, optional) – If set to TRUE, publicly displays only a limited number of shares (the reserve quantity), instead of the entire order, to avoid influencing other traders. If TRUE, must also specify the reserveQuantity, defaults to FALSE
reserveQuantity (int, conditional) – Number of shares to be publicly displayed if this is a reserve order. Required if reserveOrder is TRUE.
marketSession (str, required) – Session to place the equity order
orderTerm (str, required) – Term for which the order is in effect.
routingDestination (str, optional) – Exchange where the order should be executed.
estimatedCommission (double) – Cost billed to the user to preform requested action
estimatedTotalAmount (double) – Cost including commission
messageList (dict) – Container for messages describing the result of the action
msgDesc (str) – Text of the result message, indicating order status, success or failure, additional requirements that must be met before placing the order, etc. Applications typically display this message to the user, which may result in further user action
msgCode (int) – Standard numeric code of the result message. Refer to the Error Messages documentation for examples. May optionally be displayed to the user, but is primarily intended for internal use.
orderNum (int) – Numeric ID for this order in the E*TRADE system
orderTime (long) – The epoch time the order was submitted.
symbolDesc (str) – Text description of the security
symbol – The market symbol for the underlier
- OrderAction values:
BUY
SELL
BUY_TO_COVER
SELL_SHORT
- PriceType values:
MARKET
LIMIT - Requires limitPrice
STOP - Requires stopPrice
STOP_LIMIT - Requires limitPrice
MARKET_ON_CLOSE
- MarketSession values:
REGULAR
EXTENDED
- OrderTerm values:
GOOD_UNTIL_CANCEL
GOOD_FOR_DAY
IMMEDIATE_OR_CANCEL (only for LIMIT orders)
FILL_OR_KILL (only for LIMIT orders)
- RoutingDestination values:
AUTO (default)
ARCA
NSDQ
NYSE
- Returns:
Confirmation of the Preview Equity Order
- Return type:
xml
orjson
based onresp_format
- EtradeRef:
- exception pyetrade.order.OrderException(explanation=None, params=None)[source]¶
Bases:
Exception
- Description:
Exception raised when giving bad args to a method not from Etrade calls
Module contents¶
Init for pyetrade module