Sample code for 30+ languages & platforms
PowerBuilder

ETrade List Orders

See more ETrade Examples

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

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_JsonToken
string ls_SandboxUrl
string ls_LiveUrl
oleobject loo_Resp
oleobject loo_Xml
long li_OrderId
string ls_Details
string ls_OrderType
long j
long li_Count_j
string ls_PlacedTime
string ls_OrderValue
string ls_Status
string ls_OrderTerm
string ls_PriceType
string ls_LimitPrice
long li_StopPrice
string ls_MarketSession
string ls_AllOrNone
long k
long li_Count_k
string ls_Symbol
string ls_SecurityType
string ls_CallPut
long li_ExpiryYear
long li_ExpiryMonth
long li_ExpiryDay
string ls_StrikePrice
string ls_SymbolDescription
string ls_OrderAction
string ls_QuantityType
long li_OrderedQuantity
long li_FilledQuantity
string ls_AverageExecutionPrice
string ls_EstimatedCommission
long li_EstimatedFees
long li_NetPrice
long li_NetBid
long li_NetAsk
long li_Gcd
long li_OrderNumber
long li_BracketedLimitPrice
string ls_InitialStopPrice
string ls_ExecutedTime
string ls_TotalOrderValue
string ls_TotalCommission
string ls_Marker
string ls_Next
long i
long li_Count_i

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

loo_Http.OAuth1 = 1
loo_Http.OAuthVerifier = ""
loo_Http.OAuthConsumerKey = "ETRADE_CONSUMER_KEY"
loo_Http.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"

//  Load the access token previously obtained via the OAuth1 Authorization
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")

li_Success = loo_JsonToken.LoadFile("qa_data/tokens/etrade.json")
if li_Success <> 1 then
    Write-Debug "Failed to load OAuth1 token"
    destroy loo_Http
    destroy loo_JsonToken
    return
end if

loo_Http.OAuthToken = loo_JsonToken.StringOf("oauth_token")
loo_Http.OAuthTokenSecret = loo_JsonToken.StringOf("oauth_token_secret")

ls_SandboxUrl = "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders"
ls_LiveUrl = "https://api.etrade.com/v1/accounts/{$accountIdKey}/orders"

loo_Http.SetUrlVar("accountIdKey","6_Dpy0rmuQ9cu9IbTfvF2A")

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpNoBody("GET",ls_SandboxUrl,loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_Resp
    return
end if

//  Make sure a successful response was received.
if loo_Resp.StatusCode > 200 then
    Write-Debug loo_Resp.StatusLine
    Write-Debug loo_Resp.Header
    Write-Debug loo_Resp.BodyStr
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_Resp
    return
end if

//  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>
//  

loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")

loo_Xml.LoadXml(loo_Resp.BodyStr)
Write-Debug loo_Xml.GetXml()

ls_Marker = loo_Xml.GetChildContent("marker")
ls_Next = loo_Xml.GetChildContent("next")
i = 0
li_Count_i = loo_Xml.NumChildrenHavingTag("Order")
do while i < li_Count_i
    loo_Xml.I = i
    li_OrderId = loo_Xml.GetChildIntValue("Order[i]|orderId")
    ls_Details = loo_Xml.GetChildContent("Order[i]|details")
    ls_OrderType = loo_Xml.GetChildContent("Order[i]|orderType")
    j = 0
    li_Count_j = loo_Xml.NumChildrenHavingTag("Order[i]|OrderDetail")
    do while j < li_Count_j
        loo_Xml.J = j
        ls_PlacedTime = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|placedTime")
        ls_OrderValue = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|orderValue")
        ls_Status = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|status")
        ls_OrderTerm = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|orderTerm")
        ls_PriceType = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|priceType")
        ls_LimitPrice = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|limitPrice")
        li_StopPrice = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|stopPrice")
        ls_MarketSession = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|marketSession")
        ls_AllOrNone = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|allOrNone")
        k = 0
        li_Count_k = loo_Xml.NumChildrenHavingTag("Order[i]|OrderDetail[j]|Instrument")
        do while k < li_Count_k
            loo_Xml.K = k
            ls_Symbol = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|symbol")
            ls_SecurityType = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|securityType")
            ls_CallPut = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|callPut")
            li_ExpiryYear = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryYear")
            li_ExpiryMonth = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryMonth")
            li_ExpiryDay = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryDay")
            ls_StrikePrice = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|Product|strikePrice")
            ls_SymbolDescription = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|symbolDescription")
            ls_OrderAction = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|orderAction")
            ls_QuantityType = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|quantityType")
            li_OrderedQuantity = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|orderedQuantity")
            li_FilledQuantity = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|filledQuantity")
            ls_AverageExecutionPrice = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|averageExecutionPrice")
            ls_EstimatedCommission = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|Instrument[k]|estimatedCommission")
            li_EstimatedFees = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|Instrument[k]|estimatedFees")
            k = k + 1
        loop
        li_NetPrice = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|netPrice")
        li_NetBid = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|netBid")
        li_NetAsk = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|netAsk")
        li_Gcd = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|gcd")
        li_OrderNumber = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|orderNumber")
        li_BracketedLimitPrice = loo_Xml.GetChildIntValue("Order[i]|OrderDetail[j]|bracketedLimitPrice")
        ls_InitialStopPrice = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|initialStopPrice")
        ls_ExecutedTime = loo_Xml.GetChildContent("Order[i]|OrderDetail[j]|executedTime")
        j = j + 1
    loop
    ls_TotalOrderValue = loo_Xml.GetChildContent("Order[i]|totalOrderValue")
    ls_TotalCommission = loo_Xml.GetChildContent("Order[i]|totalCommission")
    i = i + 1
loop

Write-Debug "Success."


destroy loo_Http
destroy loo_JsonToken
destroy loo_Resp
destroy loo_Xml