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 Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(DataFlex) ETrade Place Order

The Place Order API is used to submit an order after it has been successfully previewed.

For more information, see https://apisb.etrade.com/docs/api/order/api-order-v1.html#/definition/orderPlace

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Handle hoJsonToken
    Boolean iSuccess
    String sSandboxUrl
    String sLiveUrl
    Handle hoXml
    Variant vResp
    Handle hoResp
    String sOrderType
    String sOrderTerm
    String sPriceType
    String sLimitPrice
    Integer iStopPrice
    String sMarketSession
    String sAllOrNone
    String sSymbol
    String sSecurityType
    String sSymbolDescription
    String sOrderAction
    String sQuantityType
    Integer iQuantity
    String sCancelQuantity
    String sReserveOrder
    String sReserveQuantity
    Integer iCode
    String sDescription
    String sV_type
    String sEgQual
    String sEstimatedCommission
    String sEstimatedTotalAmount
    Integer iNetPrice
    Integer iNetBid
    Integer iNetAsk
    Integer iGcd
    String sDstFlag
    Integer iOptionLevelCd
    String sMarginLevelCd
    Integer iOrderId
    String sPlacedTime
    Integer iAccountId
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

    // This requires the Chilkat 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 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

    Move "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders/place" To sSandboxUrl
    Move "https://api.etrade.com/v1/accounts/{$accountIdKey}/orders/place" To sLiveUrl

    Get ComSetUrlVar Of hoHttp "accountIdKey" "6_Dpy0rmuQ9cu9IbTfvF2A" To iSuccess

    // Send a POST with the following XML body

    // Use this online tool to generate the code from sample XML: 
    // Generate Code to Create XML

    // <PlaceOrderRequest>
    //    <orderType>EQ</orderType>
    //    <clientOrderId>sd464333</clientOrderId>
    //    <PreviewIds>
    //       <previewId>730206520</previewId>
    //    </PreviewIds>
    //    <Order>
    //       <allOrNone>false</allOrNone>
    //       <priceType>LIMIT</priceType>
    //       <orderTerm>GOOD_FOR_DAY</orderTerm>
    //       <marketSession>REGULAR</marketSession>
    //       <stopPrice />
    //       <limitPrice>188.51</limitPrice>
    //       <Instrument>
    //          <Product>
    //             <securityType>EQ</securityType>
    //             <symbol>FB</symbol>
    //          </Product>
    //          <orderAction>BUY</orderAction>
    //          <quantityType>QUANTITY</quantityType>
    //          <quantity>150</quantity>
    //       </Instrument>
    //    </Order>
    // </PlaceOrderRequest>

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End
    Set ComTag Of hoXml To "PlaceOrderRequest"
    Send ComUpdateChildContent To hoXml "orderType" "EQ"
    Send ComUpdateChildContent To hoXml "clientOrderId" "sd464333"
    Send ComUpdateChildContent To hoXml "PreviewIds|previewId" "730206520"
    Send ComUpdateChildContent To hoXml "Order|allOrNone" "false"
    Send ComUpdateChildContent To hoXml "Order|priceType" "LIMIT"
    Send ComUpdateChildContent To hoXml "Order|orderTerm" "GOOD_FOR_DAY"
    Send ComUpdateChildContent To hoXml "Order|marketSession" "REGULAR"
    Send ComUpdateChildContent To hoXml "Order|stopPrice" ""
    Send ComUpdateChildContent To hoXml "Order|limitPrice" "188.51"
    Send ComUpdateChildContent To hoXml "Order|Instrument|Product|securityType" "EQ"
    Send ComUpdateChildContent To hoXml "Order|Instrument|Product|symbol" "FB"
    Send ComUpdateChildContent To hoXml "Order|Instrument|orderAction" "BUY"
    Send ComUpdateChildContent To hoXml "Order|Instrument|quantityType" "QUANTITY"
    Send ComUpdateChildContent To hoXml "Order|Instrument|quantity" "150"
    Set ComEmitCompact Of hoXml To True

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

    Get ComGetXml Of hoXml To sTemp1
    Get ComPostXml Of hoHttp sSandboxUrl 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

    // Make sure a successful response was received.
    Get ComStatusCode Of hoResp To iTemp1
    If (iTemp1 > 200) Begin
        Get ComStatusLine Of hoResp To sTemp1
        Showln sTemp1
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Get ComBodyStr Of hoResp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Sample XML response:

    // Use this online tool to generate parsing code from sample XML: 
    // Generate Parsing Code from XML

    // <PlaceOrderResponse>
    //    <orderType>EQ</orderType>
    //    <Order>
    //       <orderTerm>GOOD_FOR_DAY</orderTerm>
    //       <priceType>LIMIT</priceType>
    //       <limitPrice>188.51</limitPrice>
    //       <stopPrice>0</stopPrice>
    //       <marketSession>REGULAR</marketSession>
    //       <allOrNone>false</allOrNone>
    //       <Instrument>
    //          <Product>
    //             <symbol>FB</symbol>
    //             <securityType>EQ</securityType>
    //          </Product>
    //          <symbolDescription>FACEBOOK INC CL A</symbolDescription>
    //          <orderAction>BUY</orderAction>
    //          <quantityType>QUANTITY</quantityType>
    //          <quantity>150</quantity>
    //          <cancelQuantity>0.0</cancelQuantity>
    //          <reserveOrder>true</reserveOrder>
    //          <reserveQuantity>0.0</reserveQuantity>
    //       </Instrument>
    //       <messages>
    //          <Message>
    //             <code>1027</code>
    //             <description>200|The market was closed when we received your order. It has been entered into our system and will be reviewed prior to market open on the next regular trading day. After market open, please check to make sure your order was accepted.</description>
    //             <type>WARNING</type>
    //          </Message>
    //       </messages>
    //       <egQual>EG_QUAL_NOT_A_MARKET_ORDER</egQual>
    //       <estimatedCommission>6.95</estimatedCommission>
    //       <estimatedTotalAmount>28283.45</estimatedTotalAmount>
    //       <netPrice>0</netPrice>
    //       <netBid>0</netBid>
    //       <netAsk>0</netAsk>
    //       <gcd>0</gcd>
    //       <ratio />
    //    </Order>
    //    <dstFlag>true</dstFlag>
    //    <optionLevelCd>4</optionLevelCd>
    //    <marginLevelCd>MARGIN_TRADING_ALLOWED</marginLevelCd>
    //    <OrderIds>
    //       <orderId>5</orderId>
    //    </OrderIds>
    //    <placedTime>1528764717641</placedTime>
    //    <accountId>84312767</accountId>
    // </PlaceOrderResponse>

    Get ComBodyStr Of hoResp To sTemp1
    Get ComLoadXml Of hoXml sTemp1 To iSuccess
    Get ComGetXml Of hoXml To sTemp1
    Showln sTemp1

    Get ComGetChildContent Of hoXml "orderType" To sOrderType
    Get ComGetChildContent Of hoXml "Order|orderTerm" To sOrderTerm
    Get ComGetChildContent Of hoXml "Order|priceType" To sPriceType
    Get ComGetChildContent Of hoXml "Order|limitPrice" To sLimitPrice
    Get ComGetChildIntValue Of hoXml "Order|stopPrice" To iStopPrice
    Get ComGetChildContent Of hoXml "Order|marketSession" To sMarketSession
    Get ComGetChildContent Of hoXml "Order|allOrNone" To sAllOrNone
    Get ComGetChildContent Of hoXml "Order|Instrument|Product|symbol" To sSymbol
    Get ComGetChildContent Of hoXml "Order|Instrument|Product|securityType" To sSecurityType
    Get ComGetChildContent Of hoXml "Order|Instrument|symbolDescription" To sSymbolDescription
    Get ComGetChildContent Of hoXml "Order|Instrument|orderAction" To sOrderAction
    Get ComGetChildContent Of hoXml "Order|Instrument|quantityType" To sQuantityType
    Get ComGetChildIntValue Of hoXml "Order|Instrument|quantity" To iQuantity
    Get ComGetChildContent Of hoXml "Order|Instrument|cancelQuantity" To sCancelQuantity
    Get ComGetChildContent Of hoXml "Order|Instrument|reserveOrder" To sReserveOrder
    Get ComGetChildContent Of hoXml "Order|Instrument|reserveQuantity" To sReserveQuantity
    Get ComGetChildIntValue Of hoXml "Order|messages|Message|code" To iCode
    Get ComGetChildContent Of hoXml "Order|messages|Message|description" To sDescription
    Get ComGetChildContent Of hoXml "Order|messages|Message|type" To sV_type
    Get ComGetChildContent Of hoXml "Order|egQual" To sEgQual
    Get ComGetChildContent Of hoXml "Order|estimatedCommission" To sEstimatedCommission
    Get ComGetChildContent Of hoXml "Order|estimatedTotalAmount" To sEstimatedTotalAmount
    Get ComGetChildIntValue Of hoXml "Order|netPrice" To iNetPrice
    Get ComGetChildIntValue Of hoXml "Order|netBid" To iNetBid
    Get ComGetChildIntValue Of hoXml "Order|netAsk" To iNetAsk
    Get ComGetChildIntValue Of hoXml "Order|gcd" To iGcd
    Get ComGetChildContent Of hoXml "dstFlag" To sDstFlag
    Get ComGetChildIntValue Of hoXml "optionLevelCd" To iOptionLevelCd
    Get ComGetChildContent Of hoXml "marginLevelCd" To sMarginLevelCd
    Get ComGetChildIntValue Of hoXml "OrderIds|orderId" To iOrderId
    Get ComGetChildContent Of hoXml "placedTime" To sPlacedTime
    Get ComGetChildIntValue Of hoXml "accountId" To iAccountId

    Showln "Success."


End_Procedure

 

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