Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) ETrade List OrdersGets the order details for a selected brokerage account based on the search criteria provided. For more information, see https://apisb.etrade.com/docs/api/order/api-order-v1.html#/definition/getOrders
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkXml.pb" Procedure ChilkatExample() ; This requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttp::setCkOAuth1(http, 1) CkHttp::setCkOAuthVerifier(http, "") CkHttp::setCkOAuthConsumerKey(http, "ETRADE_CONSUMER_KEY") CkHttp::setCkOAuthConsumerSecret(http, "ETRADE_CONSUMER_SECRET") ; Load the access token previously obtained via the OAuth1 Authorization jsonToken.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/etrade.json") If success <> 1 Debug "Failed to load OAuth1 token" CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) ProcedureReturn EndIf CkHttp::setCkOAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"oauth_token")) CkHttp::setCkOAuthTokenSecret(http, CkJsonObject::ckStringOf(jsonToken,"oauth_token_secret")) sandboxUrl.s = "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders" liveUrl.s = "https://api.etrade.com/v1/accounts/{$accountIdKey}/orders" CkHttp::ckSetUrlVar(http,"accountIdKey","6_Dpy0rmuQ9cu9IbTfvF2A") resp.i = CkHttp::ckQuickGetObj(http,sandboxUrl) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) ProcedureReturn EndIf ; Make sure a successful response was received. If CkHttpResponse::ckStatusCode(resp) > 200 Debug CkHttpResponse::ckStatusLine(resp) Debug CkHttpResponse::ckHeader(resp) Debug CkHttpResponse::ckBodyStr(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) ProcedureReturn 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> ; xml.i = CkXml::ckCreate() If xml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::ckLoadXml(xml,CkHttpResponse::ckBodyStr(resp)) Debug CkXml::ckGetXml(xml) orderId.i details.s orderType.s j.i count_j.i placedTime.s orderValue.s status.s orderTerm.s priceType.s limitPrice.s stopPrice.i marketSession.s allOrNone.s k.i count_k.i symbol.s securityType.s callPut.s expiryYear.i expiryMonth.i expiryDay.i strikePrice.s symbolDescription.s orderAction.s quantityType.s orderedQuantity.i filledQuantity.i averageExecutionPrice.s estimatedCommission.s estimatedFees.i netPrice.i netBid.i netAsk.i gcd.i orderNumber.i bracketedLimitPrice.i initialStopPrice.s executedTime.s totalOrderValue.s totalCommission.s marker.s = CkXml::ckGetChildContent(xml,"marker") next.s = CkXml::ckGetChildContent(xml,"next") i.i = 0 count_i.i = CkXml::ckNumChildrenHavingTag(xml,"Order") While i < count_i CkXml::setCkI(xml, i) orderId = CkXml::ckGetChildIntValue(xml,"Order[i]|orderId") details = CkXml::ckGetChildContent(xml,"Order[i]|details") orderType = CkXml::ckGetChildContent(xml,"Order[i]|orderType") j = 0 count_j = CkXml::ckNumChildrenHavingTag(xml,"Order[i]|OrderDetail") While j < count_j CkXml::setCkJ(xml, j) placedTime = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|placedTime") orderValue = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|orderValue") status = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|status") orderTerm = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|orderTerm") priceType = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|priceType") limitPrice = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|limitPrice") stopPrice = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|stopPrice") marketSession = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|marketSession") allOrNone = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|allOrNone") k = 0 count_k = CkXml::ckNumChildrenHavingTag(xml,"Order[i]|OrderDetail[j]|Instrument") While k < count_k CkXml::setCkK(xml, k) symbol = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|Product|symbol") securityType = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|Product|securityType") callPut = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|Product|callPut") expiryYear = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryYear") expiryMonth = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryMonth") expiryDay = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryDay") strikePrice = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|Product|strikePrice") symbolDescription = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|symbolDescription") orderAction = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|orderAction") quantityType = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|quantityType") orderedQuantity = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|Instrument[k]|orderedQuantity") filledQuantity = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|Instrument[k]|filledQuantity") averageExecutionPrice = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|averageExecutionPrice") estimatedCommission = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|Instrument[k]|estimatedCommission") estimatedFees = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|Instrument[k]|estimatedFees") k = k + 1 Wend netPrice = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|netPrice") netBid = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|netBid") netAsk = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|netAsk") gcd = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|gcd") orderNumber = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|orderNumber") bracketedLimitPrice = CkXml::ckGetChildIntValue(xml,"Order[i]|OrderDetail[j]|bracketedLimitPrice") initialStopPrice = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|initialStopPrice") executedTime = CkXml::ckGetChildContent(xml,"Order[i]|OrderDetail[j]|executedTime") j = j + 1 Wend totalOrderValue = CkXml::ckGetChildContent(xml,"Order[i]|totalOrderValue") totalCommission = CkXml::ckGetChildContent(xml,"Order[i]|totalCommission") i = i + 1 Wend Debug "Success." CkHttp::ckDispose(http) CkJsonObject::ckDispose(jsonToken) CkXml::ckDispose(xml) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.