DataFlex
DataFlex
ETrade List Transactions
See more ETrade Examples
Gets transactions for the selected brokerage account.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Handle hoJsonToken
String sSandboxUrl
String sLiveUrl
Variant vResp
Handle hoResp
Handle hoXml
String sTransactionId
Integer iAccountId
String sTransactionDate
String sPostDate
Integer iAmount
String sDescription
Integer iDescription2
String sTransactionType
String sImageFlag
String sInstType
Integer iQuantity
Integer iPrice
String sSettlementCurrency
String sPaymentCurrency
Integer iFee
String sSettlementDate
String sDetailsURI
String sPageMarkers
String sMoreTransactions
Integer iTransactionCount
Integer iTotalCount
Integer i
Integer iCount_i
String sTemp1
Integer iTemp1
Move False To iSuccess
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComOAuth1 Of hoHttp To True
Set ComOAuthVerifier Of hoHttp To ""
Set ComOAuthConsumerKey Of hoHttp To "ETRADE_CONSUMER_KEY"
Set ComOAuthConsumerSecret Of hoHttp To "ETRADE_CONSUMER_SECRET"
// Load the access token previously obtained via the OAuth1 Authorization
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
If (Not(IsComObjectCreated(hoJsonToken))) Begin
Send CreateComObject of hoJsonToken
End
Get ComLoadFile Of hoJsonToken "qa_data/tokens/etrade.json" To iSuccess
If (iSuccess <> True) Begin
Showln "Failed to load OAuth1 token"
Procedure_Return
End
Get ComStringOf Of hoJsonToken "oauth_token" To sTemp1
Set ComOAuthToken Of hoHttp To sTemp1
Get ComStringOf Of hoJsonToken "oauth_token_secret" To sTemp1
Set ComOAuthTokenSecret Of hoHttp To sTemp1
Move "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/transactions" To sSandboxUrl
Move "https://api.etrade.com/v1/accounts/{$accountIdKey}/transactions" To sLiveUrl
Get ComSetUrlVar Of hoHttp "accountIdKey" "6_Dpy0rmuQ9cu9IbTfvF2A" To iSuccess
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoResp to vResp
Get ComHttpNoBody Of hoHttp "GET" sSandboxUrl vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
// Make sure a successful response was received.
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 > 200) Begin
Get ComStatusLine Of hoResp To sTemp1
Showln sTemp1
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Procedure_Return
End
// 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>
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Get ComBodyStr Of hoResp To sTemp1
Get ComLoadXml Of hoXml sTemp1 To iSuccess
Get ComGetXml Of hoXml To sTemp1
Showln sTemp1
Move 0 To i
Get ComNumChildrenHavingTag Of hoXml "Transaction" To iCount_i
While (i < iCount_i)
Set ComI Of hoXml To i
Get ComGetChildContent Of hoXml "Transaction[i]|transactionId" To sTransactionId
Get ComGetChildIntValue Of hoXml "Transaction[i]|accountId" To iAccountId
Get ComGetChildContent Of hoXml "Transaction[i]|transactionDate" To sTransactionDate
Get ComGetChildContent Of hoXml "Transaction[i]|postDate" To sPostDate
Get ComGetChildIntValue Of hoXml "Transaction[i]|amount" To iAmount
Get ComGetChildContent Of hoXml "Transaction[i]|description" To sDescription
Get ComGetChildIntValue Of hoXml "Transaction[i]|description2" To iDescription2
Get ComGetChildContent Of hoXml "Transaction[i]|transactionType" To sTransactionType
Get ComGetChildContent Of hoXml "Transaction[i]|imageFlag" To sImageFlag
Get ComGetChildContent Of hoXml "Transaction[i]|instType" To sInstType
Get ComGetChildIntValue Of hoXml "Transaction[i]|brokerage|quantity" To iQuantity
Get ComGetChildIntValue Of hoXml "Transaction[i]|brokerage|price" To iPrice
Get ComGetChildContent Of hoXml "Transaction[i]|brokerage|settlementCurrency" To sSettlementCurrency
Get ComGetChildContent Of hoXml "Transaction[i]|brokerage|paymentCurrency" To sPaymentCurrency
Get ComGetChildIntValue Of hoXml "Transaction[i]|brokerage|fee" To iFee
Get ComGetChildContent Of hoXml "Transaction[i]|brokerage|settlementDate" To sSettlementDate
Get ComGetChildContent Of hoXml "Transaction[i]|detailsURI" To sDetailsURI
Move (i + 1) To i
Loop
Get ComGetChildContent Of hoXml "pageMarkers" To sPageMarkers
Get ComGetChildContent Of hoXml "moreTransactions" To sMoreTransactions
Get ComGetChildIntValue Of hoXml "transactionCount" To iTransactionCount
Get ComGetChildIntValue Of hoXml "totalCount" To iTotalCount
Showln "Success."
End_Procedure