Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) ETrade v1 View PortfolioGet portfolio information for a selected brokerage account.
#include <CkHttp.h> #include <CkJsonObject.h> #include <CkXml.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; http.put_OAuth1(true); http.put_OAuthVerifier(""); http.put_OAuthConsumerKey("ETRADE_CONSUMER_KEY"); http.put_OAuthConsumerSecret("ETRADE_CONSUMER_SECRET"); // Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2. CkJsonObject json; bool success = json.LoadFile("qa_data/tokens/etrade.json"); if (success != true) { strOut.append("Failed to load OAuth1 token"); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } http.put_OAuthToken(json.stringOf("oauth_token")); http.put_OAuthTokenSecret(json.stringOf("oauth_token_secret")); // See the ETrade v1 API documentation HERE. http.SetUrlVar("accountIdKey","vsnhtF7d9jXxBy6HyaAC4vQ"); const char *respStr = http.quickGetStr("https://apisb.etrade.com/v1/accounts/{$accountIdKey}/portfolio"); if (http.get_LastMethodSuccess() != true) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // A 200 status code indicates success. int statusCode = http.get_LastStatus(); strOut.append("statusCode = "); strOut.appendInt(statusCode); strOut.append("\r\n"); // Use the following online tool to generate parsing code from sample XML: // Generate Parsing Code from XML // A sample XML response is shown below... CkXml xml; xml.LoadXml(respStr); const char *tagPath = 0; int accountId; int i; int count_i; const char *positionId = 0; int expiryDay; int expiryMonth; int expiryYear; const char *securityType = 0; int strikePrice; const char *symbol = 0; const char *symbolDescription = 0; int dateAcquired; int pricePaid; int commissions; int otherFees; int quantity; const char *positionIndicator = 0; const char *positionType = 0; const char *daysGain = 0; const char *daysGainPct = 0; const char *marketValue = 0; int totalCost; const char *totalGain = 0; int totalGainPct; const char *pctOfPortfolio = 0; int costPerShare; int todayCommissions; int todayFees; int todayPricePaid; int todayQuantity; const char *adjPrevClose = 0; const char *change = 0; const char *changePct = 0; const char *lastTrade = 0; int lastTradeTime; const char *quoteStatus = 0; int volume; const char *lotsDetails = 0; const char *quoteDetails = 0; int totalPages; accountId = xml.GetChildIntValue("AccountPortfolio|accountId"); i = 0; count_i = xml.NumChildrenHavingTag("AccountPortfolio|Position"); while (i < count_i) { xml.put_I(i); positionId = xml.getChildContent("AccountPortfolio|Position[i]|positionId"); expiryDay = xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|expiryDay"); expiryMonth = xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|expiryMonth"); expiryYear = xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|expiryYear"); securityType = xml.getChildContent("AccountPortfolio|Position[i]|Product|securityType"); strikePrice = xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|strikePrice"); symbol = xml.getChildContent("AccountPortfolio|Position[i]|Product|symbol"); symbolDescription = xml.getChildContent("AccountPortfolio|Position[i]|symbolDescription"); dateAcquired = xml.GetChildIntValue("AccountPortfolio|Position[i]|dateAcquired"); pricePaid = xml.GetChildIntValue("AccountPortfolio|Position[i]|pricePaid"); commissions = xml.GetChildIntValue("AccountPortfolio|Position[i]|commissions"); otherFees = xml.GetChildIntValue("AccountPortfolio|Position[i]|otherFees"); quantity = xml.GetChildIntValue("AccountPortfolio|Position[i]|quantity"); positionIndicator = xml.getChildContent("AccountPortfolio|Position[i]|positionIndicator"); positionType = xml.getChildContent("AccountPortfolio|Position[i]|positionType"); daysGain = xml.getChildContent("AccountPortfolio|Position[i]|daysGain"); daysGainPct = xml.getChildContent("AccountPortfolio|Position[i]|daysGainPct"); marketValue = xml.getChildContent("AccountPortfolio|Position[i]|marketValue"); totalCost = xml.GetChildIntValue("AccountPortfolio|Position[i]|totalCost"); totalGain = xml.getChildContent("AccountPortfolio|Position[i]|totalGain"); totalGainPct = xml.GetChildIntValue("AccountPortfolio|Position[i]|totalGainPct"); pctOfPortfolio = xml.getChildContent("AccountPortfolio|Position[i]|pctOfPortfolio"); costPerShare = xml.GetChildIntValue("AccountPortfolio|Position[i]|costPerShare"); todayCommissions = xml.GetChildIntValue("AccountPortfolio|Position[i]|todayCommissions"); todayFees = xml.GetChildIntValue("AccountPortfolio|Position[i]|todayFees"); todayPricePaid = xml.GetChildIntValue("AccountPortfolio|Position[i]|todayPricePaid"); todayQuantity = xml.GetChildIntValue("AccountPortfolio|Position[i]|todayQuantity"); adjPrevClose = xml.getChildContent("AccountPortfolio|Position[i]|adjPrevClose"); change = xml.getChildContent("AccountPortfolio|Position[i]|Quick|change"); changePct = xml.getChildContent("AccountPortfolio|Position[i]|Quick|changePct"); lastTrade = xml.getChildContent("AccountPortfolio|Position[i]|Quick|lastTrade"); lastTradeTime = xml.GetChildIntValue("AccountPortfolio|Position[i]|Quick|lastTradeTime"); quoteStatus = xml.getChildContent("AccountPortfolio|Position[i]|Quick|quoteStatus"); volume = xml.GetChildIntValue("AccountPortfolio|Position[i]|Quick|volume"); lotsDetails = xml.getChildContent("AccountPortfolio|Position[i]|lotsDetails"); quoteDetails = xml.getChildContent("AccountPortfolio|Position[i]|quoteDetails"); i = i + 1; } totalPages = xml.GetChildIntValue("AccountPortfolio|totalPages"); // <?xml version="1.0" encoding="UTF-8"?> // <PortfolioResponse> // <AccountPortfolio> // <accountId>83554788</accountId> // <Position> // <positionId>10087531</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>A</symbol> // </Product> // <symbolDescription>A</symbolDescription> // <dateAcquired>-68400000</dateAcquired> // <pricePaid>0</pricePaid> // <commissions>0</commissions> // <otherFees>0</otherFees> // <quantity>-120</quantity> // <positionIndicator>TYPE2</positionIndicator> // <positionType>SHORT</positionType> // <daysGain>190.80</daysGain> // <daysGainPct>2.4472</daysGainPct> // <marketValue>-7605.60</marketValue> // <totalCost>0</totalCost> // <totalGain>-7605.60</totalGain> // <totalGainPct>0</totalGainPct> // <pctOfPortfolio>-0.0008</pctOfPortfolio> // <costPerShare>0</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <adjPrevClose>64.970000</adjPrevClose> // <Quick> // <change>-1.59</change> // <changePct>-2.4472</changePct> // <lastTrade>63.38</lastTrade> // <lastTradeTime>1529429280</lastTradeTime> // <quoteStatus>DELAYED</quoteStatus> // <volume>2431617</volume> // </Quick> // <lotsDetails>https://api.etrade.com/v1/accounts/JDIozUumZpHdgbIjMnAAHQ/portfolio/10087531</lotsDetails> // <quoteDetails>https://api.etrade.com/v1/market/quote/A</quoteDetails> // </Position> // <Position> // <positionId>140357348131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>TWTR</symbol> // </Product> // <symbolDescription>TWTR</symbolDescription> // <dateAcquired>-68400000</dateAcquired> // <pricePaid>0</pricePaid> // <commissions>0</commissions> // <otherFees>0</otherFees> // <quantity>3</quantity> // <positionIndicator>TYPE2</positionIndicator> // <positionType>LONG</positionType> // <daysGain>-3.915</daysGain> // <daysGainPct>-2.8369</daysGainPct> // <marketValue>134.085</marketValue> // <totalCost>0</totalCost> // <totalGain>134.085</totalGain> // <totalGainPct>0</totalGainPct> // <pctOfPortfolio>0.0235</pctOfPortfolio> // <costPerShare>0</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <adjPrevClose>46.000000</adjPrevClose> // <Quick> // <change>-1.305</change> // <changePct>-2.8369</changePct> // <lastTrade>44.695</lastTrade> // <lastTradeTime>1529429280</lastTradeTime> // <quoteStatus>DELAYED</quoteStatus> // <volume>26582141</volume> // </Quick> // <lotsDetails>https://api.etrade.com/v1/accounts/yIFaUoJ81qyAhgxLWRQ42g/portfolio/140357348131</lotsDetails> // <quoteDetails>https://api.etrade.com/v1/market/quote/TWTR</quoteDetails> // </Position> // <totalPages>1</totalPages> // </AccountPortfolio> // </PortfolioResponse> SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.