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
(PowerBuilder) ETrade - List Orders (JSON)Shows how to retrieve a list of orders for an ETrade account, and to iterate through the response. See https://developer.etrade.com/ctnt/dev-portal/getDetail?contentUri=V0_Documentation-OrderAPI-ListOrders for more information.
integer li_rc oleobject loo_Http oleobject loo_JsonToken integer li_Success oleobject loo_SbUrl string ls_RespStr integer li_StatusCode oleobject loo_Json integer i integer li_NumOrders oleobject loo_OrderList integer li_SzLegDetails integer j // This example assumes the Chilkat HTTP API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.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 3-Legged Authorization loo_JsonToken = create oleobject li_rc = loo_JsonToken.ConnectToNewObject("Chilkat_9_5_0.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") // Tell ETrade we want a JSON response: loo_Http.Accept = "application/json" // The live URL is https://etws.etrade.com/order/rest/orderlist/{accountId} // We're using the sandbox URL.. loo_SbUrl = create oleobject li_rc = loo_SbUrl.ConnectToNewObject("Chilkat_9_5_0.StringBuilder") loo_SbUrl.Append("https://etwssandbox.etrade.com/order/sandbox/rest/orderlist/") loo_SbUrl.Append("MY_ETRADE_ACCOUNT_ID") ls_RespStr = loo_Http.QuickGetStr(loo_SbUrl.GetAsString()) if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_JsonToken destroy loo_SbUrl return end if // Examine the response status code. li_StatusCode = loo_Http.LastStatus Write-Debug "Status Code = " + string(li_StatusCode) // The response is JSON. A sample response is shown below. loo_Json = create oleobject li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject") loo_Json.Load(ls_RespStr) loo_Json.EmitCompact = 0 // If the status code was not 200, then it was an error.. if li_StatusCode <> 200 then Write-Debug loo_Json.Emit() Write-Debug "List orders failed." destroy loo_Http destroy loo_JsonToken destroy loo_SbUrl destroy loo_Json return end if // Iterate over the orders. i = 0 li_NumOrders = loo_Json.SizeOfArray("GetOrderListResponse.orderListResponse.orderDetails") loo_OrderList = loo_Json.ObjectOf("GetOrderListResponse.orderListResponse") do while i < li_NumOrders loo_OrderList.I = i Write-Debug "orderId: " + string(loo_OrderList.IntOf("orderDetails[i].order.orderId")) Write-Debug "orderStatus: " + loo_OrderList.StringOf("orderDetails[i].order.orderStatus") if loo_OrderList.HasMember("orderDetails[i].order.legDetails.executedPrice") = 1 then Write-Debug "executedPrice: " + loo_OrderList.StringOf("orderDetails[i].order.legDetails.executedPrice") end if // Is the legDetails an array? If so, then iterate over it.. li_SzLegDetails = loo_OrderList.SizeOfArray("orderDetails[i].order.legDetails") if li_SzLegDetails > 0 then j = 0 do while j < li_SzLegDetails loo_OrderList.J = j Write-Debug "-- legNumber: " + string(loo_OrderList.IntOf("orderDetails[i].order.legDetails[j].legNumber")) Write-Debug " orderAction: " + loo_OrderList.StringOf("orderDetails[i].order.legDetails[j].orderAction") Write-Debug " orderedQuantity: " + string(loo_OrderList.IntOf("orderDetails[i].order.legDetails[j].orderedQuantity")) j = j + 1 loop end if Write-Debug "----" i = i + 1 loop destroy loo_OrderList Write-Debug "success." // Sample JSON response: // { // "GetOrderListResponse": { // "orderListResponse": { // "count": 11, // "marker": "", // "orderDetails": [ // { // "order": { // "orderId": 208, // "orderPlacedTime": 1267660551466, // "orderExecutedTime": 1267660558000, // "orderValue": 0, // "orderStatus": "EXECUTED", // "orderType": "EQ", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "MARKET", // "limitPrice": 0, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "CSCO" // }, // "symbolDescription": "CISCO SYS INC COM", // "orderAction": "SELL", // "orderedQuantity": 1, // "filledQuantity": 1, // "executedPrice": 24.84, // "estimatedCommission": 5, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 205, // "orderPlacedTime": 1267099216308, // "orderValue": 4999994.21, // "orderStatus": "OPEN", // "orderType": "OPTN", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 50000, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "MSQ", // "callPut": "CALL", // "expYear": 2010, // "expMonth": 4, // "expDay": 17, // "strikePrice": 26 // }, // "symbolDescription": "MSFT APR 26 Call", // "orderAction": "SELL_OPEN", // "orderedQuantity": 1, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5.75, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 200, // "orderPlacedTime": 1267095453128, // "orderValue": 210.79, // "orderStatus": "CANCEL_REQUESTED", // "orderType": "BUY_WRITES", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "NET_DEBIT", // "limitPrice": 2, // "stopPrice": 0, // "legDetails": [ // { // "legNumber": 1, // "symbolInfo": { // "symbol": "IBM" // }, // "symbolDescription": "INTERNATIONAL BUSINESS MACHS COM\n\t\t\t\t\t\t\t", // "orderAction": "BUY", // "orderedQuantity": 100, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5, // "estimatedFees": 0 // }, // { // "legNumber": 2, // "symbolInfo": { // "symbol": "IBM", // // "callPut": "CALL", // "expYear": 2010, // "expMonth": 4, // "expDay": 17, // "strikePrice": 115 // }, // "symbolDescription": "IBM APR 115 Call", // "orderAction": "SELL_OPEN", // "orderedQuantity": 1, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5.75, // "estimatedFees": 0 // } // ], // "allOrNone": false // } // }, // { // "order": { // "orderId": 192, // "orderPlacedTime": 1267089996809, // "orderValue": 10.79, // "orderStatus": "OPEN", // "orderType": "OPTN", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 0.05, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "QQQ", // "callPut": "CALL", // "expYear": 2010, // "expMonth": 3, // "expDay": 20, // "strikePrice": 43 // }, // "symbolDescription": "QQQQ MAR 43 Call", // "orderAction": "BUY_OPEN", // "orderedQuantity": 1, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5.75, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 191, // "orderPlacedTime": 1267089623587, // "orderValue": 15, // "orderStatus": "OPEN", // "orderType": "EQ", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 1, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "MSFT" // }, // "symbolDescription": "MICROSOFT CORP COM\n\t\t\t\t\t\t\t", // "orderAction": "BUY", // "orderedQuantity": 10, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 190, // "orderPlacedTime": 1267089606681, // "orderValue": 15, // "orderStatus": "OPEN", // "orderType": "EQ", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 1, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "MSFT" // }, // "symbolDescription": "MICROSOFT CORP COM\n\t\t\t\t\t\t\t", // "orderAction": "BUY", // "orderedQuantity": 10, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 189, // "orderPlacedTime": 1267089589812, // "orderValue": 15, // "orderStatus": "OPEN", // "orderType": "EQ", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 1, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "IBM" // }, // "symbolDescription": "INTERNATIONAL BUSINESS MACHS COM\n\t\t\t\t\t\t\t", // "orderAction": "BUY", // "orderedQuantity": 10, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 188, // "orderPlacedTime": 1267089356773, // "orderValue": 132.59, // "orderStatus": "OPEN", // "orderType": "EQ", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "MARKET", // "limitPrice": 0, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "IBM" // }, // "symbolDescription": "INTERNATIONAL BUSINESS MACHS COM\n\t\t\t\t\t\t\t", // "orderAction": "BUY", // "orderedQuantity": 1, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 187, // "orderPlacedTime": 1266904795303, // "orderValue": 10.79, // "orderStatus": "OPEN", // "orderType": "OPTN", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 0.05, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "MSQ", // "callPut": "CALL", // "expYear": 2010, // "expMonth": 4, // "expDay": 17, // "strikePrice": 27 // }, // "symbolDescription": "MSFT APR 27 Call", // "orderAction": "BUY_OPEN", // "orderedQuantity": 1, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 5.75, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 170, // "orderPlacedTime": 1266584434221, // "orderValue": 391.944, // "orderStatus": "OPEN", // "orderType": "OPTN", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 1, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "IBM", // "callPut": "CALL", // "expYear": 2010, // "expMonth": 2, // "expDay": 20, // "strikePrice": 130 // }, // "symbolDescription": "IBM FEB 130 Call", // "orderAction": "SELL_OPEN", // "orderedQuantity": 4, // "filledQuantity": 0, // "executedPrice": 0, // "estimatedCommission": 8, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 166, // "orderPlacedTime": 1266583451241, // "orderValue": 4020.28, // "orderStatus": "OPEN", // "orderType": "OPTN", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 2, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "IBM", // "callPut": "CALL", // "expYear": 2010, // "expMonth": 2, // "expDay": 20, // "strikePrice": 130 // }, // "symbolDescription": "IBM FEB 130 Call", // "orderAction": "BUY_CLOSE", // "orderedQuantity": 20, // "filledQuantity": 10, // "executedPrice": 2, // "estimatedCommission": 20, // "estimatedFees": 0 // }, // "allOrNone": false // } // }, // { // "order": { // "orderId": 162, // "orderPlacedTime": 1266581179588, // "orderValue": 4020.28, // "orderStatus": "OPEN", // "orderType": "OPTN", // "orderTerm": "GOOD_FOR_DAY", // "priceType": "LIMIT", // "limitPrice": 2, // "stopPrice": 0, // "legDetails": { // "legNumber": 1, // "symbolInfo": { // "symbol": "GOP", // "callPut": "CALL", // "expYear": 2010, // "expMonth": 3, // "expDay": 20, // "strikePrice": 520 // }, // "symbolDescription": "GOOG MAR 520 Call", // "orderAction": "BUY_CLOSE", // "orderedQuantity": 20, // "filledQuantity": 10, // "executedPrice": 2, // "estimatedCommission": 20, // "estimatedFees": 0 // }, // "allOrNone": false // } // } // ] // } // } // } destroy loo_Http destroy loo_JsonToken destroy loo_SbUrl destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.