Xbase++
Xbase++
ETrade List Orders
See more ETrade Examples
Gets the order details for a selected brokerage account based on the search criteria provided.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJsonToken
LOCAL cSandboxUrl
LOCAL cLiveUrl
LOCAL oResp
LOCAL oXml
LOCAL nOrderId
LOCAL cDetails
LOCAL cOrderType
LOCAL j
LOCAL nCount_j
LOCAL cPlacedTime
LOCAL cOrderValue
LOCAL cStatus
LOCAL cOrderTerm
LOCAL cPriceType
LOCAL cLimitPrice
LOCAL nStopPrice
LOCAL cMarketSession
LOCAL cAllOrNone
LOCAL k
LOCAL nCount_k
LOCAL cSymbol
LOCAL cSecurityType
LOCAL cCallPut
LOCAL nExpiryYear
LOCAL nExpiryMonth
LOCAL nExpiryDay
LOCAL cStrikePrice
LOCAL cSymbolDescription
LOCAL cOrderAction
LOCAL cQuantityType
LOCAL nOrderedQuantity
LOCAL nFilledQuantity
LOCAL cAverageExecutionPrice
LOCAL cEstimatedCommission
LOCAL nEstimatedFees
LOCAL nNetPrice
LOCAL nNetBid
LOCAL nNetAsk
LOCAL nGcd
LOCAL nOrderNumber
LOCAL nBracketedLimitPrice
LOCAL cInitialStopPrice
LOCAL cExecutedTime
LOCAL cTotalOrderValue
LOCAL cTotalCommission
LOCAL cMarker
LOCAL cNext
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oHttp:OAuth1 := 1
oHttp:OAuthVerifier := ""
oHttp:OAuthConsumerKey := "ETRADE_CONSUMER_KEY"
oHttp:OAuthConsumerSecret := "ETRADE_CONSUMER_SECRET"
// Load the access token previously obtained via the OAuth1 Authorization
oJsonToken := CreateObject("Chilkat.JsonObject")
nSuccess := oJsonToken:LoadFile("qa_data/tokens/etrade.json")
IF (nSuccess != 1)
? "Failed to load OAuth1 token"
oHttp:destroy()
oJsonToken:destroy()
RETURN
ENDIF
oHttp:OAuthToken := oJsonToken:StringOf("oauth_token")
oHttp:OAuthTokenSecret := oJsonToken:StringOf("oauth_token_secret")
cSandboxUrl := "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders"
cLiveUrl := "https://api.etrade.com/v1/accounts/{$accountIdKey}/orders"
oHttp:SetUrlVar("accountIdKey", "6_Dpy0rmuQ9cu9IbTfvF2A")
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("GET", cSandboxUrl, oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJsonToken:destroy()
oResp:destroy()
RETURN
ENDIF
// Make sure a successful response was received.
IF (oResp:StatusCode > 200)
? oResp:StatusLine
? oResp:Header
? oResp:BodyStr
oHttp:destroy()
oJsonToken:destroy()
oResp:destroy()
RETURN
ENDIF
// Sample XML response:
// Use this online tool to generate parsing code from sample XML:
// Generate Parsing Code from XML
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <OrdersResponse>
// <marker>12345678999</marker>
// <next>https://api.sit.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders?marker=12345678999</next>
// <Order>
// <orderId>479</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/479</details>
// <orderType>OPTN</orderType>
// <OrderDetail>
// <placedTime>123453456</placedTime>
// <orderValue>123.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>1.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>RIMM</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>3</expiryMonth>
// <expiryDay>9</expiryDay>
// <strikePrice>12</strikePrice>
// </Product>
// <symbolDescription>RESEARCH IN MOTION LTD COM</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>5</orderedQuantity>
// <filledQuantity>5</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// <Order>
// <orderId>477</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/477</details>
// <orderType>ONE_CANCELS_ALL</orderType>
// <totalOrderValue>209.99</totalOrderValue>
// <totalCommission>10.74</totalCommission>
// <OrderDetail>
// <orderNumber>1</orderNumber>
// <placedTime>1331699203122</placedTime>
// <orderValue>123.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>2</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <bracketedLimitPrice>2</bracketedLimitPrice>
// <initialStopPrice>2</initialStopPrice>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>ETFC</symbol>
// <securityType>EQ</securityType>
// </Product>
// <symbolDescription>ETRADE Financials</symbolDescription>
// <orderAction>BUY</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>100</orderedQuantity>
// <filledQuantity>0</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// <OrderDetail>
// <orderNumber>2</orderNumber>
// <placedTime>1331699203</placedTime>
// <orderValue>231.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>0.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <initialStopPrice>0.5</initialStopPrice>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>MON</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>4</expiryMonth>
// <expiryDay>21</expiryDay>
// <strikePrice>85</strikePrice>
// </Product>
// <symbolDescription>MON Mar 9 '12 $85 Call</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>1</orderedQuantity>
// <filledQuantity>0</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// <Order>
// <orderId>475</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/475</details>
// <orderType>SPREADS</orderType>
// <OrderDetail>
// <placedTime>1331742953</placedTime>
// <executedTime>1331742955432</executedTime>
// <orderValue>4445.99</orderValue>
// <status>EXECUTED</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>NET_DEBIT</priceType>
// <limitPrice>1.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>REE</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>7</expiryMonth>
// <expiryDay>21</expiryDay>
// <strikePrice>7</strikePrice>
// </Product>
// <symbolDescription>REE Jul 21 '12 $7 Call</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>2</orderedQuantity>
// <filledQuantity>2</filledQuantity>
// <averageExecutionPrice>1.5</averageExecutionPrice>
// <estimatedCommission>7.24</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <Instrument>
// <Product>
// <symbol>REE</symbol>
// <securityType>OPTN</securityType>
// <callPut>PUT</callPut>
// <expiryYear>2013</expiryYear>
// <expiryMonth>1</expiryMonth>
// <expiryDay>19</expiryDay>
// <strikePrice>12.50</strikePrice>
// </Product>
// <symbolDescription>REE Jan 19 '13 $12.50 Put</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>2</orderedQuantity>
// <filledQuantity>2</filledQuantity>
// <averageExecutionPrice>1.5</averageExecutionPrice>
// <estimatedCommission>7.24</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// </OrdersResponse>
//
oXml := CreateObject("Chilkat.Xml")
oXml:LoadXml(oResp:BodyStr)
? oXml:GetXml()
cMarker := oXml:GetChildContent("marker")
cNext := oXml:GetChildContent("next")
i := 0
nCount_i := oXml:NumChildrenHavingTag("Order")
DO WHILE i < nCount_i
oXml:I := i
nOrderId := oXml:GetChildIntValue("Order[i]|orderId")
cDetails := oXml:GetChildContent("Order[i]|details")
cOrderType := oXml:GetChildContent("Order[i]|orderType")
j := 0
nCount_j := oXml:NumChildrenHavingTag("Order[i]|OrderDetail")
DO WHILE j < nCount_j
oXml:J := j
cPlacedTime := oXml:GetChildContent("Order[i]|OrderDetail[j]|placedTime")
cOrderValue := oXml:GetChildContent("Order[i]|OrderDetail[j]|orderValue")
cStatus := oXml:GetChildContent("Order[i]|OrderDetail[j]|status")
cOrderTerm := oXml:GetChildContent("Order[i]|OrderDetail[j]|orderTerm")
cPriceType := oXml:GetChildContent("Order[i]|OrderDetail[j]|priceType")
cLimitPrice := oXml:GetChildContent("Order[i]|OrderDetail[j]|limitPrice")
nStopPrice := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|stopPrice")
cMarketSession := oXml:GetChildContent("Order[i]|OrderDetail[j]|marketSession")
cAllOrNone := oXml:GetChildContent("Order[i]|OrderDetail[j]|allOrNone")
k := 0
nCount_k := oXml:NumChildrenHavingTag("Order[i]|OrderDetail[j]|Instrument")
DO WHILE k < nCount_k
oXml:K := k
cSymbol := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|symbol")
cSecurityType := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|securityType")
cCallPut := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|callPut")
nExpiryYear := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryYear")
nExpiryMonth := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryMonth")
nExpiryDay := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryDay")
cStrikePrice := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|strikePrice")
cSymbolDescription := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|symbolDescription")
cOrderAction := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|orderAction")
cQuantityType := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|quantityType")
nOrderedQuantity := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|orderedQuantity")
nFilledQuantity := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|filledQuantity")
cAverageExecutionPrice := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|averageExecutionPrice")
cEstimatedCommission := oXml:GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|estimatedCommission")
nEstimatedFees := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|estimatedFees")
k := k + 1
ENDDO
nNetPrice := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|netPrice")
nNetBid := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|netBid")
nNetAsk := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|netAsk")
nGcd := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|gcd")
nOrderNumber := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|orderNumber")
nBracketedLimitPrice := oXml:GetChildIntValue("Order[i]|OrderDetail[j]|bracketedLimitPrice")
cInitialStopPrice := oXml:GetChildContent("Order[i]|OrderDetail[j]|initialStopPrice")
cExecutedTime := oXml:GetChildContent("Order[i]|OrderDetail[j]|executedTime")
j := j + 1
ENDDO
cTotalOrderValue := oXml:GetChildContent("Order[i]|totalOrderValue")
cTotalCommission := oXml:GetChildContent("Order[i]|totalCommission")
i := i + 1
ENDDO
? "Success."
oHttp:destroy()
oJsonToken:destroy()
oResp:destroy()
oXml:destroy()