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

VBScript 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

 

 

 

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

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)

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

set http = CreateObject("Chilkat_9_5_0.Http")

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

'  Load the access token previously obtained via the OAuth1 3-Legged Authorization
set jsonToken = CreateObject("Chilkat_9_5_0.JsonObject")
success = jsonToken.LoadFile("qa_data/tokens/etrade.json")
If (success <> 1) Then
    outFile.WriteLine("Failed to load OAuth1 token")
    WScript.Quit
End If

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

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

'  This example uses the sandbox URL.  The live URL is "https://etws.etrade.com/order/rest/placeequityorder"
' resp is a Chilkat_9_5_0.HttpResponse
Set resp = http.PostJson2("https://etwssandbox.etrade.com/order/sandbox/rest/placeequityorder","application/json",json.Emit())
If (http.LastMethodSuccess <> 1) Then
    outFile.WriteLine(http.LastErrorText)
    WScript.Quit
End If

'  Examine the response status code.
statusCode = resp.StatusCode
outFile.WriteLine("Status Code = " & statusCode)

'  Load the JSON response body:
success = json.Load(resp.BodyStr)
json.EmitCompact = 0

'  If the status code was not 200, then it was an error..
If (statusCode <> 200) Then
    outFile.WriteLine(json.Emit())
    outFile.WriteLine("Equity order failed.")
    WScript.Quit
End If

outFile.WriteLine(json.Emit())

'  To examine some information from the JSON:
outFile.WriteLine("quantity: " & json.IntOf("PlaceEquityOrderResponse.EquityOrderResponse.quantity"))
outFile.WriteLine("msgDesc: " & json.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"
'  	    }
'  	  }
'  	}
' 

outFile.Close

 

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