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

VB.NET UWP/WinRT Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
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

 

 

 

(VB.NET UWP/WinRT) ETrade - List Orders (JSON)

Shows how to retrieve a list of orders for an ETrade account, and to iterate through the response.

See https://developer.etrade.com/ctnt/dev-portal/getDetail?contentUri=V0_Documentation-OrderAPI-ListOrders for more information.

Chilkat Universal Windows Platform (UWP) / WinRT Downloads

Chilkat for the Universal Windows Platform (UWP)

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

Dim http As New Chilkat.Http

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

'  Load the access token previously obtained via the OAuth1 3-Legged Authorization
Dim jsonToken As New Chilkat.JsonObject
Dim success As Boolean = jsonToken.LoadFile("qa_data/tokens/etrade.json")
If (success <> True) Then
    Debug.WriteLine("Failed to load OAuth1 token")
    Exit Sub
End If


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

'  Tell ETrade we want a JSON response:
http.Accept = "application/json"

'  The live URL is https://etws.etrade.com/order/rest/orderlist/{accountId}
'  We're using the sandbox URL..
Dim sbUrl As New Chilkat.StringBuilder
sbUrl.Append("https://etwssandbox.etrade.com/order/sandbox/rest/orderlist/")
sbUrl.Append("MY_ETRADE_ACCOUNT_ID")

Dim respStr As String = Await http.QuickGetStrAsync(sbUrl.GetAsString())
If (http.LastMethodSuccess <> True) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


'  Examine the response status code.
Dim statusCode As Integer = http.LastStatus
Debug.WriteLine("Status Code = " & statusCode)

'  The response is JSON.  A sample response is shown below.
Dim json As New Chilkat.JsonObject
json.Load(respStr)
json.EmitCompact = False

'  If the status code was not 200, then it was an error..
If (statusCode <> 200) Then
    Debug.WriteLine(json.Emit())
    Debug.WriteLine("List orders failed.")
    Exit Sub
End If


'  Iterate over the orders.
Dim i As Integer = 0
Dim numOrders As Integer = json.SizeOfArray("GetOrderListResponse.orderListResponse.orderDetails")
Dim orderList As Chilkat.JsonObject = json.ObjectOf("GetOrderListResponse.orderListResponse")
While i < numOrders
    orderList.I = i
    Debug.WriteLine("orderId: " & orderList.IntOf("orderDetails[i].order.orderId"))
    Debug.WriteLine("orderStatus: " & orderList.StringOf("orderDetails[i].order.orderStatus"))
    If (orderList.HasMember("orderDetails[i].order.legDetails.executedPrice") = True) Then
        Debug.WriteLine("executedPrice: " & orderList.StringOf("orderDetails[i].order.legDetails.executedPrice"))
    End If

    '  Is the legDetails an array?  If so, then iterate over it..
    Dim szLegDetails As Integer = orderList.SizeOfArray("orderDetails[i].order.legDetails")
    If (szLegDetails > 0) Then
        Dim j As Integer = 0
        While j < szLegDetails
            orderList.J = j
            Debug.WriteLine("-- legNumber: " & orderList.IntOf("orderDetails[i].order.legDetails[j].legNumber"))
            Debug.WriteLine("   orderAction: " & orderList.StringOf("orderDetails[i].order.legDetails[j].orderAction"))
            Debug.WriteLine("   orderedQuantity: " & orderList.IntOf("orderDetails[i].order.legDetails[j].orderedQuantity"))
            j = j + 1
        End While
    End If

    Debug.WriteLine("----")
    i = i + 1
End While


Debug.WriteLine("success.")

'  Sample JSON response:

