Xbase++
Xbase++
ETrade v1 List Orders
See more HTTP Misc Examples
Gets the order details for a selected brokerage account based on the search criteria provided.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL cRespStr
LOCAL nStatusCode
LOCAL oXml
LOCAL i
LOCAL nCount_i
LOCAL cTagPath
LOCAL nOrderId
LOCAL cDetails
LOCAL cOrderType
LOCAL cOrderDetail
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oHttp:OAuth1 := 1
oHttp:OAuthVerifier := ""
oHttp:OAuthConsumerKey := "ETRADE_CONSUMER_KEY"
oHttp:OAuthConsumerSecret := "ETRADE_CONSUMER_SECRET"
// Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2.
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJson:LoadFile("qa_data/tokens/etrade.json")
IF (nSuccess != 1)
? "Failed to load OAuth1 token"
oHttp:destroy()
oJson:destroy()
RETURN
ENDIF
oHttp:OAuthToken := oJson:StringOf("oauth_token")
oHttp:OAuthTokenSecret := oJson:StringOf("oauth_token_secret")
// See the ETrade v1 API documentation HERE.
oHttp:SetUrlVar("accountIdKey", "vsnhtF7d9jXxBy6HyaAC4vQ")
cRespStr := oHttp:QuickGetStr("https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders?securityType=EQ&count=100")
IF (oHttp:LastMethodSuccess != 1)
? oHttp:LastErrorText
oHttp:destroy()
oJson:destroy()
RETURN
ENDIF
// A 200 status code indicates success.
nStatusCode := oHttp:LastStatus
? "statusCode = " + Str(nStatusCode)
// Use the following online tool to generate parsing code from sample XML:
// Generate Parsing Code from XML
// A sample XML response is shown below...
oXml := CreateObject("Chilkat.Xml")
oXml:LoadXml(cRespStr)
i := 0
nCount_i := oXml:NumChildrenHavingTag("Order")
DO WHILE i < nCount_i
oXml:I := i
nOrderId := oXml:GetChildIntValue("Order[i]|orderId")
cDetails := oXml:GetChildContent("Order[i]|details")
cOrderType := oXml:GetChildContent("Order[i]|orderType")
cOrderDetail := oXml:GetChildContent("Order[i]|OrderDetail")
i := i + 1
ENDDO
// Sample XML Response
// <?xml version="1.0" encoding="UTF-8"?>
// <OrdersResponse>
// <Order>
// <orderId>96</orderId>
// <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/96</details>
// <orderType>EQ</orderType>
// <OrderDetail>�</OrderDetail>
// </Order>
// <Order>
// <orderId>95</orderId>
// <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/95</details>
// <orderType>EQ</orderType>
// <OrderDetail>�</OrderDetail>
// </Order>
// <Order>
// <orderId>94</orderId>
// <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/94</details>
// <orderType>EQ</orderType>
// <OrderDetail>�</OrderDetail>
// </Order>
// <Order>
// <orderId>93</orderId>
// <details>https://api.etrade.com/v1/accounts/ZrnXF-hPu853sBzwHfWGBQ/orders/93</details>
// <orderType>EQ</orderType>
// <OrderDetail>�</OrderDetail>
// </Order>
// </OrdersResponse>
oHttp:destroy()
oJson:destroy()
oXml:destroy()