generated from Newton-School/html-css-js-project-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
340 lines (244 loc) · 9.42 KB
/
App.js
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
const button = document.getElementById("mainBtn");
const inputMain = document.getElementById("inputMain");
const IntraDayBtn = document.getElementById("intraday");
const dailyBtn = document.getElementById("daily")
const weeklyBtn = document.getElementById("weekly")
const monthlyBtn = document.getElementById("monthly")
let mainBtnClicked = false;
let intradayBtnClicked = false;
let dailyBtnClicked = false;
let weeklyBtnClicked = false;
let monthlyBtnClicked = false;
button.addEventListener("click", (event) => {
event.preventDefault();
const test = inputMain.value.toUpperCase();
console.log(test)
mainBtnClicked = true;
if (intradayBtnClicked) {
showDetails(test, "INTRADAY");
mainBtnClicked = false;
intradayBtnClicked = false;
}
else if (dailyBtnClicked) {
showDetails(test, "DAILY")
mainBtnClicked = false;
dailyBtnClicked = false;
}
else if (weeklyBtnClicked) {
showDetails(test, "WEEKLY")
mainBtnClicked = false;
weeklyBtnClicked = false;
}
else if (monthlyBtnClicked) {
showDetails(test, "MONTHLY")
mainBtnClicked = false;
monthlyBtn = false;
}
});
//Sabke button
IntraDayBtn.addEventListener("click", (event2) => {
event2.preventDefault();
intradayBtnClicked = true;
if (mainBtnClicked) {
showDetails("YOUR_DEFAULT_SYMBOL", "INTRADAY"); // Replace "YOUR_DEFAULT_SYMBOL" with the appropriate default symbol
mainBtnClicked = false;
intradayBtnClicked = false;
}
});
dailyBtn.addEventListener("click", (event3) => {
event3.preventDefault();
dailyBtnClicked = true;
if (mainBtnClicked) {
showDetails("Daily-Button")
mainBtnClicked = false;
dailyBtnClicked = false;
}
})
weeklyBtn.addEventListener("click", (event4) => {
event4.preventDefault();
weeklyBtnClicked = true;
if (mainBtnClicked) {
showDetails("Weekly-Butttons")
mainBtnClicked = false;
weeklyBtnClicked = false;
}
})
monthlyBtn.addEventListener("click", (event5) => {
event5.preventDefault();
monthlyBtnClicked = true;
if (mainBtnClicked) {
showDetails("Monthly Buttons")
mainBtnClicked = false;
monthlyBtnClicked = false;
}
})
async function showDetails(test, listener) {
console.log(test)
console.log(listener)
let response;
let sometime = `TIME_SERIES_${listener}`
response = await fetch(`https://www.alphavantage.co/query?function=${sometime}&symbol=${test}&interval=5min&apikey="XI0W15B1EW5UK7RH"`)
// response = await fetch(`https://www.alphavantage.co/query?function=${sometime}&symbol=${test}&apikey="1R0VK7FIB2TZ2YSS"`);
const data = await response.json();
console.log(sometime)
// const currentDate = new Date();
// const day = String(currentDate.getDate()-1).padStart(2, '0');
// const key = `2023-08-${day}`;
// let timeSeries;
// = data["Time Series (Daily)"][key]["1. open"];
// if (sometime === "TIME_SERIES_INTRADAY") {
// timeSeries = data["Time Series (5min)"]["2023-08-18 19:55:00"]["1. open"]
// } else if (sometime === "TIME_SERIES_WEEKLY") {
// timeSeries = data["Weekly Time Series"]["2023-08-18"]["1. open"]
// } else if (sometime === "TIME_SERIES_MONTHLY") {
// timeSeries = data["Monthly Time Series"]["2023-06-30"]["1. open"]
// } else if (sometime === "TIME_SERIES_DAILY") {
// timeSeries = data["Time Series (Daily)"]["2023-08-16"]["1. open"]
// }
// let valueOfTimeSeries;
// const OnlyIntraDay = data["Time Series (5min)"]
// const IntradayDates = Object.keys(OnlyIntraDay);
// const Dated = IntradayDates[0];
// const vallllues = OnlyIntraDay[Dated]
// const openIntradayValue = vallllues["1. open"]
if(listener === "DAILY"){
valueOfTimeSeries = data["Time Series (Daily)"]
}else if(listener === "MONTHLY"){
valueOfTimeSeries = data["Monthly Time Series"]
}else if(listener === "WEEKLY"){
valueOfTimeSeries = data["Weekly Time Series"]
}else{
let valueOfTimeSeries = data["Time Series (5min)"]
}
const dates = Object.keys(valueOfTimeSeries);
const date = dates[0];
const values = valueOfTimeSeries[date]
const openValue = values["1. open"];
console.log(openValue)
// console.log(timeSeries)
const MetaData = data["Meta Data"]["2. Symbol"];
const main = document.getElementById("main-sec");
const article = document.createElement("article");
article.classList.add("dynamic");
const p = document.createElement("p");
p.innerText = `${MetaData}`;
article.append(p);
const p2 = document.createElement("p");
p2.innerText = `${openValue}`;
p2.classList.add("innerContent");
const div = document.createElement("div");
div.classList.add("timeDiv")
// Color according to the bar everytime refresh
function getRandomColor(openValue) {
if (openValue >= 100) {
return 'green'
} else if (openValue > 60 && openValue <= 100) {
return 'white'
} else if (openValue <= 60) {
return 'red'
}
}
div.style.backgroundColor = getRandomColor(openValue);
div.append(p2);
article.append(div);
const p3 = document.createElement("p");
p3.innerText = `${listener}`;
const div2 = document.createElement("div");
div2.classList.add("tradeWay")
div2.append(p3);
article.append(div2);
const buttoncross = document.createElement("button");
buttoncross.classList.add("btnnn")
buttoncross.innerHTML = `<i class="fa-solid fa-xmark fa-2xl" style="color: #ffffff;"></i>`;
// button.addEventListener("click", ()=>{
// main.removeChild(article);
// })
article.append(buttoncross);
main.append(article);
let click = 0;
// let flag = false;
// article.classList.add("game")
article.addEventListener("click", (event) => {
// flag = true;
// event.stopImmediatePropagation()
let detailedModal = document.createElement("div");
// const sectio = document.getElementById("seme")
let rowDetail = document.createElement("ul");
if (click % 2 === 0) {
click++;
detailedModal.className = `name-detail detailed-model`;
detailedModal.innerHTML = `<ul class="detail-list">
<li class="date">Date</li>
<li class="open">OPEN</li>
<li class="high">HIGH</li>
<li class="low">LOW</li>
<li class="close">CLOSE</li>
<li class="volume">VOLUME</li>
</ul>`;
// sectio.append(detailedModal)
rowDetail.className = `detailed-row`;
rowDetail.className = "detail-list";
for (let i = 0; i < 4; i++) {
const date = dates[i];
const values = valueOfTimeSeries[date];
const openValue = values["1. open"];
const highValue = values["2. high"];
const lowValue = values["3. low"];
const closeValue = values["4. close"];
const volumeValue = values["5. volume"];
rowDetail.innerHTML += `<li class="date">${date}</li>
<li class="open">${openValue}</li>
<li class="high">${highValue}</li>
<li class="low">${lowValue}</li>
<li class="close">${closeValue}</li>
<li class="volume">${volumeValue}</li>`;
}
// rowDetail.innerHTML = `<li class="date">Sasta</li>
// <li class="open">MastRam</li>
// <li class="high">SantRam</li>
// <li class="low">KantaRam</li>
// <li class="close">MajataRam</li>
// <li class="volume">ties</li>`;
detailedModal.appendChild(rowDetail);
main.append(detailedModal)
buttoncross.addEventListener("click", () => {
main.removeChild(detailedModal)
})
}
if (click % 2 != 0) {
article.addEventListener("click", () => {
click++
// detailedModal.removeChild(rowDetail)
main.removeChild(detailedModal)
})
}
})
if (click % 2 != 0) {
buttoncross.addEventListener("click", (event) => {
// event.stopPropagation()
// main.removeChild(article)
})
} else {
buttoncross.addEventListener("click", (event) => {
event.stopPropagation()
main.removeChild(article)
})
}
// main.append(article)
// main.append(sectio)
// article.addEventListener("click", (e)=>{
// e.preventDefault();
// console.log("hi");
// const li = document.createElement('li');
// li.innerText="Reward";
// const buttondrop = document.createElement('button');
// const div3 = document.createElement("div");
// div3.classList.add("dropDown");
// div3.append(li);
// div3.append(buttondrop)
// main.append(div3)
// buttondrop.addEventListener("click", (e)=>{
// main.removeChild(div3);
// })
// })
}