Introduction

This SDK provides an easy-to-use client for the E*TRADE REST API. It gives PHP developers a convenient, PHP-friendly way to take advantage of our REST API and the E*TRADE Developer Platform.

What you can do with E*TRADE PHP SDK

The PHP SDK allows you to programmatically execute trades directly through the E*TRADE REST API in your PHP application. It provides libraries for the following functional areas:

  • Authentication
  • Accounts
  • Market Data
  • Orders
Requirements

Our PHP SDK requires PHP version 5.2 or newer. You can download the latest version of PHP for your operating system at http://www.php.net. Your version of PHP must include curl lib support.

Additionally, our SDK requires Google's OAuth library for PHP. After you've installed the PHP SDK, download the OAuth library from http://oauth.googlecode.com/svn/code/php/OAuth.php (Subversion revision: 1263), and copy it into the SDK's OAuth folder.

Installation
  1. Download the PHP-SDK from the E*TRADE website to a local folder of your choice.
  2. Create a config.php file for your application. A sample config.php can be copied from the SDK's Samples directory.
  3. Include your local config.php at the top of your application.
  4. Include <SDK PATH>/Common/common.php immediately after that.

Once this is done, you can start using the SDK.

For details on data structures, data types, and other API details, consult the REST API reference documentation.

Using the Config file

The E*TRADE PHP SDK provides a default configuration file in the Common folder as config.php. This file provides the basic configurations required by the SDK. You can override any or all configuration values by creating your own config.php file under your application directory and including it at the start of your application.

Some key configuration settings are:
Config setting Description
ET_SDK_PATH Location of your PHP-SDK directory
DEBUG_MODE Use this setting to provide debug messages during development
RESPONSE_FORMAT Selects the format of responses returned by the API. Possible values are "xml" and "json".

The remaining configuration values provide URL's for using APIs. Please read config.php for details.

Libraries
The E*TRADE PHP SDK includes the following libraries to let you interface with the E*TRADE Developer Platform in PHP.
Library Description
etOAUTH Provides all functions needed for OAuth authorization
etAccounts Provides an interface to the E*TRADE Accounts API
MarketClient Provides an interface to the E*TRADE Market API
OrderClient Provides an interface to the E*TRADE Orders API
E*TRADE PHP Methods
OAuth
The E*TRADE Developer Platform uses the OAuth (1.0a) open authentication protocol. This library provides all the necessary OAuth functionality.
Class Constructor / Method Description
etOAuthConsumer   Provides a consumer object to use for OAuth operations
  __construct() Params: API key, API secret, callback method (optional; default is "oob")
Returns: etOAuthConsumer object
etOAuth   The etOAuth class provides the following methods to complete OAuth operations:
  __construct()
This is the class constructor; it constructs a request object using the consumer object, e.g.:
$consumer = new etOAuthConsumer('KEY','SECRET');
$request = new etOAuth($consumer);
  GetRequestToken()
Params: none
Returns: Array of request token values.
  GetAuthorizeURL() Params: none
Returns: String, authorize URL
  GetAccessToken()
Params: verifier code.
Returns: Array, access token
  RenewAccessToken() Params: none
Returns: xml message returned from API
  RevokeAccessToken () Params: none
Returns: xml message returned from API
Accounts
The Accounts library, "etAccounts", provides methods to access account-related resources. To call Accounts methods, you must have an access token.
Class Constructor / Method Description
etAccounts __construct()
Params: consumer object
Returns: etAccounts object
  GetAccountList()
Provides list of accounts for the user
Params: none
Returns: list of accounts as XML or JSON
  GetAccountBalance()
Provides account balance details
Params: account ID
Returns: account balance as XML or JSON
  GetAccountPositions()
Returns a list of account positions
Params: account ID, AccountPositionsRequest object
AccountPositionsRequest object properties are:
• count
• marker
• symbol
• typeCode
• callPut
• expYear
• expMonth
• expDay
• strikePrice
Returns: account positions as XML or JSON
For data type, options, and other details of each parameter, refer to the REST API reference.
  GetAlerts()
Provides list of alerts
Params: none
Returns: List of alerts as XML or JSON
  GetAlertDetails()
Provides alert details
Params: alert ID
Returns: Details of an alert as XML or JSON
  DeleteAlert()
Deletes an alert
Params: alert ID
Returns: string containing success or failure message from server
Market Data
The Market library, "MarketClient", provides an interface to the ETRADE Market API.
Class Constructor
/ Method
Description
MarketClient __construct()
Creates an object of MarketClient class, using consumer object
Params: consumer object
Returns: market client object
  getOptionChain()
Returns an option chain
Params: getOptionChainsParams object
Valid getOptionChainsParams properties:
• underlier
• chainType
• skipAdjusted
• expirationMonth
• expirationYear
Returns: option chains as XML or JSON
  productLookup()
Returns product details.
Params: productLookupParams object
Valid productLookupParams object properties
• company
• type
Returns: product detail as XML or JSON
  getExpiryDates()
Returns expiry dates of a product.
Params: getExpiryDateParams object.
Valid getExpiryDateParams properties:
• underlier
• expiryType
Returns: expiry date list as XML or JSON
  getQuote()
