-
Notifications
You must be signed in to change notification settings - Fork 0
/
btc.html
692 lines (629 loc) · 32.1 KB
/
btc.html
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title id="dynTitle">FFS BTC System 8.1</title>
<script>
//const geckoapiURL = "https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin";
const binanceapiURL = "https://api.binance.com/api/v3/ticker?symbol=BTCUSDT&windowSize=";
const binanceWSS = "wss://stream.binance.com:9443/ws/btcusdt@trade";
//const fontPriceMulti = 15;
function getLocStorage() {
console.log("From localStorage: Q_len:" + localStorage.getItem("Q_len1") + "; " +
"Dev_limit:" + localStorage.getItem("Dev_limit1") + "; " +
"Qty_alert:" + localStorage.getItem("Qty_alert1") + "; " +
"Reset_sec:" + localStorage.getItem("Reset_sec1") + ";" +
"Data_size:" + localStorage.getItem("Data_size1") + ".");
Q_len.value = (localStorage.getItem("Q_len1")) ? localStorage.getItem("Q_len1") : 240;
Dev_limit.value = (localStorage.getItem("Dev_limit1")) ? localStorage.getItem("Dev_limit1") : 6;
Qty_alert.value = (localStorage.getItem("Qty_alert1")) ? localStorage.getItem("Qty_alert1") : "50/25";
Reset_sec.value = (localStorage.getItem("Reset_sec1")) ? localStorage.getItem("Reset_sec1") : 180;
DataWin_size.value = (localStorage.getItem("Data_size1")) ? localStorage.getItem("Data_size1") : 7;
}
function openTab(evt, tabName) {
let i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
evt.currentTarget.className += " active";
}
</script>
<style>
body {
background-color: black;
color: white;
}
input[type=text] {
background-color: black;
color: white;
}
.tab {
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
float: left;
outline: none;
cursor: pointer;
padding: 0px 0px;
transition: 0.3s;
font-size: 0.7em;
}
.tab button:hover {
background-color: #ddd;
}
.tab button.active {
background-color: #ccc;
color: rgb(255, 255, 255);
}
.tabcontent {
display: none;
padding: 0px 0px;
border: 1px solid #ccc;
}
.logcontent {
height: 15%;
font-size: 0.8em;
overflow-y: scroll;
}
.caption1 {
font-size: 0.6em;
}
.data1 {
font-size: 0.8em;
}
.button1 {
font-size: 0.7em;
}
.alertText {
background-color: yellow;
color: black;
}
.container {
display: flex;
}
.left-wrapper {
text-align: left;
flex: 50%;
background-color: black;
border: 0px;
}
.right-wrapper {
text-align: right;
flex: 50%;
}
a {
color: white;
font-size: 0.7em;
}
</style>
</head>
<body onload="getLocStorage()">
<div id="provision" style="display:inline-table">
<table style="display:inline-table">
<tr class="caption1">
<td>Sample size:</td>
<td><input id="ssize" type="text" style="width: 35px;" onchange="adjustWidth(this);"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();" /></td>
<td>StdDev alert:</td>
<td><input id="stddev_limit" type="text" style="width: 25px;" onchange="adjustWidth(this);"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();" />
</td>
<td>Vol/Qty alert:</td>
<td><input id="qty_limit" type="text" style="width: 55px;" onchange="adjustWidth(this);"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();" />
</td>
<td><span id="hiddenReset">Reset</span> in (s):</td>
<td><input id="resetAlertSec" type="text" style="width: 35px;" /></td>
</tr>
</table>
</div>
<div style="display:inline-table">
<table style="display:inline-table">
<tr>
<td class="caption1">
<div id="symbol"></div>
</td>
<td class="data1">
<span id="timestamp"></span>
</td>
<td>
<div class="button1">
<input type="checkbox" id="cbSound" style="width:12px; height:12px;" />Sound
<input id="dataWinSize" type="text" style="width: 25px;" onchange="adjustWidth(this);"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();" />
</div>
</td>
<td>
<button id="btnGetHL" onclick="getHighLow();" class="button1">day limits</button>
</td>
<td>
<button id="btnStart" onclick="ws_trades();wrapTradingView(); setLocStorage(); autoResizeTextbox();"
class="button1">Start</button>
</td>
</tr>
</table>
</div>
<div style="display:inline-table">
<table style="display:inline-table;">
<tr>
<td class="caption1">U.Limit</td>
<td><input id="upperPrice" type="text" value="" style="width: 65px;" onchange="adjustWidth(this);"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();" />
</td>
<td class="caption1">L.Limit</td>
<td><input id="lowerPrice" type="text" value="" style="width: 55px;" onchange="adjustWidth(this);"
onkeypress="this.onchange();" onpaste="this.onchange();" oninput="this.onchange();" />
</td>
<td class="caption1">
<div id="pQueue" style="display:inline-table"></div>StdDev:
</td>
<td class="data1" style="width:30px">
<div id="stddev"></div>
</td>
<td class="caption1">Mean:</td>
<td class="data1" style="width:70px">
<div id="mean"></div>
</td>
</tr>
</table>
</div>
<div style="display:inline-table">
<table style="display:inline-table;">
<tr>
<td>
<div id="price" style="display:inline-table; width: 140px; color:yellow;">
</div>
</td>
<td class="caption1">
<div id="vQueue" style="display:inline-table"></div>Vol:
</td>
<td style="width:20px">
<span id="sampleQty" class="data1"></span>
</td>
<td class="caption1">QTY:</td>
<td style="width:40px">
<span id="qty" class="data1"></span>
</td>
<td><button id="btnShowHideSet" onclick="SHSettings();" class="button1">H Conf</button>
</td>
<td><button id="btn_showhidechart" onclick="showhideChart();" class="button1">H Chart</button></td>
</tr>
</table>
</div>
<table style="width:100%">
<tr>
<td>
<div id="PriceAlert" class="alertText"></div>
</td>
<td>
<div id="warnCount" class="alertText"></div>
</td>
<td>
<div id="volumeAlert" class="alertText"></div>
</td>
<td>
<div id="volumeCount" class="alertText"></div>
</td>
<td>
<div id="whaleAlert" class="alertText"></div>
</td>
<td>
<div id="whaleCount" class="alertText"></div>
</td>
</tr>
</table>
<div id="chart" style="height:65%; overflow:auto; resize:both;">
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
<div id="tradingview_0579e"></div>
<div style="font-size:x-small;"><a href="https://www.tradingview.com/symbols/BTCUSD/?exchange=BINANCE"
rel="noopener" target="_blank"><span class="blue-text">BTCUSD Chart</span></a> by TradingView</div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
function wrapTradingView() {
let studies = [
{
id: "MASimple@tv-basicstudies",
inputs: {
length: 350
}
},
{
id: "MASimple@tv-basicstudies",
inputs: {
length: 125
}
},
{
id: "MASimple@tv-basicstudies",
inputs: {
length: 25
}
},
];
new TradingView.widget(
{
"autosize": true,
"symbol": "BINANCE:BTCUSD",
"interval": "1",
"timezone": "Asia/Hong_Kong",
"theme": "dark",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"range": "1D",
"enable_publishing": false,
"hide_top_toolbar": true,
"hide_legend": true,
"save_image": false,
"hidevolume": false,
"allow_symbol_change": false,
"studies": studies,
"details": true,
"container_id": "tradingview_0579e"
}
);
}
</script>
</div>
<!-- TradingView Widget END -->
</div>
<div id="DeviationLog" class="tabcontent" style="display:block;">
<div id="stdDevLog" class="logcontent">Index: Mean; StdDev; minPrice,maxPrice; Vol; DateTime</div>
</div>
<div id="VolumeLog" class="tabcontent">
<div id="volLog" class="logcontent">Index: Qty; Price; DateTime</div>
</div>
<div id="WhaleLog" class="tabcontent">
<div id="whaLog" class="logcontent">Index: Qty; Price; DateTime</div>
</div>
<div class="container">
<div class="tab left-wrapper">
<button class="tablinks active" onclick="openTab(event, 'DeviationLog')">Deviation</button>
<button class="tablinks" onclick="openTab(event, 'VolumeLog')">Volume</button>
<button class="tablinks" onclick="openTab(event, 'WhaleLog')">Whale</button>
</div>
<div class="right-wrapper"><a href="./bnb.html" target="_blank">BNB</a> <a href="./dot.html" target="_blank">DOT</a> <a href="./trx.html" target="_blank">TRX</a> <a href="./cake.html" target="_blank">CAKE</a></div>
</div>
<script>
function k(w, x, y) {
let a = new AudioContext();
v = a.createOscillator();
u = a.createGain();
v.connect(u);
v.frequency.value = x;
v.type = "sine";
u.connect(a.destination);
u.gain.value = w * 0.01;
v.start(a.currentTime);
v.stop(a.currentTime + y * 0.001);
a.close();
}
const snd = new Audio("data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fhzA1jwHuTRxDUQ//iYBczjHiTJcIuPyKlHQkv/LHQUYkuSi57yQT//uggfZNajQ3Vmz+Zt//+mm3Wm3Q576v////+32///5/EOgAAADVghQAAAAA//uQZAUAB1WI0PZugAAAAAoQwAAAEk3nRd2qAAAAACiDgAAAAAAABCqEEQRLCgwpBGMlJkIz8jKhG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ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=");
function standardDeviation(arr) {
let mean = arr.reduce((acc, curr) => {
return acc + curr
}, 0) / arr.length;
arr = arr.map((el) => {
return (el - mean) ** 2
})
let total = arr.reduce((acc, curr) => acc + curr, 0);
return Math.sqrt(total / arr.length)
}
function meanF(arr) {
return arr.reduce((acc, curr) => {
return acc + curr
}, 0) / arr.length;
}
function toDate(date) {
if (date === void 0) return new Date(0);
if (isDate(date)) return date;
else return new Date(parseFloat(date.toString()));
}
function isDate(date) {
return (date instanceof Date);
}
function format(date, format) {
let d = toDate(date);
return format
.replace(/Y/gm, d.getFullYear().toString())
.replace(/m/gm, ('0' + (d.getMonth() + 1)).substr(-2))
.replace(/d/gm, ('0' + (d.getDate() + 0)).substr(-2))
.replace(/H/gm, ('0' + (d.getHours() + 0)).substr(-2))
.replace(/i/gm, ('0' + (d.getMinutes() + 0)).substr(-2))
.replace(/s/gm, ('0' + (d.getSeconds() + 0)).substr(-2))
.replace(/v/gm, ('0000' + (d.getMilliseconds() % 1000)).substr(-3));
}
let stddev_limit, q_len, vlimit, wlimit, resetAlertSec;
let priceQueue = [], volQueue = [];
let p_count_warn = 0, v_count_warn = 0, w_count_warn = 0, curStdDev = 0, curMean = 0, curVol = 0;
let p_lastWarnTime = Date.now(), v_lastWarnTime = Date.now(), w_lastWarnTime = Date.now();
let socket_live;
const Q_len = document.getElementById("ssize");
const Dev_limit = document.getElementById("stddev_limit");
const Qty_alert = document.getElementById("qty_limit");
const Reset_sec = document.getElementById("resetAlertSec");
const DataWin_size = document.getElementById("dataWinSize");
const Symbol = document.getElementById("symbol");
const Price = document.getElementById("price");
const Qty = document.getElementById("qty");
const TStamp = document.getElementById("timestamp");
const pQueueNum = document.getElementById("pQueue");
const StdDev = document.getElementById("stddev");
const Mean = document.getElementById("mean");
const SampleQty = document.getElementById("sampleQty");
const SampleQtyNum = document.getElementById("vQueue");
const P_Alert = document.getElementById("PriceAlert");
const P_count = document.getElementById("warnCount");
const V_Alert = document.getElementById("volumeAlert");
const V_count = document.getElementById("volumeCount");
const W_Alert = document.getElementById("whaleAlert");
const W_count = document.getElementById("whaleCount");
const UpperP = document.getElementById("upperPrice");
const LowerP = document.getElementById("lowerPrice");
const CandleChart = document.getElementById("chart");
const Provision = document.getElementById("provision");
const DynTitle = document.getElementById("dynTitle");
const tvWidget = document.getElementById("tradingview_0579e");
const FullDateTime = "Y-m-d H:i:s.v";
const ShortTime = "H:i:s.v";
const Btn_GetHL = document.getElementById("btnGetHL");
const Btn_Start = document.getElementById("btnStart");
const Btn_c = document.getElementById("btn_showhidechart");
const Btn_s = document.getElementById("btnShowHideSet");
const SdLog = document.getElementById("stdDevLog");
const VLog = document.getElementById("volLog");
const WLog = document.getElementById("whaLog");
const HiddenReset = document.getElementById("hiddenReset");
const CBSound = document.getElementById("cbSound");
HiddenReset.addEventListener('click', function (evt) {
if (evt.detail === 3) {
localStorage.clear();
alert('You found me! All local storage cleared!');
}
});
async function getAnyAPI(apiURL) {
let response = await fetch(apiURL);
return await response.json();
}
// For coingecko, replaced by binance now
// function get24HighLow() {
// getAnyAPI(geckoapiURL).then(
// data => {
// UpperP.value = data[0].high_24h;
// LowerP.value = data[0].low_24h;
// UpperP.style.width = ((UpperP.value.length + 1) * 8) + 'px';
// LowerP.style.width = ((LowerP.value.length + 1) * 8) + 'px';
// }
// );
// }
function getHighLow() {
var apiURL = binanceapiURL + DataWin_size.value + 'd';
getAnyAPI(apiURL).then(
data => {
UpperP.value = parseFloat(data["highPrice"]);
LowerP.value = parseFloat(data["lowPrice"]);
UpperP.style.width = ((UpperP.value.length + 1) * 8) + 'px';
LowerP.style.width = ((LowerP.value.length + 1) * 8) + 'px';
}
);
}
function setLocStorage() {
localStorage.setItem("Q_len1", Q_len.value);
localStorage.setItem("Dev_limit1", Dev_limit.value);
localStorage.setItem("Qty_alert1", Qty_alert.value);
localStorage.setItem("Reset_sec1", Reset_sec.value);
localStorage.setItem("Data_size1", DataWin_size.value);
}
function showhideChart() {
if (Btn_c.innerHTML == "S Chart") {
CandleChart.style.display = "inline-block";
CandleChart.style.width = parent.innerWidth - 10;
Btn_c.innerHTML = "H Chart";
wrapTradingView();
}
else {
CandleChart.style.display = "none";
Btn_c.innerHTML = "S Chart";
tvWidget.innerHTML = "";
}
}
function SHSettings() {
if (Btn_s.innerHTML == "S Conf") {
Provision.style.display = "inline-block";
DataWin_size.style.display = "inline-block";
Btn_GetHL.style.display = "inline-block";
Btn_Start.style.display = "inline-block";
pQueueNum.style.display = "inline-table";
SampleQtyNum.style.display = "inline-table";
Btn_s.innerHTML = "H Conf";
}
else {
Provision.style.display = "none";
DataWin_size.style.display = "none";
Btn_GetHL.style.display = "none";
Btn_Start.style.display = "none";
pQueueNum.style.display = "none";
SampleQtyNum.style.display = "none";
Btn_s.innerHTML = "S Conf";
}
}
function ws_trades() {
q_len = Q_len.value;
stddev_limit = Dev_limit.value;
vlimit = Qty_alert.value.split("/")[0];
wlimit = Qty_alert.value.split("/")[1];
resetAlertSec = Reset_sec.value;
socket_live = new WebSocket(binanceWSS);
socket_live.onopen = function (evt) {
//alert("SocketOpen");
}
socket_live.onmessage = function (event) {
//alert(JSON.stringify(event.data));
handle_trades(JSON.parse(event.data));
}
socket_live.onerror = function (evt) {
alert("SocketError");
}
}
function handle_trades(json_message) {
let formatted_dateTime = format(json_message['E'], FullDateTime);
let curPrice = Math.trunc(json_message['p'] * 100) / 100;
let curQty = Math.trunc(json_message['q'] * 1000) / 1000;
cal_stddev_mean(curPrice, curQty);
let curDiff = (curPrice - curMean) * 100;
Symbol.innerHTML = json_message['s'];
Price.innerHTML = curPrice + " : " + Math.trunc(curDiff) / 100;
// Price.style.fontSize = function () {
// if (curMean != 0)
// return (Math.trunc((1 + curDiff * fontPriceMulti / curMean) * 100) / 100).toString() + "em";
// else
// return "1em";
// }();
Qty.innerHTML = curQty;
TStamp.innerHTML = formatted_dateTime;
pQueueNum.innerHTML = priceQueue.length + 1;
StdDev.innerHTML = curStdDev;
Mean.innerHTML = curMean;
SampleQtyNum.innerHTML = volQueue.length + 1;
SampleQty.innerHTML = curVol;
StdDevAlert();
limitAlert(curPrice);
qtyAlert(curPrice, curQty);
volAlert(curPrice);
dynamicTitle(curPrice);
}
function cal_stddev_mean(curPrice, curQty) {
priceQueue.push(curPrice);
volQueue.push(curQty);
if (priceQueue.length >= q_len) {
curStdDev = Math.trunc(standardDeviation(priceQueue) * 100) / 100;
curMean = Math.trunc(meanF(priceQueue) * 100) / 100;
priceQueue.shift();
}
if (volQueue.length >= q_len) {
const reducer = (accumulator, curr) => accumulator + curr;
curVol = Math.trunc(volQueue.reduce(reducer));
volQueue.shift();
}
}
function volAlert(curPrice) {
let curTime = Date.now();
let formatted_dateTime = format(curTime, ShortTime);
let secDiff = (curTime - v_lastWarnTime) / 1000;
if (resetAlertSec != 0) {
if (secDiff > resetAlertSec && v_count_warn != 0) {
console.log(VLog.innerHTML.trim());
console.log("Vol last reset: " + formatted_dateTime + "; V. Alert: " + v_count_warn);
VLog.innerHTML = "Index: Vol; Price; DateTime<br />Last reset: " + formatted_dateTime + "; V. Alert: " + v_count_warn;
V_Alert.innerHTML = "";
V_count.innerHTML = "";
v_count_warn = 0;
}
}
if (curVol >= vlimit) {
if (CBSound.checked)
k(200, 33, 100);
v_lastWarnTime = curTime;
VLog.innerHTML = "<i>" + ++v_count_warn + ": " + curVol + "; " + curPrice + "; " + formatted_dateTime + "</i><br />" + VLog.innerHTML;
V_Alert.innerHTML = "V. Alert: ";
V_count.innerHTML = v_count_warn;
volQueue.length = 0;
curVol = 0;
}
}
function qtyAlert(curPrice, curQty) {
let curTime = Date.now();
let formatted_dateTime = format(curTime, ShortTime);
let secDiff = (curTime - w_lastWarnTime) / 1000;
if (resetAlertSec != 0) {
if (secDiff > resetAlertSec && w_count_warn != 0) {
console.log(WLog.innerHTML.trim());
console.log("Whale last reset: " + formatted_dateTime + "; W. Alert: " + w_count_warn);
WLog.innerHTML = "Index: Qty; Price; DateTime<br />Last reset: " + formatted_dateTime + "; W. Alert: " + w_count_warn;
W_Alert.innerHTML = "";
W_count.innerHTML = "";
w_count_warn = 0;
}
}
if (curQty >= wlimit) {
if (CBSound.checked)
k(200, 55, 200);
w_lastWarnTime = curTime;
WLog.innerHTML = "<b>" + ++w_count_warn + ": " + curQty + "; " + curPrice + "; " + formatted_dateTime + "</b><br />" + WLog.innerHTML;
W_Alert.innerHTML = "Whale: ";
W_count.innerHTML = w_count_warn;
}
}
function limitAlert(cPrice) {
if (UpperP.value != "") {
if (cPrice >= UpperP.value) {
UpperP.style.backgroundColor = "rgb(115, 255, 0)";
if (CBSound.checked)
k(200, 311, 100);
}
else UpperP.style.backgroundColor = "initial";
}
if (LowerP.value != "") {
if (cPrice <= LowerP.value) {
LowerP.style.backgroundColor = "rgb(250, 150, 150)";
if (CBSound.checked)
k(200, 188, 100);
}
else LowerP.style.backgroundColor = "initial";
}
}
function StdDevAlert() {
let curTime = Date.now();
let formatted_dateTime = format(curTime, ShortTime);
let secDiff = (curTime - p_lastWarnTime) / 1000;
if (resetAlertSec != 0) {
if (secDiff > resetAlertSec && p_count_warn != 0) {
console.log(SdLog.innerHTML.trim());
console.log("Dev last reset: " + formatted_dateTime + "; P. Alert: " + p_count_warn);
SdLog.innerHTML = "Index: Mean; StdDev; minPrice,maxPrice; Vol; DateTime<br />Last reset: " + formatted_dateTime + "; Dev Alert: " + p_count_warn;
P_Alert.innerHTML = "";
P_count.innerHTML = "";
p_count_warn = 0;
}
}
if (curStdDev >= stddev_limit) {
if (CBSound.checked)
snd.play();
p_lastWarnTime = curTime;
P_Alert.innerHTML = "P. Alert: ";
P_count.innerHTML = ++p_count_warn;
SdLog.innerHTML = p_count_warn + ": " + curMean + "; " + curStdDev + "; " + Math.min.apply(null, priceQueue) + "," + Math.max.apply(null, priceQueue) + "; " + curVol + "; " + formatted_dateTime + "<br />" + SdLog.innerHTML;
priceQueue.length = 0;
curMean = 0; curStdDev = 0;
}
}
function dynamicTitle(curPrice) {
DynTitle.innerHTML = "";
if (p_count_warn > 0)
DynTitle.innerHTML += "P" + p_count_warn + " | ";
if (v_count_warn > 0)
DynTitle.innerHTML += "V" + v_count_warn + " | ";
if (w_count_warn > 0)
DynTitle.innerHTML += "W" + w_count_warn + " | ";
DynTitle.innerHTML += curPrice;
}
function autoResizeTextbox() {
let txtBox = document.getElementsByTagName("input");
for (i = 0; i < txtBox.length; i++)
if (txtBox[i].type == "text")
adjustWidth(txtBox[i]);
}
function adjustWidth(obj) {
obj.style.width = ((obj.value.length + 1) * 8) + 'px';
}
</script>
</body>
</html>