'  	{
'  	  "GetOrderListResponse": {
'  	    "orderListResponse": {
'  	      "count": 11,
'  	      "marker": "",
'  	      "orderDetails": [
'  	        {
'  	          "order": {
'  	            "orderId": 208,
'  	            "orderPlacedTime": 1267660551466,
'  	            "orderExecutedTime": 1267660558000,
'  	            "orderValue": 0,
'  	            "orderStatus": "EXECUTED",
'  	            "orderType": "EQ",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "MARKET",
'  	            "limitPrice": 0,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "CSCO"
'  	              },
'  	              "symbolDescription": "CISCO SYS INC COM",
'  	              "orderAction": "SELL",
'  	              "orderedQuantity": 1,
'  	              "filledQuantity": 1,
'  	              "executedPrice": 24.84,
'  	              "estimatedCommission": 5,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 205,
'  	            "orderPlacedTime": 1267099216308,
'  	            "orderValue": 4999994.21,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "OPTN",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 50000,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "MSQ",
'  	                "callPut": "CALL",
'  	                "expYear": 2010,
'  	                "expMonth": 4,
'  	                "expDay": 17,
'  	                "strikePrice": 26
'  	              },
'  	              "symbolDescription": "MSFT APR 26 Call",
'  	              "orderAction": "SELL_OPEN",
'  	              "orderedQuantity": 1,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 5.75,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 200,
'  	            "orderPlacedTime": 1267095453128,
'  	            "orderValue": 210.79,
'  	            "orderStatus": "CANCEL_REQUESTED",
'  	            "orderType": "BUY_WRITES",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "NET_DEBIT",
'  	            "limitPrice": 2,
'  	            "stopPrice": 0,
'  	            "legDetails": [
'  	              {
'  	                "legNumber": 1,
'  	                "symbolInfo": {
'  	                  "symbol": "IBM"
'  	                },
'  	                "symbolDescription": "INTERNATIONAL BUSINESS MACHS COM\n\t\t\t\t\t\t\t",
'  	                "orderAction": "BUY",
'  	                "orderedQuantity": 100,
'  	                "filledQuantity": 0,
'  	                "executedPrice": 0,
'  	                "estimatedCommission": 5,
'  	                "estimatedFees": 0
'  	              },
'  	              {
'  	                "legNumber": 2,
'  	                "symbolInfo": {
'  	                  "symbol": "IBM",
' 
'  	                  "callPut": "CALL",
'  	                  "expYear": 2010,
'  	                  "expMonth": 4,
'  	                  "expDay": 17,
'  	                  "strikePrice": 115
'  	                },
'  	                "symbolDescription": "IBM APR 115 Call",
'  	                "orderAction": "SELL_OPEN",
'  	                "orderedQuantity": 1,
'  	                "filledQuantity": 0,
'  	                "executedPrice": 0,
'  	                "estimatedCommission": 5.75,
'  	                "estimatedFees": 0
'  	              }
'  	            ],
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 192,
'  	            "orderPlacedTime": 1267089996809,
'  	            "orderValue": 10.79,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "OPTN",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 0.05,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "QQQ",
'  	                "callPut": "CALL",
'  	                "expYear": 2010,
'  	                "expMonth": 3,
'  	                "expDay": 20,
'  	                "strikePrice": 43
'  	              },
'  	              "symbolDescription": "QQQQ MAR 43 Call",
'  	              "orderAction": "BUY_OPEN",
'  	              "orderedQuantity": 1,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 5.75,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 191,
'  	            "orderPlacedTime": 1267089623587,
'  	            "orderValue": 15,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "EQ",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 1,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "MSFT"
'  	              },
'  	              "symbolDescription": "MICROSOFT CORP COM\n\t\t\t\t\t\t\t",
'  	              "orderAction": "BUY",
'  	              "orderedQuantity": 10,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 5,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 190,
'  	            "orderPlacedTime": 1267089606681,
'  	            "orderValue": 15,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "EQ",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 1,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "MSFT"
'  	              },
'  	              "symbolDescription": "MICROSOFT CORP COM\n\t\t\t\t\t\t\t",
'  	              "orderAction": "BUY",
'  	              "orderedQuantity": 10,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 5,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 189,
'  	            "orderPlacedTime": 1267089589812,
'  	            "orderValue": 15,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "EQ",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 1,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "IBM"
'  	              },
'  	              "symbolDescription": "INTERNATIONAL BUSINESS MACHS COM\n\t\t\t\t\t\t\t",
'  	              "orderAction": "BUY",
'  	              "orderedQuantity": 10,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 5,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 188,
'  	            "orderPlacedTime": 1267089356773,
'  	            "orderValue": 132.59,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "EQ",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "MARKET",
'  	            "limitPrice": 0,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "IBM"
'  	              },
'  	              "symbolDescription": "INTERNATIONAL BUSINESS MACHS COM\n\t\t\t\t\t\t\t",
'  	              "orderAction": "BUY",
'  	              "orderedQuantity": 1,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 5,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 187,
'  	            "orderPlacedTime": 1266904795303,
'  	            "orderValue": 10.79,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "OPTN",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 0.05,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "MSQ",
'  	                "callPut": "CALL",
'  	                "expYear": 2010,
'  	                "expMonth": 4,
'  	                "expDay": 17,
'  	                "strikePrice": 27
'  	              },
'  	              "symbolDescription": "MSFT APR 27 Call",
'  	              "orderAction": "BUY_OPEN",
'  	              "orderedQuantity": 1,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 5.75,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 170,
'  	            "orderPlacedTime": 1266584434221,
'  	            "orderValue": 391.944,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "OPTN",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 1,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "IBM",
'  	                "callPut": "CALL",
'  	                "expYear": 2010,
'  	                "expMonth": 2,
'  	                "expDay": 20,
'  	                "strikePrice": 130
'  	              },
'  	              "symbolDescription": "IBM FEB 130 Call",
'  	              "orderAction": "SELL_OPEN",
'  	              "orderedQuantity": 4,
'  	              "filledQuantity": 0,
'  	              "executedPrice": 0,
'  	              "estimatedCommission": 8,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 166,
'  	            "orderPlacedTime": 1266583451241,
'  	            "orderValue": 4020.28,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "OPTN",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 2,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "IBM",
'  	                "callPut": "CALL",
'  	                "expYear": 2010,
'  	                "expMonth": 2,
'  	                "expDay": 20,
'  	                "strikePrice": 130
'  	              },
'  	              "symbolDescription": "IBM FEB 130 Call",
'  	              "orderAction": "BUY_CLOSE",
'  	              "orderedQuantity": 20,
'  	              "filledQuantity": 10,
'  	              "executedPrice": 2,
'  	              "estimatedCommission": 20,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        },
'  	        {
'  	          "order": {
'  	            "orderId": 162,
'  	            "orderPlacedTime": 1266581179588,
'  	            "orderValue": 4020.28,
'  	            "orderStatus": "OPEN",
'  	            "orderType": "OPTN",
'  	            "orderTerm": "GOOD_FOR_DAY",
'  	            "priceType": "LIMIT",
'  	            "limitPrice": 2,
'  	            "stopPrice": 0,
'  	            "legDetails": {
'  	              "legNumber": 1,
'  	              "symbolInfo": {
'  	                "symbol": "GOP",
'  	                "callPut": "CALL",
'  	                "expYear": 2010,
'  	                "expMonth": 3,
'  	                "expDay": 20,
'  	                "strikePrice": 520
'  	              },
'  	              "symbolDescription": "GOOG MAR 520 Call",
'  	              "orderAction": "BUY_CLOSE",
'  	              "orderedQuantity": 20,
'  	              "filledQuantity": 10,
'  	              "executedPrice": 2,
'  	              "estimatedCommission": 20,
'  	              "estimatedFees": 0
'  	            },
'  	            "allOrNone": false
'  	          }
'  	        }
'  	      ]
'  	    }
'  	  }
'  	}

 

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