-
Notifications
You must be signed in to change notification settings - Fork 7
/
Default.aspx.cs
246 lines (213 loc) · 13.4 KB
/
Default.aspx.cs
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using DataAccessLayer;
namespace Analytics
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "doHourglass", "doHourglass();", true);
if (!IsPostBack)
{
GetIndexValues(null, null);
RedrawGraphs(null, null);
}
Session["EMAILID"] = null;
Session["USERROWID"] = null;
Session["DATAFOLDER"] = UserManager.GetDataFolder();
//Stock Portfolio related
Session["STOCKPORTFOLIONAME"] = null;
Session["STOCKPORTFOLIOMASTERROWID"] = null;
Session["STOCKPORTFOLIOROWID"] = null;
Session["STOCKPORTFOLIOEXCHANGE"] = null;
Session["STOCKPORTFOLIOSCRIPTNAME"] = null;
Session["STOCKPORTFOLIOSCRIPTID"] = null;
Session["STOCKPORTFOLIOCOMPNAME"] = null;
Session["STOCKSELECTEDINDEXPORTFOLIO"] = null;
//Session["STOCKMASTERROWID"] = null;
//MF Portfolio related
Session["MFPORTFOLIONAME"] = null;
Session["MFPORTFOLIOMASTERROWID"] = null;
Session["MFPORTFOLIOROWID"] = null;
Session["MFSELECTEDINDEXPORTFOLIO"] = null;
Session["MFPORTFOLIOFUNDNAME"] = null;
Session["MFPORTFOLIOFUNDHOUSECODE"] = null;
Session["MFPORTFOLIOFUNDHOUSE"] = null;
Session["MFPORTFOLIOSCHEMECODE"] = null;
loginlink.HRef = "mlogin.aspx";
registerlink.HRef = "mlogin.aspx";
ClientScript.RegisterStartupScript(this.GetType(), "resetCursor", "resetCursor();", true);
}
/// <summary>
/// method gets called every 60seconds from timer. First time gets called from Onpageload
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GetIndexValues(object sender, EventArgs e)
{
//Use myQuote.close.Last() - myMeta.chartPreviousClose to show difference
//(myQuote.close.Last() - myMeta.chartPreviousClose) / myQuote.close.Last() * 100 to show percentage diff
StockManager stockManager = new StockManager();
StringBuilder indexString = new StringBuilder();
DataAccessLayer.Chart myChart;
DataAccessLayer.Result myResult;
DataAccessLayer.Meta myMeta;
DataAccessLayer.Indicators myIndicators;
DataAccessLayer.Quote myQuote;
DateTime myDate;
DataAccessLayer.Root myDeserializedClass = stockManager.getIndexIntraDayAlternate("^BSESN", time_interval: "1min", outputsize: "compact");
if (myDeserializedClass != null)
{
myChart = myDeserializedClass.chart;
myResult = myChart.result[0];
myMeta = myResult.meta;
myIndicators = myResult.indicators;
////this will be typically only 1 row and quote will have list of close, high, low, open, volume
myQuote = myIndicators.quote[0];
////this will be typically only 1 row and adjClose will have list of adjClose
//Adjclose myAdjClose = null;
//myAdjClose = myIndicators.adjclose[0];
//DateTime myDate = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(myResult.timestamp.Last()).ToLocalTime();
myDate = stockManager.convertUnixEpochToLocalDateTime(myResult.timestamp.Last(), myMeta.timezone);
indexString.Append(string.Format("SENSEX@{0:HH:mm}: ", myDate));
indexString.Append(string.Format("{0:0.00}|", myQuote.close.Last()));
indexString.Append(string.Format("{0:0.00}|", myQuote.close.Last() - myMeta.chartPreviousClose));
indexString.Append(string.Format("{0:0.00}% ", (myQuote.close.Last() - myMeta.chartPreviousClose) / myQuote.close.Last() * 100));
}
myDeserializedClass = stockManager.getIndexIntraDayAlternate("^NSEI", time_interval: "1min", outputsize: "compact");
if (myDeserializedClass != null)
{
myChart = myDeserializedClass.chart;
myResult = myChart.result[0];
myMeta = myResult.meta;
myIndicators = myResult.indicators;
////this will be typically only 1 row and quote will have list of close, high, low, open, volume
myQuote = myIndicators.quote[0];
//myDate = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(myResult.timestamp.Last()).ToLocalTime();
//myDate = StockApi.convertUnixEpochToLocalDateTime(myResult.timestamp.Last(), myMeta.timezone);
myDate = stockManager.convertUnixEpochToLocalDateTime(myResult.timestamp.Last(), myMeta.timezone);
indexString.Append(string.Format("| NIFTY@{0:HH:mm}: ", myDate));
indexString.Append(string.Format("{0:0.00}|", myQuote.close.Last()));
indexString.Append(string.Format("{0:0.00}|", myQuote.close.Last() - myMeta.chartPreviousClose));
indexString.Append(string.Format("{0:0.00}%", (myQuote.close.Last() - myMeta.chartPreviousClose) / myQuote.close.Last() * 100));
}
headingtext.Text = indexString.ToString();
//headingtext.CssClass = headingtext.CssClass.Replace("blinking blinkingText", "");
headingtext.CssClass = headingtext.CssClass.Replace("fade", "");
}
protected void ClearHeading(object sender, EventArgs e)
{
headingtext.CssClass = "fade";
//headingtext.Text = "";
}
protected void RedrawGraphs(object sender, EventArgs e)
{
StockManager stockManager = new StockManager();
DataTable sensexTable = stockManager.GetStockPriceData("^BSESN", time_interval: "1m", fromDate: DateTime.Today.ToShortDateString());
if (chart1.Annotations.Count > 0)
chart1.Annotations.Clear();
if ((sensexTable != null) && (sensexTable.Rows.Count > 0))
{
chart1.Series["SENSEX"].ToolTip = "SENSEX" + ": Date:#VALX{g}; Close:#VALY1";
chart1.Series["SENSEX"].PostBackValue = "SENSEX," + "SENSEX" + ",#VALX{g},#VALY1,#VALY2,#VALY3,#VALY4";
chart1.Series["SENSEX"].Points.Clear();
chart1.Series["SENSEX"].Points.DataBindXY(sensexTable.Rows, "TIMESTAMP", sensexTable.Rows, "CLOSE,OPEN,HIGH,LOW");
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].MarkerSize = 5;
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].MarkerStyle = MarkerStyle.Cross;
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].Label = sensexTable.Rows[sensexTable.Rows.Count - 1]["CLOSE"].ToString();
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].LabelForeColor = System.Drawing.Color.Black;
}
else
{
sensexTable = stockManager.GetStockPriceData("^BSESN", time_interval: "1d", fromDate: DateTime.Today.AddDays(-10).ToShortDateString());
if ((sensexTable != null) && (sensexTable.Rows.Count > 0))
{
chart1.Series["SENSEX"].ToolTip = "SENSEX" + ": Date:#VALX; Close:#VALY1";
chart1.Series["SENSEX"].PostBackValue = "SENSEX," + "SENSEX" + ",#VALX,#VALY1,#VALY2,#VALY3,#VALY4";
chart1.Series["SENSEX"].XValueMember = "TIMESTAMP";
chart1.Series["SENSEX"].XValueType = ChartValueType.Date;
chart1.Series["SENSEX"].YValuesPerPoint = 4;
chart1.Series["SENSEX"].YValueMembers = "CLOSE,OPEN,HIGH,LOW";
chart1.ChartAreas["chartarea1"].AxisX2.LabelStyle.Format = "dd";
chart1.ChartAreas["chartarea1"].AxisX2.Title = "SENSEX - Last 10 days";
chart1.Series["SENSEX"].Points.Clear();
chart1.Series["SENSEX"].Points.DataBindXY(sensexTable.Rows, "TIMESTAMP", sensexTable.Rows, "CLOSE,OPEN,HIGH,LOW");
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].MarkerSize = 5;
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].MarkerStyle = MarkerStyle.Cross;
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].LabelForeColor = System.Drawing.Color.Black;
chart1.Series["SENSEX"].Points[chart1.Series["SENSEX"].Points.Count - 1].Label = sensexTable.Rows[sensexTable.Rows.Count - 1]["CLOSE"].ToString();
}
else
{
TextAnnotation noDataAnnotation = new TextAnnotation();
noDataAnnotation.Text = "No data available for BSE SENSEX";
noDataAnnotation.X = 5;
noDataAnnotation.Y = 5;
noDataAnnotation.Font = new System.Drawing.Font("Ariel", 15);
noDataAnnotation.ForeColor = System.Drawing.Color.Red;
chart1.Annotations.Add(noDataAnnotation);
}
}
if (chart2.Annotations.Count > 0)
chart2.Annotations.Clear();
DataTable niftyTable = stockManager.GetStockPriceData("^NSEI", time_interval: "1m", fromDate: DateTime.Today.ToShortDateString());
if ((niftyTable != null) && (niftyTable.Rows.Count > 0))
{
chart2.Series["NIFTY"].ToolTip = "NIFTY" + ": Date:#VALX{g}; Close:#VALY1";
chart2.Series["NIFTY"].PostBackValue = "SENSEX," + "SENSEX" + ",#VALX{g},#VALY1,#VALY2,#VALY3,#VALY4";
chart2.Series["NIFTY"].Points.Clear();
chart2.Series["NIFTY"].Points.DataBindXY(niftyTable.Rows, "TIMESTAMP", niftyTable.Rows, "CLOSE,OPEN,HIGH,LOW");
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].MarkerSize = 5;
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].MarkerStyle = MarkerStyle.Cross;
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].LabelForeColor = System.Drawing.Color.Black;
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].Label = niftyTable.Rows[niftyTable.Rows.Count - 1]["CLOSE"].ToString();
}
else
{
niftyTable = stockManager.GetStockPriceData("^NSEI", time_interval: "1d", fromDate: DateTime.Today.AddDays(-10).ToShortDateString());
if ((niftyTable != null) && (niftyTable.Rows.Count > 0))
{
chart2.Series["NIFTY"].ToolTip = "NIFTY" + ": Date:#VALX; Close:#VALY1";
chart2.Series["NIFTY"].PostBackValue = "NIFTY," + "SENSEX" + ",#VALX,#VALY1,#VALY2,#VALY3,#VALY4";
chart2.Series["NIFTY"].XValueMember = "TIMESTAMP";
chart2.Series["NIFTY"].XValueType = ChartValueType.Date;
chart2.Series["NIFTY"].YValuesPerPoint = 4;
chart2.Series["NIFTY"].YValueMembers = "CLOSE,OPEN,HIGH,LOW";
chart2.ChartAreas["chartarea2"].AxisX2.LabelStyle.Format = "dd";
chart2.ChartAreas["chartarea2"].AxisX2.Title = "NIFTY - Last 10 days";
chart2.Series["NIFTY"].Points.Clear();
chart2.Series["NIFTY"].Points.DataBindXY(niftyTable.Rows, "TIMESTAMP", niftyTable.Rows, "CLOSE,OPEN,HIGH,LOW");
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].MarkerSize = 5;
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].MarkerStyle = MarkerStyle.Cross;
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].LabelForeColor = System.Drawing.Color.Black;
chart2.Series["NIFTY"].Points[chart2.Series["NIFTY"].Points.Count - 1].Label = niftyTable.Rows[niftyTable.Rows.Count - 1]["CLOSE"].ToString();
}
else
{
TextAnnotation noDataAnnotation = new TextAnnotation();
noDataAnnotation.Text = "No data available for NIFTY";
noDataAnnotation.X = 5;
noDataAnnotation.Y = 5;
noDataAnnotation.Font = new System.Drawing.Font("Ariel", 15);
noDataAnnotation.ForeColor = System.Drawing.Color.Red;
chart2.Annotations.Add(noDataAnnotation);
}
}
}
//protected void Timer1_Tick(object sender, EventArgs e)
//{
// ViewState["counter"] = Int32.Parse(ViewState["counter"].ToString()) + 1;
// timertest.Text = ViewState["counter"].ToString();
// StockManager stockManager = new StockManager();
// stockManager.GetQuote()
//}
}
}