Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
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)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PowerBuilder) 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 ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_Http
oleobject loo_JsonToken
integer li_Success
oleobject loo_Xml
oleobject loo_Resp
integer li_StatusCode
oleobject loo_XmlResp

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

// Build the XML request body
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat_9_5_0.Xml")

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

Write-Debug loo_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.
loo_Xml.EmitCompact = 1

// Set the Accept property to get any response.
loo_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.
loo_Http.SetRequestHeader("Content-Type","application/xml")

loo_Http.SetRequestHeader("Content-Type","application/xml")

// This example uses the sandbox URL.  The live URL is "https://etws.etrade.com/order/rest/placeequityorder"
loo_Resp = loo_Http.PostXml("https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder",loo_Xml.GetXml(),"utf-8")
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_Xml
    return
end if

// Examine the response status code.
li_StatusCode = loo_Resp.StatusCode
Write-Debug "Status Code = " + string(li_StatusCode)

// Load the XML response body:
loo_XmlResp = create oleobject
li_rc = loo_XmlResp.ConnectToNewObject("Chilkat_9_5_0.Xml")

loo_XmlResp.LoadXml(loo_Resp.BodyStr)

// If the status code was not 200, then it was an error..
if li_StatusCode <> 200 then
    Write-Debug loo_Resp.BodyStr
    Write-Debug "Equity order failed."
    destroy loo_Http
    destroy loo_JsonToken
    destroy loo_Xml
    destroy loo_XmlResp
    return
end if

Write-Debug loo_XmlResp.GetXml()
destroy loo_Resp

// To examine some information from the XML response:
Write-Debug "quantity: " + loo_XmlResp.GetChildContent("equityOrderResponse|quantity")
Write-Debug "msgDesc: " + loo_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>


destroy loo_Http
destroy loo_JsonToken
destroy loo_Xml
destroy loo_XmlResp

 

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