Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(C# UWP/WinRT) ETrade - Place Equity Order (JSON version)Shows how to place an equity order using ETrade with OAuth1 authorization. See https://developer.etrade.com/ctnt/dev-portal/getDetail?contentUri=V0_Documentation-OrderAPI-PlaceEquityOrder for more information.
// This example assumes the Chilkat HTTP API to have been previously unlocked. // See Global Unlock Sample for sample code. Chilkat.Http http = new Chilkat.Http(); http.OAuth1 = true; http.OAuthVerifier = ""; http.OAuthConsumerKey = "ETRADE_CONSUMER_KEY"; http.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"; // Load the access token previously obtained via the OAuth1 3-Legged Authorization Chilkat.JsonObject jsonToken = new Chilkat.JsonObject(); bool success = jsonToken.LoadFile("qa_data/tokens/etrade.json"); if (success != true) { Debug.WriteLine("Failed to load OAuth1 token"); return; } http.OAuthToken = jsonToken.StringOf("oauth_token"); http.OAuthTokenSecret = jsonToken.StringOf("oauth_token_secret"); // Build the JSON request body Chilkat.JsonObject json = new Chilkat.JsonObject(); json.UpdateString("PlaceEquityOrder.-xmlns","http://order.etws.etrade.com"); // The accountId should be an 8-digit number such as "83405188" json.UpdateString("PlaceEquityOrder.EquityOrderRequest.accountId","MY_ETRADE_ACCOUNT_ID"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.clientOrderId","45"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.limitPrice","3"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.quantity","4"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.symbol","ETFC"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.orderAction","BUY"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.priceType","LIMIT"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.marketSession","REGULAR"); json.UpdateString("PlaceEquityOrder.EquityOrderRequest.orderTerm","GOOD_FOR_DAY"); json.EmitCompact = false; Debug.WriteLine(json.Emit()); // The above code builds the following JSON: // { // "PlaceEquityOrder": { // "-xmlns": "http://order.etws.etrade.com", // "EquityOrderRequest": { // "accountId": "83405188", // "clientOrderId": "45", // "limitPrice": "3", // "quantity": "4", // "symbol": "ETFC", // "orderAction": "BUY", // "priceType": "LIMIT", // "marketSession": "REGULAR", // "orderTerm": "GOOD_FOR_DAY" // } // } // } // POST the JSON and get the response. json.EmitCompact = true; // Set the Accept property to get a JSON response. http.Accept = "application/json"; // This example uses the sandbox URL. The live URL is "https://etws.etrade.com/order/rest/placeequityorder" Chilkat.HttpResponse resp = await http.PostJson2Async("https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder","application/json",json.Emit()); if (http.LastMethodSuccess != true) { Debug.WriteLine(http.LastErrorText); return; } // Examine the response status code. int statusCode = resp.StatusCode; Debug.WriteLine("Status Code = " + Convert.ToString(statusCode)); // Load the JSON response body: json.Load(resp.BodyStr); json.EmitCompact = false; // If the status code was not 200, then it was an error.. if (statusCode != 200) { Debug.WriteLine(json.Emit()); Debug.WriteLine("Equity order failed."); return; } Debug.WriteLine(json.Emit()); // To examine some information from the JSON: Debug.WriteLine("quantity: " + Convert.ToString(json.IntOf("PlaceEquityOrderResponse.EquityOrderResponse.quantity"))); Debug.WriteLine("msgDesc: " + json.StringOf("PlaceEquityOrderResponse.EquityOrderResponse.messageList.msgDesc")); // etc .. // This is a sample response: // { // "PlaceEquityOrderResponse": { // "EquityOrderResponse": { // "accountId": 83310056, // "allOrNone": false, // "estimatedCommission": 9.99, // "estimatedTotalAmount": 1909.99, // "messageList": { // "msgDesc": "Your order was successfully entered during market hours.", // "msgCode": 1026 // }, // "orderNum": 277, // "orderTime": 1240982042179, // "quantity": 100, // "reserveOrder": false, // "reserveQuantity": 0, // "orderTerm": "GOOD_UNTIL_CANCEL", // "limitPrice": 18, // "stopPrice": 0, // "symbolDesc": "CISCO SYS INC COM", // "symbol": "CSCO", // "orderAction": "BUY", // "priceType": "LIMIT" // } // } // } // |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.