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
(SQL Server) 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
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OASetProperty @http, 'OAuth1', 1 EXEC sp_OASetProperty @http, 'OAuthVerifier', '' EXEC sp_OASetProperty @http, 'OAuthConsumerKey', 'ETRADE_CONSUMER_KEY' EXEC sp_OASetProperty @http, 'OAuthConsumerSecret', 'ETRADE_CONSUMER_SECRET' -- Load the access token previously obtained via the OAuth1 Authorization DECLARE @jsonToken int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT DECLARE @success int EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/etrade.json' IF @success <> 1 BEGIN PRINT 'Failed to load OAuth1 token' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken RETURN END EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'oauth_token' EXEC sp_OASetProperty @http, 'OAuthToken', @sTmp0 EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'oauth_token_secret' EXEC sp_OASetProperty @http, 'OAuthTokenSecret', @sTmp0 DECLARE @sandboxUrl nvarchar(4000) SELECT @sandboxUrl = 'https://apisb.etrade.com/v1/accounts/{$accountIdKey}/portfolio' DECLARE @liveUrl nvarchar(4000) SELECT @liveUrl = 'https://api.etrade.com/v1/accounts/{$accountIdKey}/portfolio' EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'accountIdKey', '6_Dpy0rmuQ9cu9IbTfvF2A' DECLARE @resp int EXEC sp_OAMethod @http, 'QuickGetObj', @resp OUT, @sandboxUrl EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken RETURN END -- Make sure a successful response was received. EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT IF @iTmp0 > 200 BEGIN EXEC sp_OAGetProperty @resp, 'StatusLine', @sTmp0 OUT PRINT @sTmp0 EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT PRINT @sTmp0 EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken RETURN END -- 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> -- DECLARE @xml int -- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT EXEC sp_OAMethod @xml, 'LoadXml', @success OUT, @sTmp0 EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT PRINT @sTmp0 DECLARE @accountId int DECLARE @positionId int DECLARE @expiryDay int DECLARE @expiryMonth int DECLARE @expiryYear int DECLARE @securityType nvarchar(4000) DECLARE @strikePrice int DECLARE @symbol nvarchar(4000) DECLARE @symbolDescription nvarchar(4000) DECLARE @dateAcquired nvarchar(4000) DECLARE @pricePaid nvarchar(4000) DECLARE @commissions nvarchar(4000) DECLARE @otherFees nvarchar(4000) DECLARE @quantity int DECLARE @positionIndicator nvarchar(4000) DECLARE @positionType nvarchar(4000) DECLARE @daysGain nvarchar(4000) DECLARE @daysGainPct nvarchar(4000) DECLARE @marketValue nvarchar(4000) DECLARE @totalCost nvarchar(4000) DECLARE @totalGain nvarchar(4000) DECLARE @totalGainPct nvarchar(4000) DECLARE @pctOfPortfolio nvarchar(4000) DECLARE @costPerShare nvarchar(4000) DECLARE @todayCommissions int DECLARE @todayFees int DECLARE @todayPricePaid int DECLARE @todayQuantity int DECLARE @change nvarchar(4000) DECLARE @changePct nvarchar(4000) DECLARE @lastTrade nvarchar(4000) DECLARE @lastTradeTime int DECLARE @volume int DECLARE @lotsDetails nvarchar(4000) DECLARE @quoteDetails nvarchar(4000) DECLARE @totalPages int EXEC sp_OAMethod @xml, 'GetChildIntValue', @accountId OUT, 'AccountPortfolio|accountId' DECLARE @i int SELECT @i = 0 DECLARE @count_i int EXEC sp_OAMethod @xml, 'NumChildrenHavingTag', @count_i OUT, 'AccountPortfolio|Position' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @xml, 'I', @i EXEC sp_OAMethod @xml, 'GetChildIntValue', @positionId OUT, 'AccountPortfolio|Position[i]|positionId' EXEC sp_OAMethod @xml, 'GetChildIntValue', @expiryDay OUT, 'AccountPortfolio|Position[i]|Product|expiryDay' EXEC sp_OAMethod @xml, 'GetChildIntValue', @expiryMonth OUT, 'AccountPortfolio|Position[i]|Product|expiryMonth' EXEC sp_OAMethod @xml, 'GetChildIntValue', @expiryYear OUT, 'AccountPortfolio|Position[i]|Product|expiryYear' EXEC sp_OAMethod @xml, 'GetChildContent', @securityType OUT, 'AccountPortfolio|Position[i]|Product|securityType' EXEC sp_OAMethod @xml, 'GetChildIntValue', @strikePrice OUT, 'AccountPortfolio|Position[i]|Product|strikePrice' EXEC sp_OAMethod @xml, 'GetChildContent', @symbol OUT, 'AccountPortfolio|Position[i]|Product|symbol' EXEC sp_OAMethod @xml, 'GetChildContent', @symbolDescription OUT, 'AccountPortfolio|Position[i]|symbolDescription' EXEC sp_OAMethod @xml, 'GetChildContent', @dateAcquired OUT, 'AccountPortfolio|Position[i]|dateAcquired' EXEC sp_OAMethod @xml, 'GetChildContent', @pricePaid OUT, 'AccountPortfolio|Position[i]|pricePaid' EXEC sp_OAMethod @xml, 'GetChildContent', @commissions OUT, 'AccountPortfolio|Position[i]|commissions' EXEC sp_OAMethod @xml, 'GetChildContent', @otherFees OUT, 'AccountPortfolio|Position[i]|otherFees' EXEC sp_OAMethod @xml, 'GetChildIntValue', @quantity OUT, 'AccountPortfolio|Position[i]|quantity' EXEC sp_OAMethod @xml, 'GetChildContent', @positionIndicator OUT, 'AccountPortfolio|Position[i]|positionIndicator' EXEC sp_OAMethod @xml, 'GetChildContent', @positionType OUT, 'AccountPortfolio|Position[i]|positionType' EXEC sp_OAMethod @xml, 'GetChildContent', @daysGain OUT, 'AccountPortfolio|Position[i]|daysGain' EXEC sp_OAMethod @xml, 'GetChildContent', @daysGainPct OUT, 'AccountPortfolio|Position[i]|daysGainPct' EXEC sp_OAMethod @xml, 'GetChildContent', @marketValue OUT, 'AccountPortfolio|Position[i]|marketValue' EXEC sp_OAMethod @xml, 'GetChildContent', @totalCost OUT, 'AccountPortfolio|Position[i]|totalCost' EXEC sp_OAMethod @xml, 'GetChildContent', @totalGain OUT, 'AccountPortfolio|Position[i]|totalGain' EXEC sp_OAMethod @xml, 'GetChildContent', @totalGainPct OUT, 'AccountPortfolio|Position[i]|totalGainPct' EXEC sp_OAMethod @xml, 'GetChildContent', @pctOfPortfolio OUT, 'AccountPortfolio|Position[i]|pctOfPortfolio' EXEC sp_OAMethod @xml, 'GetChildContent', @costPerShare OUT, 'AccountPortfolio|Position[i]|costPerShare' EXEC sp_OAMethod @xml, 'GetChildIntValue', @todayCommissions OUT, 'AccountPortfolio|Position[i]|todayCommissions' EXEC sp_OAMethod @xml, 'GetChildIntValue', @todayFees OUT, 'AccountPortfolio|Position[i]|todayFees' EXEC sp_OAMethod @xml, 'GetChildIntValue', @todayPricePaid OUT, 'AccountPortfolio|Position[i]|todayPricePaid' EXEC sp_OAMethod @xml, 'GetChildIntValue', @todayQuantity OUT, 'AccountPortfolio|Position[i]|todayQuantity' EXEC sp_OAMethod @xml, 'GetChildContent', @change OUT, 'AccountPortfolio|Position[i]|Quick|change' EXEC sp_OAMethod @xml, 'GetChildContent', @changePct OUT, 'AccountPortfolio|Position[i]|Quick|changePct' EXEC sp_OAMethod @xml, 'GetChildContent', @lastTrade OUT, 'AccountPortfolio|Position[i]|Quick|lastTrade' EXEC sp_OAMethod @xml, 'GetChildIntValue', @lastTradeTime OUT, 'AccountPortfolio|Position[i]|Quick|lastTradeTime' EXEC sp_OAMethod @xml, 'GetChildIntValue', @volume OUT, 'AccountPortfolio|Position[i]|Quick|volume' EXEC sp_OAMethod @xml, 'GetChildContent', @lotsDetails OUT, 'AccountPortfolio|Position[i]|lotsDetails' EXEC sp_OAMethod @xml, 'GetChildContent', @quoteDetails OUT, 'AccountPortfolio|Position[i]|quoteDetails' SELECT @i = @i + 1 END EXEC sp_OAMethod @xml, 'GetChildIntValue', @totalPages OUT, 'AccountPortfolio|totalPages' PRINT 'Success.' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @xml END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.