diff --git a/.vs/Steves_Code/v17/.wsuo b/.vs/Steves_Code/v17/.wsuo new file mode 100644 index 0000000..a24c159 Binary files /dev/null and b/.vs/Steves_Code/v17/.wsuo differ diff --git a/.vs/Steves_Code/v17/DocumentLayout.json b/.vs/Steves_Code/v17/DocumentLayout.json new file mode 100644 index 0000000..c0e067f --- /dev/null +++ b/.vs/Steves_Code/v17/DocumentLayout.json @@ -0,0 +1,12 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\Steve.OZDOMAIN\\source\\repos\\Steves_Code\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [] + } + ] +} \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..cfae872 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,7 @@ +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\C:\\Users\\Steve.OZDOMAIN\\Source\\Repos\\Steves_Code", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/Websites/SharePrices/.vs/SharePrices/v17/.suo b/Websites/SharePrices/.vs/SharePrices/v17/.suo new file mode 100644 index 0000000..b6db647 Binary files /dev/null and b/Websites/SharePrices/.vs/SharePrices/v17/.suo differ diff --git a/Websites/SharePrices/.vs/SharePrices/v17/DocumentLayout.backup.json b/Websites/SharePrices/.vs/SharePrices/v17/DocumentLayout.backup.json new file mode 100644 index 0000000..7176f60 --- /dev/null +++ b/Websites/SharePrices/.vs/SharePrices/v17/DocumentLayout.backup.json @@ -0,0 +1,12 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\Steve.OZDOMAIN\\source\\repos\\Steves_Code\\Websites\\SharePrices\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [] + } + ] +} \ No newline at end of file diff --git a/Websites/SharePrices/.vs/SharePrices/v17/DocumentLayout.json b/Websites/SharePrices/.vs/SharePrices/v17/DocumentLayout.json new file mode 100644 index 0000000..7176f60 --- /dev/null +++ b/Websites/SharePrices/.vs/SharePrices/v17/DocumentLayout.json @@ -0,0 +1,12 @@ +{ + "Version": 1, + "WorkspaceRootPath": "C:\\Users\\Steve.OZDOMAIN\\source\\repos\\Steves_Code\\Websites\\SharePrices\\", + "Documents": [], + "DocumentGroupContainers": [ + { + "Orientation": 0, + "VerticalTabListWidth": 256, + "DocumentGroups": [] + } + ] +} \ No newline at end of file diff --git a/Websites/SharePrices/SharePrices.v12.suo b/Websites/SharePrices/SharePrices.v12.suo index 4b46cce..62e03c8 100644 Binary files a/Websites/SharePrices/SharePrices.v12.suo and b/Websites/SharePrices/SharePrices.v12.suo differ diff --git a/Websites/SharePrices/SharePrices/App_Code/DataAccessLayer.vb b/Websites/SharePrices/SharePrices/App_Code/DataAccessLayer.vb index e285a78..fb2a1d7 100644 --- a/Websites/SharePrices/SharePrices/App_Code/DataAccessLayer.vb +++ b/Websites/SharePrices/SharePrices/App_Code/DataAccessLayer.vb @@ -33,7 +33,21 @@ Public Class DataAccessLayer DisposeSQLCommand(c) End Function - Public Shared Function AddHolding(AccountName As String, Symbol As String, NoUnits As Integer, PurchasePricePerUnit As Double, PurchaseDate As Int64) As String + Public Shared Sub UpdateInstrument(Symbol As String, GMTOffset As Integer, Currency As String, CurrentPrice As Double, InstrumentType As String, TradeDayStart As DateTime, TradeDayEnd As DateTime) + '@Symbol varchar(8), @GMTOffset int, @Currency varchar(3), @CurrentPrice money, @InstrumentType varchar(10) + Dim c As SqlCommand = GetSQLCommand("usp_UpdateInstrument") + c.Parameters.AddWithValue("Symbol", Symbol) + c.Parameters.AddWithValue("GMTOffset", GMTOffset) + c.Parameters.AddWithValue("Currency", Currency) + c.Parameters.AddWithValue("CurrentPrice", CurrentPrice) + c.Parameters.AddWithValue("InstrumentType", InstrumentType) + c.Parameters.AddWithValue("TradeDayStart", TradeDayStart) + c.Parameters.AddWithValue("TradeDayEnd", TradeDayEnd) + c.ExecuteNonQuery() + DisposeSQLCommand(c) + End Sub + + Public Shared Function AddHolding(AccountName As String, Symbol As String, NoUnits As Double, PurchasePricePerUnit As Double, PurchaseDate As Int64) As String Dim c As SqlCommand = GetSQLCommand("usp_InsertHolding") c.Parameters.AddWithValue("Account", AccountName) c.Parameters.AddWithValue("Symbol", Symbol) @@ -160,10 +174,25 @@ Public Class DataAccessLayer DisposeSQLCommand(c) End Function - Public Shared Function DeleteHolding(HoldingID) As String - Dim c As SqlCommand = GetSQLCommand("usp_DeleteHolding") + 'Public Shared Function DeleteHolding(HoldingID) As String + ' Dim c As SqlCommand = GetSQLCommand("usp_DeleteHolding") + ' c.Parameters.AddWithValue("HoldingID", HoldingID) + ' DeleteHolding = DataReaderToJSONString(c.ExecuteReader()) + ' DisposeSQLCommand(c) + 'End Function + Public Shared Function SoldHolding(HoldingID As Integer, SoldDate As DateTime) As String + Dim c As SqlCommand = GetSQLCommand("usp_SoldHolding") c.Parameters.AddWithValue("HoldingID", HoldingID) - DeleteHolding = DataReaderToJSONString(c.ExecuteReader()) + c.Parameters.AddWithValue("SoldDate", SoldDate) + SoldHolding = DataReaderToJSONString(c.ExecuteReader()) + DisposeSQLCommand(c) + End Function + + Public Shared Function SwapInstrumentDisplayOrders(Symbol1 As String, Symbol2 As String) As String + Dim c As SqlCommand = GetSQLCommand("usp_SwapDisplayOrder") + c.Parameters.AddWithValue("Symbol1", Symbol1) + c.Parameters.AddWithValue("Symbol2", Symbol2) + SwapInstrumentDisplayOrders = DataReaderToJSONString(c.ExecuteReader()) DisposeSQLCommand(c) End Function @@ -210,7 +239,7 @@ Public Class DataAccessLayer End While If result <> "" Then result = result.Substring(1) If noRows > 1 Then result = "[" + result + "]" - 'Debug.Print("Result: " + result) + 'Debug.Print(" DataReaderToJSONString Result: " + result) Return result End Function End Class diff --git a/Websites/SharePrices/SharePrices/CreateDBSchema.sql b/Websites/SharePrices/SharePrices/CreateDBSchema.sql index 2328539..f187b80 100644 --- a/Websites/SharePrices/SharePrices/CreateDBSchema.sql +++ b/Websites/SharePrices/SharePrices/CreateDBSchema.sql @@ -2,9 +2,13 @@ USE SharePrices GO /* +DROP VIEW vErroneousPrices_Intraday +DROP VIEW vErroneousPrices_Daily DROP VIEW vHolding +DROP PROCEDURE usp_SwapDisplayOrder DROP PROCEDURE usp_GetHoldingsHistory -DROP PROCEDURE usp_DeleteHolding +--DROP PROCEDURE usp_DeleteHolding +DROP PROCEDURE usp_SoldHolding DROP PROCEDURE usp_GetAccounts DROP PROCEDURE usp_GetHoldings DROP PROCEDURE usp_InsertHolding @@ -12,6 +16,7 @@ DROP PROCEDURE usp_InsertIntradayData DROP PROCEDURE usp_InsertDailyData DROP PROCEDURE usp_GetDailyData DROP PROCEDURE usp_GetIntradayData +DROP PROCEDURE usp_UpdateInstrument DROP PROCEDURE usp_InsertInstrument DROP PROCEDURE usp_GetInstruments DROP TYPE PriceDataType @@ -53,23 +58,39 @@ CREATE TABLE Instrument ( --ExchangeID tinyint NOT NULL, Symbol VARCHAR(8) NOT NULL, FullName VARCHAR(100) NULL, + DisplayName VARCHAR(30) NULL, DisplayOrder TINYINT NULL, + PostPandemicDilution money NOT NULL, + GMTOffset INT NULL, + Currency VARCHAR(3) NULL, + --CurrentPrice money NULL, + CurrentPrice real NULL, + InstrumentType VARCHAR(15) NULL, + ShowInMarquee CHAR(1) NULL, -- A = Always, O = Only when open, NULL = Never + TradeDayStart datetime NULL, + TradeDayEnd datetime NULL, + LastUpdated datetime NULL, CONSTRAINT PK_Instrument PRIMARY KEY CLUSTERED (InstrumentID), + CONSTRAINT UC_Instrument_Symbol UNIQUE NONCLUSTERED (Symbol), --CONSTRAINT FK_Instrument_Exchange FOREIGN KEY (ExchangeID) REFERENCES Exchange (ExchangeID) ) -GO +GO --CREATE NONCLUSTERED INDEX IDX_Instrument_ExchangeID_Symbol ON Instrument (ExchangeID, Symbol) -CREATE NONCLUSTERED INDEX IDX_Instrument_Symbol ON Instrument (Symbol) +--CREATE NONCLUSTERED INDEX IDX_Instrument_Symbol ON Instrument (Symbol) CREATE NONCLUSTERED INDEX IDX_Instrument_DisplayOrder ON Instrument (DisplayOrder) GO CREATE TABLE InstrumentHistory_Daily ( InstrumentID smallint NOT NULL, HistoryDT date NOT NULL, - OpenPrice money NULL, - HighPrice money NULL, - LowPrice money NULL, - ClosePrice money NULL, + --OpenPrice money NULL, + --HighPrice money NULL, + --LowPrice money NULL, + --ClosePrice money NULL, + OpenPrice real NULL, + HighPrice real NULL, + LowPrice real NULL, + ClosePrice real NULL, Volume bigint NULL, CONSTRAINT PK_InstrumentHistory_Daily PRIMARY KEY CLUSTERED (InstrumentID, HistoryDT), CONSTRAINT FK_InstrumentHistory_Daily_Instrument FOREIGN KEY (InstrumentID) REFERENCES Instrument (InstrumentID) @@ -79,10 +100,14 @@ GO CREATE TABLE InstrumentHistory_Intraday ( InstrumentID smallint NOT NULL, HistoryDT smalldatetime NOT NULL, - OpenPrice money NULL, - HighPrice money NULL, - LowPrice money NULL, - ClosePrice money NULL, + --OpenPrice money NULL, + --HighPrice money NULL, + --LowPrice money NULL, + --ClosePrice money NULL, + OpenPrice real NULL, + HighPrice real NULL, + LowPrice real NULL, + ClosePrice real NULL, Volume bigint NULL, CONSTRAINT PK_InstrumentHistory_Intraday PRIMARY KEY CLUSTERED (InstrumentID, HistoryDT), CONSTRAINT FK_InstrumentHistory_Intraday_Instrument FOREIGN KEY (InstrumentID) REFERENCES Instrument (InstrumentID) @@ -103,16 +128,20 @@ INSERT Account (ShortName) VALUES ('Steph ii ISA'), ('Steph ii Trd'), ('Steve ii Trd'), + ('Steve ii ISA'), ('Steve AJB'), - ('Steph AJB') + ('Steph AJB'), + ('Steve Crypto') GO CREATE TABLE Holding ( HoldingID int IDENTITY NOT NULL, AccountID tinyint NOT NULL, InstrumentID smallint NOT NULL, - NoUnits int NOT NULL, - PurchasePricePerUnit money NOT NULL, + --NoUnits int NOT NULL, + NoUnits real NOT NULL, + --PurchasePricePerUnit money NOT NULL, + PurchasePricePerUnit real NOT NULL, PurchaseDate datetime NOT NULL, SoldDate datetime NULL, CONSTRAINT PK_Holding PRIMARY KEY CLUSTERED (HoldingID), @@ -124,10 +153,14 @@ GO CREATE TYPE PriceDataType AS TABLE ( PriceDT datetime NOT NULL, - OpenPrice money NULL, - HighPrice money NULL, - LowPrice money NULL, - ClosePrice money NULL, + --OpenPrice money NULL, + --HighPrice money NULL, + --LowPrice money NULL, + --ClosePrice money NULL, + OpenPrice real NULL, + HighPrice real NULL, + LowPrice real NULL, + ClosePrice real NULL, Volume bigint NULL ) GO @@ -147,7 +180,7 @@ BEGIN SELECT @DisplayOrder = ISNULL(@DisplayOrder, 1) --INSERT Instrument (ExchangeID, Symbol, FullName, DisplayOrder) SELECT @ExchangeID, @Symbol, @FullName, @DisplayOrder WHERE NOT EXISTS (SELECT NULL FROM Instrument WHERE ExchangeID = @ExchangeID AND Symbol = @Symbol) - INSERT Instrument (Symbol, FullName, DisplayOrder) SELECT @Symbol, @FullName, @DisplayOrder + INSERT Instrument (Symbol, FullName, DisplayOrder, PostPandemicDilution) SELECT @Symbol, @FullName, @DisplayOrder, 1 SELECT i.DisplayOrder, i.FullName as [InstrumentName], @@ -165,6 +198,7 @@ END GO GRANT EXECUTE ON usp_InsertInstrument TO WebApp_Role GO +/* EXEC usp_InsertInstrument '^AXJO', 'S&P ASX 200' EXEC usp_InsertInstrument 'QAN.AX', 'Qantas' EXEC usp_InsertInstrument 'WEB.AX', 'Webjet' @@ -197,6 +231,7 @@ EXEC usp_InsertInstrument 'EBAY', 'E-bay' EXEC usp_InsertInstrument 'GBPUSD=X', 'GBP/USD' EXEC usp_InsertInstrument 'GBPAUD=X', 'GBP/AUD' GO +*/ /* @@ -206,6 +241,33 @@ delete Instrument where InstrumentID>31 */ +--CREATE PROCEDURE usp_UpdateInstrument (@Symbol varchar(8), @GMTOffset int, @Currency varchar(3), @CurrentPrice money, @InstrumentType varchar(15), @TradeDayStart datetime, @TradeDayEnd datetime) +CREATE PROCEDURE usp_UpdateInstrument (@Symbol varchar(8), @GMTOffset int, @Currency varchar(3), @CurrentPrice real, @InstrumentType varchar(15), @TradeDayStart datetime, @TradeDayEnd datetime) +AS +BEGIN + SET NOCOUNT ON + DECLARE @DisplayOrder tinyint + + UPDATE + Instrument + SET + --DisplayName VARCHAR(30) NULL, + --PostPandemicDilution money NOT NULL, + --ShowInMarquee CHAR(1) NULL, -- A = Always, O = Only when open, NULL = Never + GMTOffset = @GMTOffset, + Currency = @Currency, + CurrentPrice = @CurrentPrice, + InstrumentType = @InstrumentType, + TradeDayStart = @TradeDayStart, + TradeDayEnd = @TradeDayEnd, + LastUpdated = CURRENT_TIMESTAMP + WHERE + Symbol = @Symbol +END +GO +GRANT EXECUTE ON usp_UpdateInstrument TO WebApp_Role +GO + CREATE PROCEDURE usp_GetAccounts AS BEGIN @@ -231,7 +293,16 @@ BEGIN i.DisplayOrder, --e.ShortName as [Exchange], i.FullName as [InstrumentName], + ISNULL(i.DisplayName, LEFT(i.FullName, 30)) as [DisplayName], i.Symbol as [Symbol], + i.PostPandemicDilution as [PostPandemicDilution], + i.GMTOffset as [GMTOffset], + i.Currency as [Currency], + i.CurrentPrice as [CurrentPrice], + i.InstrumentType as [InstrumentType], + i.ShowInMarquee as [ShowInMarquee], + i.TradeDayStart as [SingleDayStartDate], + i.TradeDayEnd as [SingleDayEndDate], ISNULL((SELECT MIN(dd.HistoryDT) FROM InstrumentHistory_Daily dd WHERE dd.InstrumentID = i.InstrumentID), CONVERT(DATETIME, '2030-12-31')) as [MinDailyDate], ISNULL((SELECT MAX(dd.HistoryDT) FROM InstrumentHistory_Daily dd WHERE dd.InstrumentID = i.InstrumentID), CONVERT(DATETIME, '1970-01-01')) as [MaxDailyDate], ISNULL((SELECT MIN(id.HistoryDT) FROM InstrumentHistory_Intraday id WHERE id.InstrumentID = i.InstrumentID), CONVERT(DATETIME, '2030-12-31')) as [MinIntradayDate], @@ -309,13 +380,14 @@ AS BEGIN SET NOCOUNT ON DECLARE @InstrumentID int - DECLARE @NoUpdated int + --DECLARE @NoUpdated int DECLARE @NoInserted int SELECT @InstrumentID = InstrumentID FROM Instrument WHERE Symbol = @Symbol IF @InstrumentID IS NOT NULL BEGIN + /* UPDATE h SET @@ -331,6 +403,7 @@ BEGIN AND h.HistoryDT = CONVERT(date, d.PriceDT) SET @NoUpdated = @@ROWCOUNT + */ INSERT InstrumentHistory_Daily ( InstrumentID, @@ -342,7 +415,7 @@ BEGIN Volume) SELECT @InstrumentID, - CONVERT(date, PriceDT), + CONVERT(date, DATEADD(hour, 1, PriceDT)), --Add an hour to the input datetime before converting to date to allow for changes in daylight savings OpenPrice, HighPrice, LowPrice, @@ -351,11 +424,11 @@ BEGIN FROM @PriceData d WHERE - NOT EXISTS (SELECT NULL FROM InstrumentHistory_Daily h WHERE h.InstrumentID = @InstrumentID AND h.HistoryDT = CONVERT(date, d.PriceDT)) + NOT EXISTS (SELECT NULL FROM InstrumentHistory_Daily h WHERE h.InstrumentID = @InstrumentID AND h.HistoryDT = CONVERT(date, DATEADD(hour, 1, PriceDT))) SET @NoInserted = @@ROWCOUNT - SELECT @NoInserted as [NoInserted], @NoUpdated as [NoUpdated] + SELECT @NoInserted as [NoInserted] /*, @NoUpdated as [NoUpdated]*/ END ELSE BEGIN @@ -428,7 +501,8 @@ GO GRANT EXECUTE ON usp_InsertIntradayData TO WebApp_Role GO -CREATE PROCEDURE usp_InsertHolding (@Account varchar(20), @Symbol varchar(8), @NoUnits int, @PurchasePricePerUnit money, @PurchaseDate datetime, @Solddate datetime = NULL) +--CREATE PROCEDURE usp_InsertHolding (@Account varchar(20), @Symbol varchar(8), @NoUnits int, @PurchasePricePerUnit money, @PurchaseDate datetime, @Solddate datetime = NULL) +CREATE PROCEDURE usp_InsertHolding (@Account varchar(20), @Symbol varchar(8), @NoUnits real, @PurchasePricePerUnit real, @PurchaseDate datetime, @Solddate datetime = NULL) AS BEGIN DECLARE @AccountID tinyint @@ -473,76 +547,77 @@ END GO GRANT EXECUTE ON usp_InsertHolding TO WebApp_Role GO --- EXEC usp_InsertHolding 'Steve ii Trd', 'QAN.AX', 15700, 3.63, '2020-04-28', '2020-06-12' --- EXEC usp_InsertHolding 'Steve ii Trd', 'WEB.AX', 17000, 2.55, '2020-04-28', '2020-06-12' --- EXEC usp_InsertHolding 'Steve ii Trd', 'WBC.AX', 2240, 15.07, '2020-05-13', '2020-06-12' --- EXEC usp_InsertHolding 'Steve ii Trd', 'FLT.AX', 3500, 13.813, '2020-06-03', '2020-06-12' --- EXEC usp_InsertHolding 'Steve ii Trd', 'WEB.AX', 20618, 3.0359, '2020-07-22 05:37', NULL + +-- EXEC usp_InsertHolding 'Steph AJB', 'TMPL.L', 2372, 708, '2020-05-13' +-- EXEC usp_InsertHolding 'Steph AJB', 'SDV.L', 2000, 127, '2020-05-17', '2020-06-12' +-- EXEC usp_InsertHolding 'Steph AJB', 'BP.L', 5787, 311, '2020-05-13' +-- EXEC usp_InsertHolding 'Steph AJB', 'RDSB.L', 1897, 1264.88, '2020-05-11' +-- EXEC usp_InsertHolding 'Steph AJB', 'LLOY.L', 59170, 30.42, '2020-05-11' +-- EXEC usp_InsertHolding 'Steph AJB', 'BARC.L', 17261, 104.28, '2020-05-11' + +-- EXEC usp_InsertHolding 'Steph HL Trd', 'EBAY', 949, 39.35, '2020-04-29', '2020-06-11' +-- EXEC usp_InsertHolding 'Steph HL Trd', 'NCLH', 1696, 21.72, '2020-06-10', '2020-06-11' +-- EXEC usp_InsertHolding 'Steph HL Trd', 'AMZN', 15, 2375.18, '2020-04-29', '2020-06-05' +-- EXEC usp_InsertHolding 'Steph HL Trd', 'IAG.L', 6644, 325.1, '2020-06-05' +-- EXEC usp_InsertHolding 'Steph HL Trd', 'RR.L', 5783, 335.08, '2020-06-05' +-- EXEC usp_InsertHolding 'Steph HL Trd', 'RR.L', 19276, 32.00, '2020-11-09' + +-- EXEC usp_InsertHolding 'Steph ii ISA', 'AAL', 2170, 11.5245, '2020-07-21 12:13', NULL +-- EXEC usp_InsertHolding 'Steph ii ISA', 'FLT.AX', 2705, 11.63, '2020-08-20 01:10', NULL +-- EXEC usp_InsertHolding 'Steph ii ISA', 'RCL', 1050, 54.15 , '2020-05-27', '2020-06-11' +-- EXEC usp_InsertHolding 'Steph ii ISA', 'GME', 125, 125.033296, '2021-02-25 15:01', NULL +-- EXEC usp_InsertHolding 'Steph ii ISA', 'AAL', 1840, 20.845949, '2021-02-26 14:13', NULL + +-- EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 2650, 17.8, '2020-05-27', '2020-06-11' +-- EXEC usp_InsertHolding 'Steph ii Trd', 'AML.L', 9985, 67.1, '2020-06-04', '2020-06-12' -- EXEC usp_InsertHolding 'Steph ii Trd', 'CBA.AX', 580, 59.00, '2020-05-13', '2020-06-12' -- EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 2580, 19.037, '2020-07-21 11:55', NULL -- EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 2580, 15.1690, '2020-07-21 11:55', NULL -- EXEC usp_InsertHolding 'Steph ii Trd', 'RCL', 1071, 53.7053, '2020-07-21 12:01', NULL -- EXEC usp_InsertHolding 'Steph ii Trd', 'RCL', 1078, 53.192, '2020-07-21 12:18', NULL --- EXEC usp_InsertHolding 'Steph ii ISA', 'AAL', 2170, 11.5245, '2020-07-21 12:13', NULL --- EXEC usp_InsertHolding 'Steph ii ISA', 'FLT.AX', 2705, 11.63, '2020-08-20 01:10', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'MKS.L', 33546, 138.59, '2021-02-22 14:58', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'CUK', 3250, 21.54336, '2021-02-22 15:04', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'AAL', 1700, 20.42657, '2021-02-22 15:11', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'RR.L', 28762, 100.8243, '2021-02-22 15:15', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'TUI.L', 5119, 376.9953, '2021-02-22 15:17', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'RCL', 2149, 80.8007, '2021-02-22 14:44', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 2100, 27.5428, '2021-02-22 14:51', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'WEB.AX', 14500, 5.42542, '2021-02-23 00:17', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 960, 21.1690, '2020-11-18 15:55', NULL +-- EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 40, 21.08, '2020-11-18 15:58', NULL -EXEC usp_InsertHolding 'Steve AJB', 'TMPL.L', 5623, 708, '2020-05-13' -EXEC usp_InsertHolding 'Steve AJB', 'MKS.L', 33546, 89, '2020-05-11' + + +-- EXEC usp_InsertHolding 'Steve AJB', 'TMPL.L', 5623, 708, '2020-05-13' +-- EXEC usp_InsertHolding 'Steve AJB', 'MKS.L', 33546, 89, '2020-05-11' -- EXEC usp_InsertHolding 'Steve AJB', 'CCL', 2334, 17.44, '2020-06-03', '2020-06-11' -EXEC usp_InsertHolding 'Steph AJB', 'TMPL.L', 2372, 708, '2020-05-13' --- EXEC usp_InsertHolding 'Steph AJB', 'SDV.L', 2000, 127, '2020-05-17', '2020-06-12' -EXEC usp_InsertHolding 'Steph AJB', 'BP.L', 5787, 311, '2020-05-13' -EXEC usp_InsertHolding 'Steph AJB', 'RDSB.L', 1897, 1264.88, '2020-05-11' -EXEC usp_InsertHolding 'Steph AJB', 'LLOY.L', 59170, 30.42, '2020-05-11' -EXEC usp_InsertHolding 'Steph AJB', 'BARC.L', 17261, 104.28, '2020-05-11' --- EXEC usp_InsertHolding 'Steph ii ISA', 'RCL', 1050, 54.15 , '2020-05-27', '2020-06-11' --- EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 2650, 17.8, '2020-05-27', '2020-06-11' --- EXEC usp_InsertHolding 'Steph ii Trd', 'AML.L', 9985, 67.1, '2020-06-04', '2020-06-12' +-- EXEC usp_InsertHolding 'Steve AJB', 'NCLH', 2322, 27.9475, '2021-02-22 14:55', NULL + -- EXEC usp_InsertHolding 'Steve HL ISA', 'NCLH', 3053, 17.27, '2020-05-27', '2020-06-11' -- EXEC usp_InsertHolding 'Steve HL ISA', 'NCLH', 3053, 17.27, '2020-05-17', '2020-06-24 18:24' -- EXEC usp_InsertHolding 'Steve HL ISA', 'CCL', 2667, 15.451, '2020-07-21 17:10', NULL +-- EXEC usp_InsertHolding 'Steve HL ISA', 'GME', 617, 119.986797, '2021-02-25 14:55', NULL +-- EXEC usp_InsertHolding 'Steve HL ISA', 'GME', 527, 124.422968, '2021-02-25 15:01', NULL + -- EXEC usp_InsertHolding 'Steve HL Trd', 'AAL', 2994, 12.35, '2020-05-27', '2020-06-11' -EXEC usp_InsertHolding 'Steph HL Trd', 'IAG.L', 6644, 325.1, '2020-06-05' -EXEC usp_InsertHolding 'Steve HL Trd', 'TUI.L', 4010, 490.93, '2020-06-05' --- EXEC usp_InsertHolding 'Steph HL Trd', 'EBAY', 949, 39.35, '2020-04-29', '2020-06-11' --- EXEC usp_InsertHolding 'Steph HL Trd', 'NCLH', 1696, 21.72, '2020-06-10', '2020-06-11' --- EXEC usp_InsertHolding 'Steph HL Trd', 'AMZN', 15, 2375.18, '2020-04-29', '2020-06-05' -EXEC usp_InsertHolding 'Steph HL Trd', 'RR.L', 5783, 335.08, '2020-06-05' -EXEC usp_InsertHolding 'Steph HL Trd', 'RR.L', 19276, 32.00, '2020-11-09' -EXEC usp_InsertHolding 'Steve ii Trd', 'MAB.L', 9044, 227.2204, '2020-06-22 10:38', '2020-11-16 09:42' -EXEC usp_InsertHolding 'Steve ii Trd', 'JDW.L', 824, 11.3962, '2020-06-22 10:40', '2020-11-25 12:47' -EXEC usp_InsertHolding 'Steve ii Trd', 'RTN.L', 39894, 0.70936, '2020-06-22 10:34', '2020-12-02 10:50' -EXEC usp_InsertHolding 'Steve ii Trd', 'AML.L', 1078, 1854.724, '2020-12-24 09:22', NULL -EXEC usp_InsertHolding 'Steve ii Trd', 'IAG.L', 10911, 166.3459, '2020-12-24 09:28', NULL -EXEC usp_InsertHolding 'Steve ii Trd', 'CCL.L', 2576, 1203.112, '2020-11-16 12:56', NULL -EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 960, 21.1690, '2020-11-18 15:55', NULL -EXEC usp_InsertHolding 'Steph ii Trd', 'NCLH', 40, 21.08, '2020-11-18 15:58', NULL +-- EXEC usp_InsertHolding 'Steve HL Trd', 'TUI.L', 4010, 490.93, '2020-06-05' +-- EXEC usp_InsertHolding 'Steve HL Trd', 'TUI.L', 3456, 95.745, '2021-01-21', NULL +-- EXEC usp_InsertHolding 'Steve ii Trd', 'QAN.AX', 15700, 3.63, '2020-04-28', '2020-06-12' +-- EXEC usp_InsertHolding 'Steve ii Trd', 'WEB.AX', 17000, 2.55, '2020-04-28', '2020-06-12' +-- EXEC usp_InsertHolding 'Steve ii Trd', 'WBC.AX', 2240, 15.07, '2020-05-13', '2020-06-12' +-- EXEC usp_InsertHolding 'Steve ii Trd', 'FLT.AX', 3500, 13.813, '2020-06-03', '2020-06-12' +-- EXEC usp_InsertHolding 'Steve ii Trd', 'WEB.AX', 20618, 3.0359, '2020-07-22 05:37', NULL +-- EXEC usp_InsertHolding 'Steve ii Trd', 'GME', 512, 54.17987, '2021-02-24 20:05', NULL +-- EXEC usp_InsertHolding 'Steve ii Trd', 'MAB.L', 9044, 227.2204, '2020-06-22 10:38', '2020-11-16 09:42' +-- EXEC usp_InsertHolding 'Steve ii Trd', 'JDW.L', 824, 11.3962, '2020-06-22 10:40', '2020-11-25 12:47' +-- EXEC usp_InsertHolding 'Steve ii Trd', 'RTN.L', 39894, 0.70936, '2020-06-22 10:34', '2020-12-02 10:50' +-- EXEC usp_InsertHolding 'Steve ii Trd', 'AML.L', 1078, 1854.724, '2020-12-24 09:22', NULL +-- EXEC usp_InsertHolding 'Steve ii Trd', 'IAG.L', 10911, 166.3459, '2020-12-24 09:28', NULL +-- EXEC usp_InsertHolding 'Steve ii Trd', 'CCL.L', 2576, 1203.112, '2020-11-16 12:56', NULL +-- EXEC usp_InsertHolding 'Steve ii Trd', 'ARB.L', 11459, 261.7805, '2021-03-01 11:25', NULL GO -CREATE VIEW vHolding -AS - SELECT - h.HoldingID, - a.ShortName as [AccountName], - i.Symbol, - i.FullName as [InstrumentName], - h.PurchaseDate, - h.NoUnits, - h.PurchasePricePerUnit, - h.SoldDate - FROM - Holding h - INNER JOIN Instrument i - ON i.InstrumentId = h.InstrumentId - INNER JOIN Account a - ON a.AccountID = h.AccountID -GO - --- select * from vholding where instrumentname like '%caribb%' - --- update holding set solddate = '2020-06-24 18:27' where holdingid = 34 - CREATE PROCEDURE usp_GetHoldings AS BEGIN @@ -613,6 +688,7 @@ GO GRANT EXECUTE ON usp_GetHoldingsHistory TO WebApp_Role GO +/* CREATE PROCEDURE usp_DeleteHolding (@HoldingID int) AS BEGIN @@ -622,6 +698,173 @@ END GO GRANT EXECUTE ON usp_DeleteHolding TO WebApp_Role GO +*/ +CREATE PROCEDURE usp_SoldHolding (@HoldingID int, @SoldDate datetime) +AS +BEGIN + UPDATE Holding SET SoldDate = @SoldDate WHERE HoldingID = @HoldingID + SELECT @@ROWCOUNT AS [RecordsUpdated] +END +GO +GRANT EXECUTE ON usp_SoldHolding TO WebApp_Role +GO + +CREATE PROCEDURE usp_SwapDisplayOrder (@Symbol1 varchar(8), @Symbol2 varchar(8)) +AS +BEGIN + DECLARE @OldDisplayOrder1 TINYINT + DECLARE @OldDisplayOrder2 TINYINT + + SELECT @OldDisplayOrder1 = DisplayOrder FROM Instrument WHERE Symbol = @Symbol1 + SELECT @OldDisplayOrder2 = DisplayOrder FROM Instrument WHERE Symbol = @Symbol2 + + UPDATE + Instrument + SET + DisplayOrder = CASE + WHEN Symbol = @Symbol1 THEN @OldDisplayOrder2 + WHEN Symbol = @Symbol2 THEN @OldDisplayOrder1 + END + WHERE + Symbol IN (@Symbol1, @Symbol2) + + SELECT + @Symbol1 as [Symbol1], + @OldDisplayOrder2 as [Symbol1NewDisplayOrder], + @Symbol2 as [Symbol2], + @OldDisplayOrder1 as [Symbol2NewDisplayOrder] +END +GO +GRANT EXECUTE ON usp_SwapDisplayOrder TO WebApp_Role +GO + +CREATE VIEW vHolding +AS + SELECT + h.HoldingID, + a.ShortName as [AccountName], + i.Symbol, + i.FullName as [InstrumentName], + h.PurchaseDate, + h.NoUnits, + h.PurchasePricePerUnit, + h.SoldDate + FROM + Holding h + INNER JOIN Instrument i + ON i.InstrumentId = h.InstrumentId + INNER JOIN Account a + ON a.AccountID = h.AccountID +GO + +CREATE VIEW vErroneousPrices_Daily +AS +SELECT + i.InstrumentID, + i.Symbol, + i.FullName, + p.HistoryDT as [PreviousHistoryDT], + d1.HistoryDT as [HistoryDT], + n.HistoryDT as [NextHistoryDT], + p.OpenPrice as [PreviousOpen], + d1.OpenPrice as [Open], + n.OpenPrice as [NextOpen], + p.HighPrice as [PreviousHigh], + d1.HighPrice as [High], + n.HighPrice as [NextHigh], + p.LowPrice as [PreviousLow], + d1.LowPrice as [Low], + n.LowPrice as [NextLow], + p.ClosePrice as [PreviousClose], + d1.ClosePrice as [Close], + n.ClosePrice as [NextClose] +FROM + Instrument i + INNER JOIN InstrumentHistory_Daily d1 + ON d1.InstrumentID = i.InstrumentID + INNER JOIN InstrumentHistory_Daily p + ON p.InstrumentID = d1.InstrumentID + AND p.HistoryDT = (SELECT MAX(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT < d1.HistoryDT) + INNER JOIN InstrumentHistory_Daily n + ON n.InstrumentID = d1.InstrumentID + AND n.HistoryDT = (SELECT MIN(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT > d1.HistoryDT) +WHERE + (p.OpenPrice/CASE WHEN d1.OpenPrice = 0 THEN 0.0000001 ELSE d1.OpenPrice END > 90 AND n.OpenPrice/CASE WHEN d1.OpenPrice = 0 THEN 0.0000001 ELSE d1.OpenPrice END > 90) + OR (p.HighPrice/CASE WHEN d1.HighPrice = 0 THEN 0.0000001 ELSE d1.HighPrice END > 90 AND n.HighPrice/CASE WHEN d1.HighPrice = 0 THEN 0.0000001 ELSE d1.HighPrice END > 90) + OR (p.LowPrice/CASE WHEN d1.LowPrice = 0 THEN 0.0000001 ELSE d1.LowPrice END > 90 AND n.LowPrice/CASE WHEN d1.LowPrice = 0 THEN 0.0000001 ELSE d1.LowPrice END > 90) + OR (p.ClosePrice/CASE WHEN d1.ClosePrice = 0 THEN 0.0000001 ELSE d1.ClosePrice END > 90 AND n.ClosePrice/CASE WHEN d1.ClosePrice = 0 THEN 0.0000001 ELSE d1.ClosePrice END > 90) +GO + +CREATE VIEW vErroneousPrices_Intraday +AS +SELECT + i.InstrumentID, + i.Symbol, + i.FullName, + p.HistoryDT as [PreviousHistoryDT], + d1.HistoryDT as [HistoryDT], + n.HistoryDT as [NextHistoryDT], + p.OpenPrice as [PreviousOpen], + d1.OpenPrice as [Open], + n.OpenPrice as [NextOpen], + p.HighPrice as [PreviousHigh], + d1.HighPrice as [High], + n.HighPrice as [NextHigh], + p.LowPrice as [PreviousLow], + d1.LowPrice as [Low], + n.LowPrice as [NextLow], + p.ClosePrice as [PreviousClose], + d1.ClosePrice as [Close], + n.ClosePrice as [NextClose] +FROM + Instrument i + INNER JOIN InstrumentHistory_Intraday d1 + ON d1.InstrumentID = i.InstrumentID + INNER JOIN InstrumentHistory_Intraday p + ON p.InstrumentID = d1.InstrumentID + AND p.HistoryDT = (SELECT MAX(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT < d1.HistoryDT) + INNER JOIN InstrumentHistory_Intraday n + ON n.InstrumentID = d1.InstrumentID + AND n.HistoryDT = (SELECT MIN(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT > d1.HistoryDT) +WHERE + (p.OpenPrice/CASE WHEN d1.OpenPrice = 0 THEN 0.0000001 ELSE d1.OpenPrice END > 90 AND n.OpenPrice/CASE WHEN d1.OpenPrice = 0 THEN 0.0000001 ELSE d1.OpenPrice END > 90) + OR (p.HighPrice/CASE WHEN d1.HighPrice = 0 THEN 0.0000001 ELSE d1.HighPrice END > 90 AND n.HighPrice/CASE WHEN d1.HighPrice = 0 THEN 0.0000001 ELSE d1.HighPrice END > 90) + OR (p.LowPrice/CASE WHEN d1.LowPrice = 0 THEN 0.0000001 ELSE d1.LowPrice END > 90 AND n.LowPrice/CASE WHEN d1.LowPrice = 0 THEN 0.0000001 ELSE d1.LowPrice END > 90) + OR (p.ClosePrice/CASE WHEN d1.ClosePrice = 0 THEN 0.0000001 ELSE d1.ClosePrice END > 90 AND n.ClosePrice/CASE WHEN d1.ClosePrice = 0 THEN 0.0000001 ELSE d1.ClosePrice END > 90) +GO + +CREATE VIEW vDataQuality_Prices +AS +SELECT + i.InstrumentID, + i.Symbol, + i.FullName, + p.HistoryDT as [PreviousHistoryDT], + d1.HistoryDT as [HistoryDT], + n.HistoryDT as [NextHistoryDT], + p.OpenPrice as [PreviousOpen], + d1.OpenPrice as [Open], + n.OpenPrice as [NextOpen], + p.HighPrice as [PreviousHigh], + d1.HighPrice as [High], + n.HighPrice as [NextHigh], + p.LowPrice as [PreviousLow], + d1.LowPrice as [Low], + n.LowPrice as [NextLow], + p.ClosePrice as [PreviousClose], + d1.ClosePrice as [Close], + n.ClosePrice as [NextClose] +FROM + Instrument i + INNER JOIN InstrumentHistory_Daily d1 + ON d1.InstrumentID = i.InstrumentID + INNER JOIN InstrumentHistory_Daily p + ON p.InstrumentID = d1.InstrumentID + AND p.HistoryDT = (SELECT MAX(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT < d1.HistoryDT) + INNER JOIN InstrumentHistory_Daily n + ON n.InstrumentID = d1.InstrumentID + AND n.HistoryDT = (SELECT MIN(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT > d1.HistoryDT) +GO /* @@ -634,8 +877,35 @@ select * from InstrumentHistory_Intraday where InstrumentID = 18 order by Histor --Delete daily prices that are 90% less than previous and next daily prices DELETE d1 +select * FROM - InstrumentHistory_Daily d1 + Instrument i + INNER JOIN InstrumentHistory_Daily d1 + ON d1.InstrumentID = i.InstrumentID + INNER JOIN InstrumentHistory_Daily p + ON p.InstrumentID = d1.InstrumentID + AND p.HistoryDT = (SELECT MAX(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT < d1.HistoryDT) + INNER JOIN InstrumentHistory_Daily n + ON n.InstrumentID = d1.InstrumentID + AND n.HistoryDT = (SELECT MIN(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT > d1.HistoryDT) +WHERE + (p.ClosePrice/d1.ClosePrice > 90 + AND n.ClosePrice/d1.ClosePrice > 90) + OR + (p.OpenPrice/d1.OpenPrice > 90 + AND n.OpenPrice/d1.OpenPrice > 90) + OR + (p.HighPrice/d1.HighPrice > 90 + AND n.HighPrice/d1.HighPrice > 90) + OR + (p.LowPrice/d1.LowPrice > 90 + AND n.LowPrice/d1.LowPrice > 90) + +SELECT * +FROM + Instrument i + INNER JOIN InstrumentHistory_Daily d1 + ON d1.InstrumentID = i.InstrumentID INNER JOIN InstrumentHistory_Daily p ON p.InstrumentID = d1.InstrumentID AND p.HistoryDT = (SELECT MAX(HistoryDT) FROM InstrumentHistory_Daily WHERE InstrumentID = d1.InstrumentID AND HistoryDT < d1.HistoryDT) @@ -646,4 +916,8 @@ WHERE p.ClosePrice/d1.ClosePrice > 90 AND n.ClosePrice/d1.ClosePrice > 90 + +select * from Instrument i inner join InstrumentHistory_Daily d on d.InstrumentID = i.InstrumentID +where i.Symbol = 'IAG.L' and d.HistoryDT between '2020-10-05' and '2020-10-07' order by d.HistoryDT + */ diff --git a/Websites/SharePrices/SharePrices/FlotTest.html b/Websites/SharePrices/SharePrices/FlotTest.html index 6beb0c0..00d6281 100644 --- a/Websites/SharePrices/SharePrices/FlotTest.html +++ b/Websites/SharePrices/SharePrices/FlotTest.html @@ -6,8 +6,87 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Col1Col2Col3Col4Col5Col6Col7Col8Col9
Value Col 1Value Col 2Value Col 3Value Col 4Value Col 5Value Col 6Value Col 7Value Col 8Value Col 9
Value Col 1 +
 
