Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) ETrade View PortfolioGets portfolio information for the selected brokerage account. For more information, see https://apisb.etrade.com/docs/api/account/api-portfolio-v1.html
integer li_rc oleobject loo_Http oleobject loo_JsonToken integer li_Success string ls_SandboxUrl string ls_LiveUrl oleobject loo_Resp oleobject loo_Xml integer li_AccountId integer li_PositionId integer li_ExpiryDay integer li_ExpiryMonth integer li_ExpiryYear string ls_SecurityType integer li_StrikePrice string ls_Symbol string ls_SymbolDescription string ls_DateAcquired string ls_PricePaid string ls_Commissions string ls_OtherFees integer li_Quantity string ls_PositionIndicator string ls_PositionType string ls_DaysGain string ls_DaysGainPct string ls_MarketValue string ls_TotalCost string ls_TotalGain string ls_TotalGainPct string ls_PctOfPortfolio string ls_CostPerShare integer li_TodayCommissions integer li_TodayFees integer li_TodayPricePaid integer li_TodayQuantity string ls_Change string ls_ChangePct string ls_LastTrade integer li_LastTradeTime integer li_Volume string ls_LotsDetails string ls_QuoteDetails integer li_TotalPages integer i integer li_Count_i // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Http = create oleobject // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") if li_rc < 0 then destroy loo_Http MessageBox("Error","Connecting to COM object failed") return end if loo_Http.OAuth1 = 1 loo_Http.OAuthVerifier = "" loo_Http.OAuthConsumerKey = "ETRADE_CONSUMER_KEY" loo_Http.OAuthConsumerSecret = "ETRADE_CONSUMER_SECRET" // Load the access token previously obtained via the OAuth1 Authorization loo_JsonToken = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject") li_Success = loo_JsonToken.LoadFile("qa_data/tokens/etrade.json") if li_Success <> 1 then Write-Debug "Failed to load OAuth1 token" destroy loo_Http destroy loo_JsonToken return end if loo_Http.OAuthToken = loo_JsonToken.StringOf("oauth_token") loo_Http.OAuthTokenSecret = loo_JsonToken.StringOf("oauth_token_secret") ls_SandboxUrl = "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/portfolio" ls_LiveUrl = "https://api.etrade.com/v1/accounts/{$accountIdKey}/portfolio" loo_Http.SetUrlVar("accountIdKey","6_Dpy0rmuQ9cu9IbTfvF2A") loo_Resp = loo_Http.QuickGetObj(ls_SandboxUrl) if loo_Http.LastMethodSuccess <> 1 then Write-Debug loo_Http.LastErrorText destroy loo_Http destroy loo_JsonToken return end if // Make sure a successful response was received. if loo_Resp.StatusCode > 200 then Write-Debug loo_Resp.StatusLine Write-Debug loo_Resp.Header Write-Debug loo_Resp.BodyStr destroy loo_Http destroy loo_JsonToken return end if // 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"?> // <PortfolioResponse> // <AccountPortfolio> // <accountId>83359700</accountId> // <Position> // <positionId>27005131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>BR</symbol> // </Product> // <symbolDescription>BR</symbolDescription> // <dateAcquired>-57600000</dateAcquired> // <pricePaid>0</pricePaid> // <commissions>0</commissions> // <otherFees>0</otherFees> // <quantity>10</quantity> // <positionIndicator>TYPE2</positionIndicator> // <positionType>LONG</positionType> // <daysGain>-2.7999</daysGain> // <daysGainPct>-1.3346</daysGainPct> // <marketValue>207</marketValue> // <totalCost>0</totalCost> // <totalGain>207</totalGain> // <totalGainPct>0</totalGainPct> // <pctOfPortfolio>0.0018</pctOfPortfolio> // <costPerShare>0</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <Quick> // <change>-0.28</change> // <changePct>-1.3346</changePct> // <lastTrade>20.70</lastTrade> // <lastTradeTime>1343160240</lastTradeTime> // <volume>431591</volume> // </Quick> // <lotsDetails>https://apisb.etrade.com/v1/accounts/E5Nd4LJBsEi_UyHm4Vio9g/portfolio/27005131</lotsDetails> // <quoteDetails>https://apisb.etrade.com/v1/market/quote/BR</quoteDetails> // </Position> // <Position> // <positionId>4709131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>GLD</symbol> // </Product> // <symbolDescription>GLD</symbolDescription> // <dateAcquired>1335250800000</dateAcquired> // <pricePaid>1</pricePaid> // <commissions>5</commissions> // <otherFees>0</otherFees> // <quantity>2</quantity> // <positionIndicator>TYPE1</positionIndicator> // <positionType>LONG</positionType> // <daysGain>0.9799</daysGain> // <daysGainPct>0.3201</daysGainPct> // <marketValue>307.04</marketValue> // <totalCost>7</totalCost> // <totalGain>300.04</totalGain> // <totalGainPct>4286.2857</totalGainPct> // <pctOfPortfolio>0.0028</pctOfPortfolio> // <costPerShare>3.5</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <Quick> // <change>0.49</change> // <changePct>0.3201</changePct> // <lastTrade>153.52</lastTrade> // <lastTradeTime>1343160000</lastTradeTime> // <volume>6510878</volume> // </Quick> // <lotsDetails>https://apisb.etrade.com/v1/accounts/E5Nd4LJBsEi_UyHm4Vio9g/portfolio/4709131</lotsDetails> // <quoteDetails>https://apisb.etrade.com/v1/market/quote/GLD</quoteDetails> // </Position> // <Position> // <positionId>4729131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>MSFT</symbol> // </Product> // <symbolDescription>MSFT</symbolDescription> // <dateAcquired>1335250800000</dateAcquired> // <pricePaid>1</pricePaid> // <commissions>5</commissions> // <otherFees>0</otherFees> // <quantity>1</quantity> // <positionIndicator>TYPE2</positionIndicator> // <positionType>LONG</positionType> // <daysGain>-0.13</daysGain> // <daysGainPct>-0.4439</daysGainPct> // <marketValue>29.1499</marketValue> // <totalCost>6</totalCost> // <totalGain>23.1499</totalGain> // <totalGainPct>385.8333</totalGainPct> // <pctOfPortfolio>0.0002</pctOfPortfolio> // <costPerShare>6</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <Quick> // <change>-0.13</change> // <changePct>-0.4439</changePct> // <lastTrade>29.15</lastTrade> // <lastTradeTime>1343160000</lastTradeTime> // <volume>47711254</volume> // </Quick> // <lotsDetails>https://apisb.etrade.com/v1/accounts/E5Nd4LJBsEi_UyHm4Vio9g/portfolio/4729131</lotsDetails> // <quoteDetails>https://apisb.etrade.com/v1/market/quote/MSFT</quoteDetails> // </Position> // <Position> // <positionId>23971131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>MSFT</symbol> // </Product> // <symbolDescription>MSFT</symbolDescription> // <dateAcquired>-57600000</dateAcquired> // <pricePaid>0</pricePaid> // <commissions>0</commissions> // <otherFees>0</otherFees> // <quantity>-10</quantity> // <positionIndicator>TYPE5</positionIndicator> // <positionType>SHORT</positionType> // <daysGain>1.30</daysGain> // <daysGainPct>-0.4439</daysGainPct> // <marketValue>-291.5</marketValue> // <totalCost>0</totalCost> // <totalGain>-291.5</totalGain> // <totalGainPct>0</totalGainPct> // <pctOfPortfolio>-0.0026</pctOfPortfolio> // <costPerShare>0</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <Quick> // <change>-0.13</change> // <changePct>-0.4439</changePct> // <lastTrade>29.15</lastTrade> // <lastTradeTime>1343160000</lastTradeTime> // <volume>47711254</volume> // </Quick> // <lotsDetails>https://apisb.etrade.com/v1/accounts/E5Nd4LJBsEi_UyHm4Vio9g/portfolio/23971131</lotsDetails> // <quoteDetails>https://apisb.etrade.com/v1/market/quote/MSFT</quoteDetails> // </Position> // <Position> // <positionId>4725131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>RBL</symbol> // </Product> // <symbolDescription>RBL</symbolDescription> // <dateAcquired>1335250800000</dateAcquired> // <pricePaid>1</pricePaid> // <commissions>5</commissions> // <otherFees>0</otherFees> // <quantity>2</quantity> // <positionIndicator>TYPE2</positionIndicator> // <positionType>LONG</positionType> // <daysGain>-0.52</daysGain> // <daysGainPct>-1.0252</daysGainPct> // <marketValue>50.20</marketValue> // <totalCost>7</totalCost> // <totalGain>43.20</totalGain> // <totalGainPct>617.1428</totalGainPct> // <pctOfPortfolio>0.0004</pctOfPortfolio> // <costPerShare>3.5</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <Quick> // <change>-0.26</change> // <changePct>-1.0252</changePct> // <lastTrade>25.10</lastTrade> // <lastTradeTime>1343159760</lastTradeTime> // <volume>11827</volume> // </Quick> // <lotsDetails>https://apisb.etrade.com/v1/accounts/E5Nd4LJBsEi_UyHm4Vio9g/portfolio/4725131</lotsDetails> // <quoteDetails>https://apisb.etrade.com/v1/market/quote/RBL</quoteDetails> // </Position> // <Position> // <positionId>20841131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>RPI</symbol> // </Product> // <symbolDescription>RPI</symbolDescription> // <dateAcquired>1335250800000</dateAcquired> // <pricePaid>7.5599</pricePaid> // <commissions>5</commissions> // <otherFees>45</otherFees> // <quantity>2</quantity> // <positionIndicator>TYPE2</positionIndicator> // <positionType>LONG</positionType> // <daysGain>0</daysGain> // <daysGainPct>0</daysGainPct> // <marketValue>2.8599</marketValue> // <totalCost>65.12</totalCost> // <totalGain>-62.2599</totalGain> // <totalGainPct>-95.6081</totalGainPct> // <pctOfPortfolio>0.00</pctOfPortfolio> // <costPerShare>32.56</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <Quick> // <change>0</change> // <changePct>0</changePct> // <lastTrade>1.43</lastTrade> // <lastTradeTime>1343150700</lastTradeTime> // <volume>1803</volume> // </Quick> // <lotsDetails>https://apisb.etrade.com/v1/accounts/E5Nd4LJBsEi_UyHm4Vio9g/portfolio/20841131</lotsDetails> // <quoteDetails>https://apisb.etrade.com/v1/market/quote/RPI</quoteDetails> // </Position> // <Position> // <positionId>4732131</positionId> // <Product> // <expiryDay>0</expiryDay> // <expiryMonth>0</expiryMonth> // <expiryYear>0</expiryYear> // <securityType>EQ</securityType> // <strikePrice>0</strikePrice> // <symbol>RXD</symbol> // </Product> // <symbolDescription>RXD</symbolDescription> // <dateAcquired>1335250800000</dateAcquired> // <pricePaid>1</pricePaid> // <commissions>2.99</commissions> // <otherFees>0.0099</otherFees> // <quantity>-3</quantity> // <positionIndicator>TYPE5</positionIndicator> // <positionType>SHORT</positionType> // <daysGain>-1.296</daysGain> // <daysGainPct>2.6799</daysGainPct> // <marketValue>-49.6559</marketValue> // <totalCost>0</totalCost> // <totalGain>-49.6559</totalGain> // <totalGainPct>-827.60</totalGainPct> // <pctOfPortfolio>-0.0004</pctOfPortfolio> // <costPerShare>0</costPerShare> // <todayCommissions>0</todayCommissions> // <todayFees>0</todayFees> // <todayPricePaid>0</todayPricePaid> // <todayQuantity>0</todayQuantity> // <Quick> // <change>0.432</change> // <changePct>2.6799</changePct> // <lastTrade>16.552</lastTrade> // <lastTradeTime>1343157480</lastTradeTime> // <volume>2200</volume> // </Quick> // <lotsDetails>https://apisb.etrade.com/v1/accounts/E5Nd4LJBsEi_UyHm4Vio9g/portfolio/4732131</lotsDetails> // <quoteDetails>https://apisb.etrade.com/v1/market/quote/RXD</quoteDetails> // </Position> // <totalPages>1</totalPages> // </AccountPortfolio> // </PortfolioResponse> // loo_Xml = create oleobject // Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml") loo_Xml.LoadXml(loo_Resp.BodyStr) Write-Debug loo_Xml.GetXml() li_AccountId = loo_Xml.GetChildIntValue("AccountPortfolio|accountId") i = 0 li_Count_i = loo_Xml.NumChildrenHavingTag("AccountPortfolio|Position") do while i < li_Count_i loo_Xml.I = i li_PositionId = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|positionId") li_ExpiryDay = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|expiryDay") li_ExpiryMonth = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|expiryMonth") li_ExpiryYear = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|expiryYear") ls_SecurityType = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|Product|securityType") li_StrikePrice = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|Product|strikePrice") ls_Symbol = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|Product|symbol") ls_SymbolDescription = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|symbolDescription") ls_DateAcquired = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|dateAcquired") ls_PricePaid = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|pricePaid") ls_Commissions = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|commissions") ls_OtherFees = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|otherFees") li_Quantity = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|quantity") ls_PositionIndicator = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|positionIndicator") ls_PositionType = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|positionType") ls_DaysGain = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|daysGain") ls_DaysGainPct = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|daysGainPct") ls_MarketValue = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|marketValue") ls_TotalCost = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|totalCost") ls_TotalGain = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|totalGain") ls_TotalGainPct = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|totalGainPct") ls_PctOfPortfolio = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|pctOfPortfolio") ls_CostPerShare = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|costPerShare") li_TodayCommissions = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|todayCommissions") li_TodayFees = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|todayFees") li_TodayPricePaid = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|todayPricePaid") li_TodayQuantity = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|todayQuantity") ls_Change = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|Quick|change") ls_ChangePct = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|Quick|changePct") ls_LastTrade = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|Quick|lastTrade") li_LastTradeTime = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|Quick|lastTradeTime") li_Volume = loo_Xml.GetChildIntValue("AccountPortfolio|Position[i]|Quick|volume") ls_LotsDetails = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|lotsDetails") ls_QuoteDetails = loo_Xml.GetChildContent("AccountPortfolio|Position[i]|quoteDetails") i = i + 1 loop li_TotalPages = loo_Xml.GetChildIntValue("AccountPortfolio|totalPages") Write-Debug "Success." destroy loo_Http destroy loo_JsonToken destroy loo_Xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.