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

DataFlex 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
uncategorized

 

 

 

(DataFlex) 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

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Handle hoJsonToken
    Boolean iSuccess
    Handle hoXml
    Variant vResp
    Handle hoResp
    Integer iStatusCode
    Handle hoXmlResp
    String sTemp1
    Boolean bTemp1

    // This example assumes the Chilkat HTTP API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Set ComOAuth1 Of hoHttp To True
    Set ComOAuthVerifier Of hoHttp To ""
    Set ComOAuthConsumerKey Of hoHttp To "ETRADE_CONSUMER_KEY"
    Set ComOAuthConsumerSecret Of hoHttp To "ETRADE_CONSUMER_SECRET"

    // Load the access token previously obtained via the OAuth1 3-Legged Authorization
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
    If (Not(IsComObjectCreated(hoJsonToken))) Begin
        Send CreateComObject of hoJsonToken
    End
    Get ComLoadFile Of hoJsonToken "qa_data/tokens/etrade.json" To iSuccess
    If (iSuccess <> True) Begin
        Showln "Failed to load OAuth1 token"
        Procedure_Return
    End

    Get ComStringOf Of hoJsonToken "oauth_token" To sTemp1
    Set ComOAuthToken Of hoHttp To sTemp1
    Get ComStringOf Of hoJsonToken "oauth_token_secret" To sTemp1
    Set ComOAuthTokenSecret Of hoHttp To sTemp1

    // Build the XML request body
    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Set ComTag Of hoXml To "PlaceEquityOrder"
    Get ComAddAttribute Of hoXml "xmlns" "http://order.etws.etrade.com" To iSuccess
    // The accountId should be an 8-digit number such as "83405188"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|accountId" "MY_ETRADE_ACCOUNT_ID"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|clientOrderId" "45"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|limitPrice" "3"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|previewId" ""
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|stopPrice" ""
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|allOrNone" ""
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|quantity" "4"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|reserveOrder" ""
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|reserveQuantity" ""
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|symbol" "ETFC"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|orderAction" "BUY"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|priceType" "LIMIT"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|routingDestination" ""
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|marketSession" "REGULAR"
    Send ComUpdateChildContent To hoXml "EquityOrderRequest|orderTerm" "GOOD_FOR_DAY"
    Set ComEmitXmlDecl Of hoXml To False

    Get ComGetXml Of hoXml To sTemp1
    Showln sTemp1

    // 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.
    Set ComEmitCompact Of hoXml To True

    // Set the Accept property to get any response.
    Set ComAccept Of hoHttp To "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.
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/xml"

    Send ComSetRequestHeader To hoHttp "Content-Type" "application/xml"

    // This example uses the sandbox URL.  The live URL is "https://etws.etrade.com/order/rest/placeequityorder"
    Get ComGetXml Of hoXml To sTemp1
    Get ComPostXml Of hoHttp "https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder" sTemp1 "utf-8" To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Examine the response status code.
    Get ComStatusCode Of hoResp To iStatusCode
    Showln "Status Code = " iStatusCode

    // Load the XML response body:
    Get Create (RefClass(cComChilkatXml)) To hoXmlResp
    If (Not(IsComObjectCreated(hoXmlResp))) Begin
        Send CreateComObject of hoXmlResp
    End
    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoadXml Of hoXmlResp sTemp1 To iSuccess

    // If the status code was not 200, then it was an error..
    If (iStatusCode <> 200) Begin
        Get ComBodyStr Of hoResp To sTemp1
        Showln sTemp1
        Showln "Equity order failed."
        Procedure_Return
    End

    Get ComGetXml Of hoXmlResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp

    // To examine some information from the XML response:
    Get ComGetChildContent Of hoXmlResp "equityOrderResponse|quantity" To sTemp1
    Showln "quantity: " sTemp1
    Get ComGetChildContent Of hoXmlResp "equityOrderResponse|messageList|message|msgDesc" To sTemp1
    Showln "msgDesc: " sTemp1
    // 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>


End_Procedure

 

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