+
30%
+
+
 
+
60%
+
+
 
+
90%
+
Value Col 5Value Col 6Value Col 7Value Col 8Value Col 9
Value Col 1Value Col 2Value Col 3Value Col 4Value Col 5Value Col 6Value Col 7Value Col 8Value Col 9
+
diff --git a/Websites/SharePrices/SharePrices/Global.asax b/Websites/SharePrices/SharePrices/Global.asax new file mode 100644 index 0000000..f1235eb --- /dev/null +++ b/Websites/SharePrices/SharePrices/Global.asax @@ -0,0 +1 @@ +<%@ Application Codebehind="Global.asax.vb" Inherits="SharePrices.Global_asax" Language="vb" %> diff --git a/Websites/SharePrices/SharePrices/Global.asax.vb b/Websites/SharePrices/SharePrices/Global.asax.vb new file mode 100644 index 0000000..d727545 --- /dev/null +++ b/Websites/SharePrices/SharePrices/Global.asax.vb @@ -0,0 +1,42 @@ +Imports System.Diagnostics +Imports System.Web.SessionState + +Public Class Global_asax + Inherits System.Web.HttpApplication + + Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) + ' Fires when the application is started + Debug.Print("Global.asx:Application_Start") + End Sub + + Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) + ' Fires when the session is started + Debug.Print("Global.asx:Session_Start") + End Sub + + Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) + ' Fires at the beginning of each request + Debug.Print("Global.asx:Application_BeginRequest") + End Sub + + Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs) + ' Fires upon attempting to authenticate the use + Debug.Print("Global.asx:Application_AuthenticateRequest") + End Sub + + Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) + ' Fires when an error occurs + Debug.Print("Global.asx:Application_Error") + End Sub + + Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) + ' Fires when the session ends + Debug.Print("Global.asx:Session_End") + End Sub + + Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) + ' Fires when the application ends + Debug.Print("Global.asx:Application_End") + End Sub + +End Class \ No newline at end of file diff --git a/Websites/SharePrices/SharePrices/LayoutTest.html b/Websites/SharePrices/SharePrices/LayoutTest.html new file mode 100644 index 0000000..c02f3cf --- /dev/null +++ b/Websites/SharePrices/SharePrices/LayoutTest.html @@ -0,0 +1,63 @@ + + + + + + + +
+ Header div +
+
+
+ + Tab 1
+ Line1
+ Line2
+ Line3
+ Line4
+ Line5
+
+
+
+
+
+ + Tab 2
+ Line1
+ Line2
+ Line3
+ Line4
+ Line5
+ Line6
+ Line7
+ Line8
+ Line9
+ Line10
+
+
+
+ + diff --git a/Websites/SharePrices/SharePrices/SharePrices.aspx b/Websites/SharePrices/SharePrices/SharePrices.aspx index be5ac1d..608badc 100644 --- a/Websites/SharePrices/SharePrices/SharePrices.aspx +++ b/Websites/SharePrices/SharePrices/SharePrices.aspx @@ -5,35 +5,95 @@ Steve's share prices - - - + + + + + + + + + -
-
Charts
-
Current Holdings
-
Share Analysis
+
+
+
+ + + +
+
Charts
+
+
+
+
+
+ +
+
Holdings table
+
+ + + + + + + + + + +
Book Cost currencies
Current Value currencies
Book Cost per Account
Current Value per Account
+
+
+
+
+
+
+
+
+
Analysis
+
+
+
Log
+