Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Tcl Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Tcl) ETrade View Portfolio

Gets portfolio information for the selected brokerage account.

For more information, see https://apisb.etrade.com/docs/api/account/api-portfolio-v1.html

Chilkat Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

# This 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 Authorization
set jsonToken [new_CkJsonObject]

set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/etrade.json"]
if {$success != 1} then {
    puts "Failed to load OAuth1 token"
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    exit
}

CkHttp_put_OAuthToken $http [CkJsonObject_stringOf $jsonToken "oauth_token"]
CkHttp_put_OAuthTokenSecret $http [CkJsonObject_stringOf $jsonToken "oauth_token_secret"]

set sandboxUrl "https://apisb.etrade.com/v1/accounts/{$accountIdKey}/portfolio"
set liveUrl "https://api.etrade.com/v1/accounts/{$accountIdKey}/portfolio"

CkHttp_SetUrlVar $http "accountIdKey" "6_Dpy0rmuQ9cu9IbTfvF2A"

# resp is a CkHttpResponse
set resp [CkHttp_QuickGetObj $http $sandboxUrl]
if {[CkHttp_get_LastMethodSuccess $http] != 1} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    exit
}

# Make sure a successful response was received.
if {[CkHttpResponse_get_StatusCode $resp] > 200} then {
    puts [CkHttpResponse_statusLine $resp]
    puts [CkHttpResponse_header $resp]
    puts [CkHttpResponse_bodyStr $resp]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    exit
}

# 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>
# 

set xml [new_CkXml]

CkXml_LoadXml $xml [CkHttpResponse_bodyStr $resp]
puts [CkXml_getXml $xml]

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_GetChildIntValue $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_getChildContent $xml "AccountPortfolio|Position[i]|dateAcquired"]
    set pricePaid [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|pricePaid"]
    set commissions [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|commissions"]
    set otherFees [CkXml_getChildContent $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_getChildContent $xml "AccountPortfolio|Position[i]|totalCost"]
    set totalGain [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|totalGain"]
    set totalGainPct [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|totalGainPct"]
    set pctOfPortfolio [CkXml_getChildContent $xml "AccountPortfolio|Position[i]|pctOfPortfolio"]
    set costPerShare [CkXml_getChildContent $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 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 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"]

puts "Success."

delete_CkHttp $http
delete_CkJsonObject $jsonToken
delete_CkXml $xml

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.