Sample code for 30+ languages & platforms
Unicode C

ETrade List Transactions

See more ETrade Examples

Gets transactions for the selected brokerage account.

Chilkat Unicode C Downloads

Unicode C
#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;
    const wchar_t *transactionId;
    int accountId;
    const wchar_t *transactionDate;
    const wchar_t *postDate;
    int amount;
    const wchar_t *description;
    int description2;
    const wchar_t *transactionType;
    const wchar_t *imageFlag;
    const wchar_t *instType;
    int quantity;
    int price;
    const wchar_t *settlementCurrency;
    const wchar_t *paymentCurrency;
    int fee;
    const wchar_t *settlementDate;
    const wchar_t *detailsURI;
    const wchar_t *pageMarkers;
    const wchar_t *moreTransactions;
    int transactionCount;
    int totalCount;
    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}/transactions";
    liveUrl = L"https://api.etrade.com/v1/accounts/{$accountIdKey}/transactions";

    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"?>
    // <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>

    xml = CkXmlW_Create();
    CkXmlW_LoadXml(xml,CkHttpResponseW_bodyStr(resp));
    wprintf(L"%s\n",CkXmlW_getXml(xml));

    i = 0;
    count_i = CkXmlW_NumChildrenHavingTag(xml,L"Transaction");
    while (i < count_i) {
        CkXmlW_putI(xml,i);
        transactionId = CkXmlW_getChildContent(xml,L"Transaction[i]|transactionId");
        accountId = CkXmlW_GetChildIntValue(xml,L"Transaction[i]|accountId");
        transactionDate = CkXmlW_getChildContent(xml,L"Transaction[i]|transactionDate");
        postDate = CkXmlW_getChildContent(xml,L"Transaction[i]|postDate");
        amount = CkXmlW_GetChildIntValue(xml,L"Transaction[i]|amount");
        description = CkXmlW_getChildContent(xml,L"Transaction[i]|description");
        description2 = CkXmlW_GetChildIntValue(xml,L"Transaction[i]|description2");
        transactionType = CkXmlW_getChildContent(xml,L"Transaction[i]|transactionType");
        imageFlag = CkXmlW_getChildContent(xml,L"Transaction[i]|imageFlag");
        instType = CkXmlW_getChildContent(xml,L"Transaction[i]|instType");
        quantity = CkXmlW_GetChildIntValue(xml,L"Transaction[i]|brokerage|quantity");
        price = CkXmlW_GetChildIntValue(xml,L"Transaction[i]|brokerage|price");
        settlementCurrency = CkXmlW_getChildContent(xml,L"Transaction[i]|brokerage|settlementCurrency");
        paymentCurrency = CkXmlW_getChildContent(xml,L"Transaction[i]|brokerage|paymentCurrency");
        fee = CkXmlW_GetChildIntValue(xml,L"Transaction[i]|brokerage|fee");
        settlementDate = CkXmlW_getChildContent(xml,L"Transaction[i]|brokerage|settlementDate");
        detailsURI = CkXmlW_getChildContent(xml,L"Transaction[i]|detailsURI");
        i = i + 1;
    }

    pageMarkers = CkXmlW_getChildContent(xml,L"pageMarkers");
    moreTransactions = CkXmlW_getChildContent(xml,L"moreTransactions");
    transactionCount = CkXmlW_GetChildIntValue(xml,L"transactionCount");
    totalCount = CkXmlW_GetChildIntValue(xml,L"totalCount");

    wprintf(L"Success.\n");


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(jsonToken);
    CkHttpResponseW_Dispose(resp);
    CkXmlW_Dispose(xml);

    }