Unicode C
Unicode C
ETrade List Orders
See more ETrade Examples
Gets the order details for a selected brokerage account based on the search criteria provided.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkXmlW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW jsonToken;
const wchar_t *sandboxUrl;
const wchar_t *liveUrl;
HCkHttpResponseW resp;
HCkXmlW xml;
int orderId;
const wchar_t *details;
const wchar_t *orderType;
int j;
int count_j;
const wchar_t *placedTime;
const wchar_t *orderValue;
const wchar_t *status;
const wchar_t *orderTerm;
const wchar_t *priceType;
const wchar_t *limitPrice;
int stopPrice;
const wchar_t *marketSession;
const wchar_t *allOrNone;
int k;
int count_k;
const wchar_t *symbol;
const wchar_t *securityType;
const wchar_t *callPut;
int expiryYear;
int expiryMonth;
int expiryDay;
const wchar_t *strikePrice;
const wchar_t *symbolDescription;
const wchar_t *orderAction;
const wchar_t *quantityType;
int orderedQuantity;
int filledQuantity;
const wchar_t *averageExecutionPrice;
const wchar_t *estimatedCommission;
int estimatedFees;
int netPrice;
int netBid;
int netAsk;
int gcd;
int orderNumber;
int bracketedLimitPrice;
const wchar_t *initialStopPrice;
const wchar_t *executedTime;
const wchar_t *totalOrderValue;
const wchar_t *totalCommission;
const wchar_t *marker;
const wchar_t *next;
int i;
int count_i;
success = FALSE;
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
CkHttpW_putOAuth1(http,TRUE);
CkHttpW_putOAuthVerifier(http,L"");
CkHttpW_putOAuthConsumerKey(http,L"ETRADE_CONSUMER_KEY");
CkHttpW_putOAuthConsumerSecret(http,L"ETRADE_CONSUMER_SECRET");
// Load the access token previously obtained via the OAuth1 Authorization
jsonToken = CkJsonObjectW_Create();
success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/etrade.json");
if (success != TRUE) {
wprintf(L"Failed to load OAuth1 token\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
return;
}
CkHttpW_putOAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"oauth_token"));
CkHttpW_putOAuthTokenSecret(http,CkJsonObjectW_stringOf(jsonToken,L"oauth_token_secret"));
sandboxUrl = L"https://apisb.etrade.com/v1/accounts/{$accountIdKey}/orders";
liveUrl = L"https://api.etrade.com/v1/accounts/{$accountIdKey}/orders";
CkHttpW_SetUrlVar(http,L"accountIdKey",L"6_Dpy0rmuQ9cu9IbTfvF2A");
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpNoBody(http,L"GET",sandboxUrl,resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkHttpResponseW_Dispose(resp);
return;
}
// Make sure a successful response was received.
if (CkHttpResponseW_getStatusCode(resp) > 200) {
wprintf(L"%s\n",CkHttpResponseW_statusLine(resp));
wprintf(L"%s\n",CkHttpResponseW_header(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkHttpResponseW_Dispose(resp);
return;
}
// Sample XML response:
// Use this online tool to generate parsing code from sample XML:
// Generate Parsing Code from XML
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <OrdersResponse>
// <marker>12345678999</marker>
// <next>https://api.sit.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders?marker=12345678999</next>
// <Order>
// <orderId>479</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/479</details>
// <orderType>OPTN</orderType>
// <OrderDetail>
// <placedTime>123453456</placedTime>
// <orderValue>123.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>1.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>RIMM</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>3</expiryMonth>
// <expiryDay>9</expiryDay>
// <strikePrice>12</strikePrice>
// </Product>
// <symbolDescription>RESEARCH IN MOTION LTD COM</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>5</orderedQuantity>
// <filledQuantity>5</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// <Order>
// <orderId>477</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/477</details>
// <orderType>ONE_CANCELS_ALL</orderType>
// <totalOrderValue>209.99</totalOrderValue>
// <totalCommission>10.74</totalCommission>
// <OrderDetail>
// <orderNumber>1</orderNumber>
// <placedTime>1331699203122</placedTime>
// <orderValue>123.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>2</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <bracketedLimitPrice>2</bracketedLimitPrice>
// <initialStopPrice>2</initialStopPrice>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>ETFC</symbol>
// <securityType>EQ</securityType>
// </Product>
// <symbolDescription>ETRADE Financials</symbolDescription>
// <orderAction>BUY</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>100</orderedQuantity>
// <filledQuantity>0</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// <OrderDetail>
// <orderNumber>2</orderNumber>
// <placedTime>1331699203</placedTime>
// <orderValue>231.0000</orderValue>
// <status>OPEN</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>LIMIT</priceType>
// <limitPrice>0.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <initialStopPrice>0.5</initialStopPrice>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>MON</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>4</expiryMonth>
// <expiryDay>21</expiryDay>
// <strikePrice>85</strikePrice>
// </Product>
// <symbolDescription>MON Mar 9 '12 $85 Call</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>1</orderedQuantity>
// <filledQuantity>0</filledQuantity>
// <averageExecutionPrice>0</averageExecutionPrice>
// <estimatedCommission>9.99</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// <Order>
// <orderId>475</orderId>
// <details>https://api.etrade.com/accounts/E5Nd4LJBsEi_UyHm4Vio9g/orders/475</details>
// <orderType>SPREADS</orderType>
// <OrderDetail>
// <placedTime>1331742953</placedTime>
// <executedTime>1331742955432</executedTime>
// <orderValue>4445.99</orderValue>
// <status>EXECUTED</status>
// <orderTerm>GOOD_FOR_DAY</orderTerm>
// <priceType>NET_DEBIT</priceType>
// <limitPrice>1.5</limitPrice>
// <stopPrice>0</stopPrice>
// <marketSession>REGULAR</marketSession>
// <allOrNone>false</allOrNone>
// <Instrument>
// <Product>
// <symbol>REE</symbol>
// <securityType>OPTN</securityType>
// <callPut>CALL</callPut>
// <expiryYear>2012</expiryYear>
// <expiryMonth>7</expiryMonth>
// <expiryDay>21</expiryDay>
// <strikePrice>7</strikePrice>
// </Product>
// <symbolDescription>REE Jul 21 '12 $7 Call</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>2</orderedQuantity>
// <filledQuantity>2</filledQuantity>
// <averageExecutionPrice>1.5</averageExecutionPrice>
// <estimatedCommission>7.24</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <Instrument>
// <Product>
// <symbol>REE</symbol>
// <securityType>OPTN</securityType>
// <callPut>PUT</callPut>
// <expiryYear>2013</expiryYear>
// <expiryMonth>1</expiryMonth>
// <expiryDay>19</expiryDay>
// <strikePrice>12.50</strikePrice>
// </Product>
// <symbolDescription>REE Jan 19 '13 $12.50 Put</symbolDescription>
// <orderAction>BUY_OPEN</orderAction>
// <quantityType>QUANTITY</quantityType>
// <orderedQuantity>2</orderedQuantity>
// <filledQuantity>2</filledQuantity>
// <averageExecutionPrice>1.5</averageExecutionPrice>
// <estimatedCommission>7.24</estimatedCommission>
// <estimatedFees>0</estimatedFees>
// </Instrument>
// <netPrice>0</netPrice>
// <netBid>0</netBid>
// <netAsk>0</netAsk>
// <gcd>0</gcd>
// <ratio/>
// </OrderDetail>
// </Order>
// </OrdersResponse>
//
xml = CkXmlW_Create();
CkXmlW_LoadXml(xml,CkHttpResponseW_bodyStr(resp));
wprintf(L"%s\n",CkXmlW_getXml(xml));
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
marker = CkXmlW_getChildContent(xml,L"marker");
next = CkXmlW_getChildContent(xml,L"next");
i = 0;
count_i = CkXmlW_NumChildrenHavingTag(xml,L"Order");
while (i < count_i) {
CkXmlW_putI(xml,i);
orderId = CkXmlW_GetChildIntValue(xml,L"Order[i]|orderId");
details = CkXmlW_getChildContent(xml,L"Order[i]|details");
orderType = CkXmlW_getChildContent(xml,L"Order[i]|orderType");
j = 0;
count_j = CkXmlW_NumChildrenHavingTag(xml,L"Order[i]|OrderDetail");
while (j < count_j) {
CkXmlW_putJ(xml,j);
placedTime = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|placedTime");
orderValue = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|orderValue");
status = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|status");
orderTerm = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|orderTerm");
priceType = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|priceType");
limitPrice = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|limitPrice");
stopPrice = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|stopPrice");
marketSession = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|marketSession");
allOrNone = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|allOrNone");
k = 0;
count_k = CkXmlW_NumChildrenHavingTag(xml,L"Order[i]|OrderDetail[j]|Instrument");
while (k < count_k) {
CkXmlW_putK(xml,k);
symbol = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|Product|symbol");
securityType = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|Product|securityType");
callPut = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|Product|callPut");
expiryYear = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryYear");
expiryMonth = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryMonth");
expiryDay = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|Product|expiryDay");
strikePrice = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|Product|strikePrice");
symbolDescription = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|symbolDescription");
orderAction = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|orderAction");
quantityType = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|quantityType");
orderedQuantity = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|orderedQuantity");
filledQuantity = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|filledQuantity");
averageExecutionPrice = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|averageExecutionPrice");
estimatedCommission = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|estimatedCommission");
estimatedFees = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|Instrument[k]|estimatedFees");
k = k + 1;
}
netPrice = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|netPrice");
netBid = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|netBid");
netAsk = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|netAsk");
gcd = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|gcd");
orderNumber = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|orderNumber");
bracketedLimitPrice = CkXmlW_GetChildIntValue(xml,L"Order[i]|OrderDetail[j]|bracketedLimitPrice");
initialStopPrice = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|initialStopPrice");
executedTime = CkXmlW_getChildContent(xml,L"Order[i]|OrderDetail[j]|executedTime");
j = j + 1;
}
totalOrderValue = CkXmlW_getChildContent(xml,L"Order[i]|totalOrderValue");
totalCommission = CkXmlW_getChildContent(xml,L"Order[i]|totalCommission");
i = i + 1;
}
wprintf(L"Success.\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkHttpResponseW_Dispose(resp);
CkXmlW_Dispose(xml);
}