Sample code for 30+ languages & platforms
AutoIt

ETrade v1 List Orders

See more HTTP Misc Examples

Gets the order details for a selected brokerage account based on the search criteria provided.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oHttp = ObjCreate("Chilkat.Http")

$oHttp.OAuth1 = True
$oHttp.OAuthVerifier = ""
$oHttp.OAuthConsumerKey = "ETRADE_CONSUMER_KEY"
$oHttp.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"

; Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2.
$oJson = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oJson.LoadFile("qa_data/tokens/etrade.json")
If ($bSuccess <> True) Then
    ConsoleWrite("Failed to load OAuth1 token" & @CRLF)
    Exit
EndIf

$oHttp.OAuthToken = $oJson.StringOf("oauth_token")
$oHttp.OAuthTokenSecret = $oJson.StringOf("oauth_token_secret")

; See the ETrade v1 API documentation HERE.

$oHttp.SetUrlVar("accountIdKey","vsnhtF7d9jXxBy6HyaAC4vQ")
Local $sRespStr = $oHttp.QuickGetStr("https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders?securityType=EQ&count=100")
If ($oHttp.LastMethodSuccess <> True) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

; A 200 status code indicates success.
Local $iStatusCode = $oHttp.LastStatus
ConsoleWrite("statusCode = " & $iStatusCode & @CRLF)

; Use the following online tool to generate parsing code from sample XML: 
; Generate Parsing Code from XML

; A sample XML response is shown below...

$oXml = ObjCreate("Chilkat.Xml")
$oXml.LoadXml($sRespStr)

Local $i
Local $iCount_i
Local $sTagPath
Local $iOrderId
Local $sDetails
Local $sOrderType
Local $sOrderDetail

$i = 0
$iCount_i = $oXml.NumChildrenHavingTag("Order")
While $i < $iCount_i
    $oXml.I = $i
    $iOrderId = $oXml.GetChildIntValue("Order[i]|orderId")
    $sDetails = $oXml.GetChildContent("Order[i]|details")
    $sOrderType = $oXml.GetChildContent("Order[i]|orderType")
    $sOrderDetail = $oXml.GetChildContent("Order[i]|OrderDetail")
    $i = $i + 1
Wend

; Sample XML Response
; <?xml version="1.0" encoding="UTF-8"?>
; <OrdersResponse>
;    <Order>
;       <orderId>96</orderId>
;       <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/96</details>
;       <orderType>EQ</orderType>
;       <OrderDetail>�</OrderDetail>
;    </Order>
;    <Order>
;       <orderId>95</orderId>
;       <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/95</details>
;       <orderType>EQ</orderType>
;       <OrderDetail>�</OrderDetail>
;    </Order>
;    <Order>
;       <orderId>94</orderId>
;       <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/94</details>
;       <orderType>EQ</orderType>
;       <OrderDetail>�</OrderDetail>
;    </Order>
;    <Order>
;       <orderId>93</orderId>
;       <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/93</details>
;       <orderType>EQ</orderType>
;       <OrderDetail>�</OrderDetail>
;    </Order>
; </OrdersResponse>