Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C# Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(C#) ETrade - Place Equity Order (XML version)

Shows how to place an equity order using ETrade with OAuth1 authorization. This example demonstrates sending an XML request and getting an XML response (rather than JSON).

See https://developer.etrade.com/ctnt/dev-portal/getDetail?contentUri=V0_Documentation-OrderAPI-PlaceEquityOrder for more information.

Chilkat .NET Downloads

Chilkat .NET Assemblies

Chilkat for .NET Core

Chilkat for Mono

//  This example assumes the Chilkat HTTP API to have been previously unlocked.
//  See HTTP 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) {
    Console.WriteLine("Failed to load OAuth1 token");
    return;
}

http.OAuthToken = jsonToken.StringOf("oauth_token");
http.OAuthTokenSecret = jsonToken.StringOf("oauth_token_secret");

//  Build the XML request body
Chilkat.Xml xml = new Chilkat.Xml();
xml.Tag = "PlaceEquityOrder";
xml.AddAttribute("xmlns","http://order.etws.etrade.com");
//  The accountId should be an 8-digit number such as "83405188"
xml.UpdateChildContent("EquityOrderRequest|accountId","MY_ETRADE_ACCOUNT_ID");
xml.UpdateChildContent("EquityOrderRequest|clientOrderId","45");
xml.UpdateChildContent("EquityOrderRequest|limitPrice","3");
xml.UpdateChildContent("EquityOrderRequest|previewId","");
xml.UpdateChildContent("EquityOrderRequest|stopPrice","");
xml.UpdateChildContent("EquityOrderRequest|allOrNone","");
xml.UpdateChildContent("EquityOrderRequest|quantity","4");
xml.UpdateChildContent("EquityOrderRequest|reserveOrder","");
xml.UpdateChildContent("EquityOrderRequest|reserveQuantity","");
xml.UpdateChildContent("EquityOrderRequest|symbol","ETFC");
xml.UpdateChildContent("EquityOrderRequest|orderAction","BUY");
xml.UpdateChildContent("EquityOrderRequest|priceType","LIMIT");
xml.UpdateChildContent("EquityOrderRequest|routingDestination","");
xml.UpdateChildContent("EquityOrderRequest|marketSession","REGULAR");
xml.UpdateChildContent("EquityOrderRequest|orderTerm","GOOD_FOR_DAY");
xml.EmitXmlDecl = false;

Console.WriteLine(xml.GetXml());

//  The above code builds the following XML:

//  	<PlaceEquityOrder xmlns="http://order.etws.etrade.com">
//  	    <EquityOrderRequest>
//  	        <accountId>83405188</accountId>
//  	        <clientOrderId>45</clientOrderId>
//  	        <limitPrice>3</limitPrice>
//  	        <previewId />
//  	        <stopPrice />
//  	        <allOrNone />
//  	        <quantity>4</quantity>
//  	        <reserveOrder />
//  	        <reserveQuantity />
//  	        <symbol>ETFC</symbol>
//  	        <orderAction>BUY</orderAction>
//  	        <priceType>LIMIT</priceType>
//  	        <routingDestination />
//  	        <marketSession>REGULAR</marketSession>
//  	        <orderTerm>GOOD_FOR_DAY</orderTerm>
//  	    </EquityOrderRequest>
//  	</PlaceEquityOrder>

//  POST the XML and get the response.
xml.EmitCompact = true;

//  Set the Accept property to get any response.
http.Accept = "application/xml";

//  The PostXml method will (by default) set the Content-Type request header to "text/xml".
//  ETrade does not like it.  Use "application/xml" instead.
http.SetRequestHeader("Content-Type","application/xml");

//  This example uses the sandbox URL.  The live URL is "https://etws.etrade.com/order/rest/placeequityorder"
Chilkat.HttpResponse resp = http.PostXml("https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder",xml.GetXml(),"utf-8");
if (http.LastMethodSuccess != true) {
    Console.WriteLine(http.LastErrorText);
    return;
}

//  Examine the response status code.
int statusCode = resp.StatusCode;
Console.WriteLine("Status Code = " + Convert.ToString(statusCode));

//  Load the XML response body:
Chilkat.Xml xmlResp = new Chilkat.Xml();
xmlResp.LoadXml(resp.BodyStr);

//  If the status code was not 200, then it was an error..
if (statusCode != 200) {
    Console.WriteLine(resp.BodyStr);
    Console.WriteLine("Equity order failed.");
    return;
}

Console.WriteLine(xmlResp.GetXml());

//  To examine some information from the XML response:
Console.WriteLine("quantity: " + xmlResp.GetChildContent("equityOrderResponse|quantity"));
Console.WriteLine("msgDesc: " + xmlResp.GetChildContent("equityOrderResponse|messageList|message|msgDesc"));
//  etc ..

//  This is a sample response:

//  	<PlaceEquityOrderResponse>
//  	    <equityOrderResponse>
//  	        <accountId>83310056</accountId>
//  	        <allOrNone>false</allOrNone>
//  	        <estimatedCommission>9.99</estimatedCommission>
//  	        <estimatedTotalAmount>1909.99</estimatedTotalAmount>
//  	        <messageList>
//  	            <message>
//  	                <msgDesc>Your order was successfully entered during market hours.</msgDesc>
//  	                <msgCode>1026</msgCode>
//  	            </message>
//  	        </messageList>
//  	        <orderNum>277</orderNum>
//  	        <orderTime>1240982042179</orderTime>
//  	        <quantity>100</quantity>
//  	        <reserveOrder>false</reserveOrder>
//  	        <reserveQuantity>0</reserveQuantity>
//  	        <orderTerm>GOOD_UNTIL_CANCEL</orderTerm>
//  	        <limitPrice>18</limitPrice>
//  	        <stopPrice>0</stopPrice>
//  	        <symbolDesc>CISCO SYS INC COM</symbolDesc>
//  	        <symbol>CSCO</symbol>
//  	        <orderAction>BUY</orderAction>
//  	        <priceType>LIMIT</priceType>
//  	    </equityOrderResponse>
//  	</PlaceEquityOrderResponse>

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.