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

Visual FoxPro 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

 

 

 

(Visual FoxPro) 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loHttp
LOCAL loJsonToken
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
LOCAL lnStatusCode

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

loHttp = CreateObject('Chilkat_9_5_0.Http')

loHttp.OAuth1 = 1
loHttp.OAuthVerifier = ""
loHttp.OAuthConsumerKey = "ETRADE_CONSUMER_KEY"
loHttp.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"

* Load the access token previously obtained via the OAuth1 3-Legged Authorization
loJsonToken = CreateObject('Chilkat_9_5_0.JsonObject')
lnSuccess = loJsonToken.LoadFile("qa_data/tokens/etrade.json")
IF (lnSuccess <> 1) THEN
    ? "Failed to load OAuth1 token"
    RELEASE loHttp
    RELEASE loJsonToken
    CANCEL
ENDIF

loHttp.OAuthToken = loJsonToken.StringOf("oauth_token")
loHttp.OAuthTokenSecret = loJsonToken.StringOf("oauth_token_secret")

* Build the JSON request body
loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("PlaceEquityOrder.-xmlns","http://order.etws.etrade.com")
* The accountId should be an 8-digit number such as "83405188"
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.accountId","MY_ETRADE_ACCOUNT_ID")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.clientOrderId","45")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.limitPrice","3")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.quantity","4")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.symbol","ETFC")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.orderAction","BUY")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.priceType","LIMIT")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.marketSession","REGULAR")
loJson.UpdateString("PlaceEquityOrder.EquityOrderRequest.orderTerm","GOOD_FOR_DAY")
loJson.EmitCompact = 0
? loJson.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.
loJson.EmitCompact = 1
* Set the Accept property to get a JSON response.
loHttp.Accept = "application/json"

* This example uses the sandbox URL.  The live URL is "https://etws.etrade.com/order/rest/placeequityorder"
loResp = loHttp.PostJson2("https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder","application/json",loJson.Emit())
IF (loHttp.LastMethodSuccess <> 1) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loJson
    CANCEL
ENDIF

* Examine the response status code.
lnStatusCode = loResp.StatusCode
? "Status Code = " + STR(lnStatusCode)

* Load the JSON response body:
loJson.Load(loResp.BodyStr)
loJson.EmitCompact = 0

* If the status code was not 200, then it was an error..
IF (lnStatusCode <> 200) THEN
    ? loJson.Emit()
    ? "Equity order failed."
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loJson
    CANCEL
ENDIF

? loJson.Emit()
RELEASE loResp

* To examine some information from the JSON:
? "quantity: " + STR(loJson.IntOf("PlaceEquityOrderResponse.EquityOrderResponse.quantity"))
? "msgDesc: " + loJson.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"
* 	    }
* 	  }
* 	}
* 

RELEASE loHttp
RELEASE loJsonToken
RELEASE loJson


 

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