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

Swift 3,4,5... Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Swift 3,4,5...) ETrade v1 View Portfolio

Get portfolio information for a selected brokerage account.

Chilkat Downloads for the Swift Programming Language

MAC OS X (Cocoa) Objective-C/Swift Libs

iOS Objective-C/Swift Libs

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()!

    http.oAuth1 = true
    http.oAuthVerifier = ""
    http.oAuthConsumerKey = "ETRADE_CONSUMER_KEY"
    http.oAuthConsumerSecret = "ETRADE_CONSUMER_SECRET"

    // Load the access token previously obtained via the OAuth1 3-Legged Authorization examples Step1 and Step2.
    let json = CkoJsonObject()!
    var success: Bool = json.loadFile("qa_data/tokens/etrade.json")
    if success != true {
        print("Failed to load OAuth1 token")
        return
    }

    http.oAuthToken = json.string(of: "oauth_token")
    http.oAuthTokenSecret = json.string(of: "oauth_token_secret")

    // See the ETrade v1 API documentation HERE.

    http.setUrlVar("accountIdKey", value: "vsnhtF7d9jXxBy6HyaAC4vQ")
    var respStr: String? = http.quickGetStr("https://apisb.etrade.com/v1/accounts/{$accountIdKey}/portfolio")
    if http.lastMethodSuccess != true {
        print("\(http.lastErrorText!)")
        return
    }

    // A 200 status code indicates success.
    var statusCode: Int = http.lastStatus.intValue
    print("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...

    let xml = CkoXml()!
    xml.load(respStr)

    var tagPath: String?
    var accountId: Int
    var i: Int
    var count_i: Int
    var positionId: String?
    var expiryDay: Int
    var expiryMonth: Int
    var expiryYear: Int
    var securityType: String?
    var strikePrice: Int
    var symbol: String?
    var symbolDescription: String?
    var dateAcquired: Int
    var pricePaid: Int
    var commissions: Int
    var otherFees: Int
    var quantity: Int
    var positionIndicator: String?
    var positionType: String?
    var daysGain: String?
    var daysGainPct: String?
    var marketValue: String?
    var totalCost: Int
    var totalGain: String?
    var totalGainPct: Int
    var pctOfPortfolio: String?
    var costPerShare: Int
    var todayCommissions: Int
    var todayFees: Int
    var todayPricePaid: Int
    var todayQuantity: Int
    var adjPrevClose: String?
    var change: String?
    var changePct: String?
    var lastTrade: String?
    var lastTradeTime: Int
    var quoteStatus: String?
    var volume: Int
    var lotsDetails: String?
    var quoteDetails: String?
    var totalPages: Int

    accountId = xml.getChildIntValue("AccountPortfolio|accountId").intValue
    i = 0
    count_i = xml.numChildrenHavingTag("AccountPortfolio|Position").intValue
    while i < count_i {
        xml.i = i
        positionId = xml.getChildContent("AccountPortfolio|Position[i]|positionId")
        expiryDay = xml.getChildIntValue("AccountPortfolio|Position[i]|Product|expiryDay").intValue
        expiryMonth = xml.getChildIntValue("AccountPortfolio|Position[i]|Product|expiryMonth").intValue
        expiryYear = xml.getChildIntValue("AccountPortfolio|Position[i]|Product|expiryYear").intValue
        securityType = xml.getChildContent("AccountPortfolio|Position[i]|Product|securityType")
        strikePrice = xml.getChildIntValue("AccountPortfolio|Position[i]|Product|strikePrice").intValue
        symbol = xml.getChildContent("AccountPortfolio|Position[i]|Product|symbol")
        symbolDescription = xml.getChildContent("AccountPortfolio|Position[i]|symbolDescription")
        dateAcquired = xml.getChildIntValue("AccountPortfolio|Position[i]|dateAcquired").intValue
        pricePaid = xml.getChildIntValue("AccountPortfolio|Position[i]|pricePaid").intValue
        commissions = xml.getChildIntValue("AccountPortfolio|Position[i]|commissions").intValue
        otherFees = xml.getChildIntValue("AccountPortfolio|Position[i]|otherFees").intValue
        quantity = xml.getChildIntValue("AccountPortfolio|Position[i]|quantity").intValue
        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").intValue
        totalGain = xml.getChildContent("AccountPortfolio|Position[i]|totalGain")
        totalGainPct = xml.getChildIntValue("AccountPortfolio|Position[i]|totalGainPct").intValue
        pctOfPortfolio = xml.getChildContent("AccountPortfolio|Position[i]|pctOfPortfolio")
        costPerShare = xml.getChildIntValue("AccountPortfolio|Position[i]|costPerShare").intValue
        todayCommissions = xml.getChildIntValue("AccountPortfolio|Position[i]|todayCommissions").intValue
        todayFees = xml.getChildIntValue("AccountPortfolio|Position[i]|todayFees").intValue
        todayPricePaid = xml.getChildIntValue("AccountPortfolio|Position[i]|todayPricePaid").intValue
        todayQuantity = xml.getChildIntValue("AccountPortfolio|Position[i]|todayQuantity").intValue
        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").intValue
        quoteStatus = xml.getChildContent("AccountPortfolio|Position[i]|Quick|quoteStatus")
        volume = xml.getChildIntValue("AccountPortfolio|Position[i]|Quick|volume").intValue
        lotsDetails = xml.getChildContent("AccountPortfolio|Position[i]|lotsDetails")
        quoteDetails = xml.getChildContent("AccountPortfolio|Position[i]|quoteDetails")
        i = i + 1
    }

    totalPages = xml.getChildIntValue("AccountPortfolio|totalPages").intValue

    // <?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>

}

 

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