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
(Tcl) ETrade v1 View PortfolioGet portfolio information for a selected brokerage account.
load ./chilkat.dll # This example requires the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] CkHttp_put_OAuth1 $http 1 CkHttp_put_OAuthVerifier $http "" CkHttp_put_OAuthConsumerKey $http "ETRADE_CONSUMER_KEY" CkHttp_put_OAuthConsumerSecret $http "ETRADE_CONSUMER_SECRET" # Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2. set json [new_CkJsonObject] set success [CkJsonObject_LoadFile $json "qa_data/tokens/etrade.json"] if {$success != 1} then { puts "Failed to load OAuth1 token" delete_CkHttp $http delete_CkJsonObject $json exit } CkHttp_put_OAuthToken $http [CkJsonObject_stringOf $json "oauth_token"] CkHttp_put_OAuthTokenSecret $http [CkJsonObject_stringOf $json "oauth_token_secret"] # See the ETrade v1 API documentation HERE. CkHttp_SetUrlVar $http "accountIdKey" "vsnhtF7d9jXxBy6HyaAC4vQ" set respStr [CkHttp_quickGetStr $http "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/portfolio"] if {[CkHttp_get_LastMethodSuccess $http] != 1} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkJsonObject $json exit } # A 200 status code indicates success. set statusCode [CkHttp_get_LastStatus $http] puts "statusCode = $statusCode" # Use the following online tool to generate parsing code from sample XML: # Generate Parsing Code from XML # A sample XML response is shown below... set xml [new_CkXml] CkXml_LoadXml $xml $respStr set accountId [CkXml_GetChildIntValue $xml "AccountPortfolio|accountId"] set i 0 set count_i [CkXml_NumChildrenHavingTag $xml "AccountPortfolio|Position"] while {$i < $count_i} { CkXml_put_I $xml $i set positionId [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|positionId"] set expiryDay [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|Product|expiryDay"] set expiryMonth [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|Product|expiryMonth"] set expiryYear [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|Product|expiryYear"] set securityType [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|Product|securityType"] set strikePrice [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|Product|strikePrice"] set symbol [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|Product|symbol"] set symbolDescription [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|symbolDescription"] set dateAcquired [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|dateAcquired"] set pricePaid [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|pricePaid"] set commissions [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|commissions"] set otherFees [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|otherFees"] set quantity [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|quantity"] set positionIndicator [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|positionIndicator"] set positionType [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|positionType"] set daysGain [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|daysGain"] set daysGainPct [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|daysGainPct"] set marketValue [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|marketValue"] set totalCost [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|totalCost"] set totalGain [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|totalGain"] set totalGainPct [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|totalGainPct"] set pctOfPortfolio [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|pctOfPortfolio"] set costPerShare [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|costPerShare"] set todayCommissions [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|todayCommissions"] set todayFees [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|todayFees"] set todayPricePaid [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|todayPricePaid"] set todayQuantity [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|todayQuantity"] set adjPrevClose [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|adjPrevClose"] set change [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|Quick|change"] set changePct [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|Quick|changePct"] set lastTrade [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|Quick|lastTrade"] set lastTradeTime [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|Quick|lastTradeTime"] set quoteStatus [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|Quick|quoteStatus"] set volume [CkXml_GetChildIntValue $xml "AccountPortfolio|Position[i]|Quick|volume"] set lotsDetails [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|lotsDetails"] set quoteDetails [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|quoteDetails"] set i [expr $i + 1] } set totalPages [CkXml_GetChildIntValue $xml "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> delete_CkHttp $http delete_CkJsonObject $json delete_CkXml $xml |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.