Returns a quote for a product.
Params: getExpiryDateParams object
Valid getExpiryDateParams properties:
• symbolList
• afterhourFlag
• detailFlag
Returns: quote detail as XML or JSON
Orders
The Orders library, "OrderClient", provides an interface for the ETRADE Orders API.
Class Constructor
/ Method
Description
OrderClient getOrderList()
Provides a list of orders that are open or were active during the current day
Params: Account ID
Returns: Orders list as XML or JSON
  previewEquityOrder()
Provides preview of an equity order.
Params: getExpiryDateParams object
Valid getExpiryDateParams properties:
• accountId
• clientOrderId
• limitPrice
• previewId
• stopPrice
• allOrNone
• quantity
• reserveOrder
• reserveQuantity
• stopLimitPrice
• symbol
• orderAction
• priceType
• routingDestination
• marketSession
• orderTerm
Returns: response as XML or JSON
  placeEquityOrder()
Places an equity order.
Params: getExpiryDateParams object
Valid getExpiryDateParams properties:
• accountId
• clientOrderId
• limitPrice
• previewId
• stopPrice
• allOrNone
• quantity
• reserveOrder
• reserveQuantity
• stopLimitPrice
• symbol
• orderAction
• priceType
• routingDestination
• marketSession
• orderTerm
Returns: response as XML or JSON
  previewOptionOrder()
Provides preview of an option order.
Params: OptionOrderRequest object.
Valid OptionOrderRequest properties:
• accountId
• clientOrderId
• limitPrice
• previewId
• stopPrice
• allOrNone
• quantity
• reserveOrder
• reserveQuantity
• stopLimitPrice
• symbolInfo ( object )
• orderAction
• priceType
• routingDestination
• marketSession
• orderTerm
Valid symbolInfo object properties:
• symbol
• callOrPut
• strikePrice
• expirationYear
• expirationMonth
• expirationDay
Returns: response as XML or JSON
  placeOptionOrder()
Returns expiry dates of a product.
Params: OptionOrderRequest object.
Valid OptionOrderRequest properties:
• accountId
• clientOrderId
• limitPrice
• previewId
• stopPrice
• allOrNone
• quantity
• reserveOrder
• reserveQuantity
• stopLimitPrice
• symbolInfo ( object )
• orderAction
• priceType
• routingDestination
• marketSession
• orderTerm
Valid symbolInfo object properties:
• symbol
• callOrPut
• strikePrice
• expirationYear
• expirationMonth
• expirationDay
Returns: response as XML or JSON
  previewChangeEquityOrder()
Provides preview of change to an equity order
Params: changeEquityOrderRequest object.
Valid changeEquityOrderRequest properties:
• priceType
• orderTerm
• accountId
• orderNum
• clientOrderId
• limitPrice
• previewId
• stopPrice
• allOrNone
• quantity
• reserveOrder
• reserveQuantity
Returns: response as XML or JSON
  previewChangeOptionOrder() Provides preview of change to an option order.
Params: changeOptionOrderRequest object
Valid changeOptionOrderRequest properties:
• stopLimitPrice
• priceType
• orderTerm
• accountId
• orderNum
• clientOrderId
• limitPrice
• previewId
• stopPrice
• allOrNone
• quantity
• reserveOrder
• reserveQuantity
Returns: response as XML or JSON
  placeChangeOptionOrder()
Executes change to an option order.
Params: changeOptionOrderRequest object
Valid changeOptionOrderRequest properties:
• stopLimitPrice
• priceType
• orderTerm
• accountId
• orderNum
• clientOrderId
• limitPrice
• previewId
• stopPrice
• allOrNone
• quantity
• reserveOrder
• reserveQuantity
Returns: response as XML or JSON
  cancelOrder() Cancels an order.
Params: CancelOrderRequest object
Valid CancelOrderRequest properties:
• accountId
• orderNum
Returns: response as XML or JSON
PLEASE READ THE IMPORTANT DISCLOSURES BELOW

By using E*TRADE API ("API") and accepting the terms of the Application Programming Interface License Agreement and the Application Programming Interface User Agreement, you agree that API may employ security policies, procedures and systems of Third Party providers which may or may not be less stringent and secure than the policies, procedures and systems of E*TRADE Securities LLC ("E*TRADE") or its affiliates. Material provided on API may have been produced by independent third parties not affiliated or endorsed by E*TRADE or its affiliates ("Third Party"). To the extent that API or Third Party providers express opinions or make recommendations, you understand that such opinions or recommendations are expressed by the Third Party provider and are not the opinions or recommendations of E*TRADE or its affiliates. E*TRADE is not responsible for the accuracy of market data displayed on API or made available by Third Party providers. There may be latency between the time an order (or other information) is submitted from API and the time the order is received by E*TRADE. The E*TRADE Two Second Execution Guarantee or any similar guarantee does not apply for orders placed through API and Third Party provider web sites. The E*TRADE CompleteTM Protection Guarantee does not apply. Orders created and submitted through API are not vetted until they are received by E*TRADE. It is possible that E*TRADE may reject an order placed through API. Please see the Application Programming Interface License Agreement and the Application Programming Interface User Agreement for more information.


The E*TRADE family of companies provides financial services including trading, investing, and related banking products and services to retail investors.


Securities products and services offered by E*TRADE Securities LLC, Member FINRA/SIPC.


System response and account access times may vary due to a variety of factors, including trading volumes, market conditions, system performance, and other factors.