Unicode C++
Unicode C++
ETrade List Transactions
See more ETrade Examples
Gets transactions for the selected brokerage account.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkXmlW.h>
void ChilkatSample(void)
{
bool success = false;
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
http.put_OAuth1(true);
http.put_OAuthVerifier(L"");
http.put_OAuthConsumerKey(L"ETRADE_CONSUMER_KEY");
http.put_OAuthConsumerSecret(L"ETRADE_CONSUMER_SECRET");
// Load the access token previously obtained via the OAuth1 Authorization
CkJsonObjectW jsonToken;
success = jsonToken.LoadFile(L"qa_data/tokens/etrade.json");
if (success != true) {
wprintf(L"Failed to load OAuth1 token\n");
return;
}
http.put_OAuthToken(jsonToken.stringOf(L"oauth_token"));
http.put_OAuthTokenSecret(jsonToken.stringOf(L"oauth_token_secret"));
const wchar_t *sandboxUrl = L"https://apisb.etrade.com/v1/accounts/{$accountIdKey}/transactions";
const wchar_t *liveUrl = L"https://api.etrade.com/v1/accounts/{$accountIdKey}/transactions";
http.SetUrlVar(L"accountIdKey",L"6_Dpy0rmuQ9cu9IbTfvF2A");
CkHttpResponseW resp;
success = http.HttpNoBody(L"GET",sandboxUrl,resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
// Make sure a successful response was received.
if (resp.get_StatusCode() > 200) {
wprintf(L"%s\n",resp.statusLine());
wprintf(L"%s\n",resp.header());
wprintf(L"%s\n",resp.bodyStr());
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"?>
// <TransactionListResponse>
// <Transaction>
// <transactionId>18165100001766</transactionId>
// <accountId>83564979</accountId>
// <transactionDate>1528948800000</transactionDate>
// <postDate>1528948800000</postDate>
// <amount>-2</amount>
// <description>ACH WITHDRAWL REFID:109187276;</description>
// <description2>109187276</description2>
// <transactionType>Transfer</transactionType>
// <memo />
// <imageFlag>false</imageFlag>
// <instType>BROKERAGE</instType>
// <brokerage>
// <product />
// <quantity>0</quantity>
// <price>0</price>
// <settlementCurrency>USD</settlementCurrency>
// <paymentCurrency>USD</paymentCurrency>
// <fee>0</fee>
// <settlementDate>1528948800000</settlementDate>
// </brokerage>
// <detailsURI>https://api.etrade.com/v1/accounts/yIFaUoJ81qyAhgxLWRQ42g/transactions/18165100001766</detailsURI>
// </Transaction>
// <Transaction>
// <transactionId>18158100000983</transactionId>
// <accountId>83564979</accountId>
// <transactionDate>1528344000000</transactionDate>
// <postDate>1528344000000</postDate>
// <amount>-2</amount>
// <description>ACH WITHDRAWL REFID:98655276;</description>
// <description2>98655276</description2>
// <transactionType>Transfer</transactionType>
// <memo />
// <imageFlag>false</imageFlag>
// <instType>BROKERAGE</instType>
// <brokerage>
// <product />
// <quantity>0</quantity>
// <price>0</price>
// <settlementCurrency>USD</settlementCurrency>
// <paymentCurrency>USD</paymentCurrency>
// <fee>0</fee>
// <settlementDate>1528344000000</settlementDate>
// </brokerage>
// <detailsURI>https://api.etrade.com/v1/accounts/yIFaUoJ81qyAhgxLWRQ42g/transactions/18158100000983</detailsURI>
// </Transaction>
// <pageMarkers>eNpTsAlITE91zi%2FNK%2FHMc04syi8tTs2xM7TRxybMpWATkl%2BSmBOUmpxflAKWtTO10ccQg6mDmwEyEE0EqAbE8SvNTUotCk4tLE3NS061M9Ax0DEEYgOIA9BkuRQgmjxTfDKLQUYoQAV8E4uyU4vsDC0MzUwNDYDA0NzMrKamBmIKVJYLphpiKsyTUB7IbH1kwwFa7F0D</pageMarkers>
// <moreTransactions>false</moreTransactions>
// <transactionCount>5</transactionCount>
// <totalCount>5</totalCount>
// </TransactionListResponse>
CkXmlW xml;
xml.LoadXml(resp.bodyStr());
wprintf(L"%s\n",xml.getXml());
const wchar_t *transactionId = 0;
int accountId;
const wchar_t *transactionDate = 0;
const wchar_t *postDate = 0;
int amount;
const wchar_t *description = 0;
int description2;
const wchar_t *transactionType = 0;
const wchar_t *imageFlag = 0;
const wchar_t *instType = 0;
int quantity;
int price;
const wchar_t *settlementCurrency = 0;
const wchar_t *paymentCurrency = 0;
int fee;
const wchar_t *settlementDate = 0;
const wchar_t *detailsURI = 0;
const wchar_t *pageMarkers = 0;
const wchar_t *moreTransactions = 0;
int transactionCount;
int totalCount;
int i = 0;
int count_i = xml.NumChildrenHavingTag(L"Transaction");
while (i < count_i) {
xml.put_I(i);
transactionId = xml.getChildContent(L"Transaction[i]|transactionId");
accountId = xml.GetChildIntValue(L"Transaction[i]|accountId");
transactionDate = xml.getChildContent(L"Transaction[i]|transactionDate");
postDate = xml.getChildContent(L"Transaction[i]|postDate");
amount = xml.GetChildIntValue(L"Transaction[i]|amount");
description = xml.getChildContent(L"Transaction[i]|description");
description2 = xml.GetChildIntValue(L"Transaction[i]|description2");
transactionType = xml.getChildContent(L"Transaction[i]|transactionType");
imageFlag = xml.getChildContent(L"Transaction[i]|imageFlag");
instType = xml.getChildContent(L"Transaction[i]|instType");
quantity = xml.GetChildIntValue(L"Transaction[i]|brokerage|quantity");
price = xml.GetChildIntValue(L"Transaction[i]|brokerage|price");
settlementCurrency = xml.getChildContent(L"Transaction[i]|brokerage|settlementCurrency");
paymentCurrency = xml.getChildContent(L"Transaction[i]|brokerage|paymentCurrency");
fee = xml.GetChildIntValue(L"Transaction[i]|brokerage|fee");
settlementDate = xml.getChildContent(L"Transaction[i]|brokerage|settlementDate");
detailsURI = xml.getChildContent(L"Transaction[i]|detailsURI");
i = i + 1;
}
pageMarkers = xml.getChildContent(L"pageMarkers");
moreTransactions = xml.getChildContent(L"moreTransactions");
transactionCount = xml.GetChildIntValue(L"transactionCount");
totalCount = xml.GetChildIntValue(L"totalCount");
wprintf(L"Success.\n");
}