Accounts - Fetch
Returns a list of E*TRADE accounts for the current user, using SQL Server
- See SQLHTTP easy setup for E*Trade
- See API Call documentation for parameter values and other information
- Create the stored procedure documented below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
CREATE PROCEDURE usp_ETrade_Accounts_Fetch( @Profile nvarchar(100), @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS EXEC usp_ETrade_Auth_Refresh @Profile DECLARE @URL nvarchar(MAX) DECLARE @HTTPSessionID uniqueidentifier DECLARE @Sandbox bit SET @Sandbox = SQLHTTP.net.AuthParam(@Profile, 'Sandbox') IF @Sandbox = 1 BEGIN SET @URL = 'https://etwssandbox.etrade.com/accounts/sandbox/rest/accountlist' END ELSE BEGIN SET @URL = 'https://etws.etrade.com/accounts/rest/accountlist' END EXEC SQLHTTP.net.HTTPSession @HTTPSessionID OUTPUT EXEC usp_Etrade_Auth_Header @Profile, @HTTPSessionID, @URL, 'GET' EXEC SQLHTTP.net.HTTPRequest @HttpSessionID, @URL = @URL, @Method = 'GET', @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT, @Response = @Response OUTPUT GO |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) EXEC usp_ETrade_Accounts_Fetch @Profile = 'My Etrade Sandbox', @Response = @Response OUTPUT, @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT IF @StatusCode >= 400 EXEC SQLHTTP.net.RaiseHttpError @StatusCode, @StatusDescription, @Response ELSE IF SQLHTTP.net.IsXmlValid(@Response) = 0 BEGIN RAISERROR(@Response, 16, 1) RETURN END ELSE BEGIN DECLARE @X xml SET @X = CONVERT(xml, @Response) --The XPath syntax below was easily generated by executing the following commands: --EXEC SQLHTTP.net.XQueryHelper @X --and then executing: --EXEC SQLHTTP.net.XQueryHelper @X, 'AccountListResponse[1]/Account' -- SELECT T.C.value(N'accountDesc[1]', N'nvarchar(MAX)') AS [accountDesc] ,T.C.value(N'accountId[1]', N'nvarchar(MAX)') AS [accountId] ,T.C.value(N'marginLevel[1]', N'nvarchar(MAX)') AS [marginLevel] ,T.C.value(N'netAccountValue[1]', N'nvarchar(MAX)') AS [netAccountValue] ,T.C.value(N'registrationType[1]', N'nvarchar(MAX)') AS [registrationType] FROM @X.nodes(N'/AccountListResponse[1]/Account') T(C) END |
1 2 3 4 5 6 7 8 |
accountDesc accountId marginLevel netAccountValue registrationType -------------- ------------ ------------- ----------------- ------------------ MyAccount-1 30049872 MARGIN 9999871.82 INDIVIDUAL MyAccount-2 83405188 MARGIN 10086354.52 INDIVIDUAL MyAccount-3 83405553 CASH 100105468.99 INDIVIDUAL SIMPLE IRA 83491757 CASH 99794.13 IRA |
IMPORTANT DISCLAIMER
CODE/SQL ON THESE PAGES ARE PROVIDED AS-IS AND ARE AVAILABLE FOR ILLUSTRATIVE PURPOSES ONLY.
USERS ARE REQUIRED TO ABIDE BY THE TERMS AND CONDITIONS FOR USING REFERENCED THIRD PARTY WEBSITES AND/OR APIs FROM THEIR RESPECTIVE WEBSITES. WE DO NOT CONDONE ANY VIOLATION OF THIRD PARTY WEBSITES AND/OR APIs TERMS AND CONDITIONS USING OUR SOFTWARE.
USERS SHALL BE SOLELY RESPONSIBLE AND BE SOLELY LIABLE FOR VIOLATION OF ANY RULES SPECIFIED BY THIRD PARTIES FOR USING THEIR WEBSITES AND/OR APIs, OR INFRINGEMENT OF RIGHTS OF SUCH THIRD PARTIES.