-
Notifications
You must be signed in to change notification settings - Fork 0
/
myownbot.html
executable file
·1376 lines (1179 loc) · 54.8 KB
/
myownbot.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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{% extends 'index.html' %}
{% block title %}
<h2>My Own Bot</h2>
{% endblock %}
{% block content %}
{% if user.is_authenticated %}
<body>
<div id="app" class="test">
<principalcomponent></principalcomponent>
</div>
</body>
</div>
<script type="module">
var coinpairs = []; // Used in the 1st and 5th pop-up
function readCsv() { // Reads the csv file and update the coinpairs list
var str = ""
fetch("../coinpairs.csv")
.then(response => response.text())
.then(data => {
const lines = data.split("\n");
for (let i = 1; i < lines.length-1; i++) {
coinpairs[i-1] = lines[i].split(",")[1];
}
console.log(coinpairs);
} ) } ;
window.onload = readCsv; // When the windows loads ==> we should load the csv
/* ---------------------------------- */
/* --- Symbol Selection Component --- */
/* ---------------------------------- */
// Used anytime the user needs to select a symbol in the indicator part of the 2nd popup
var symbolcomponent = Vue.component('symbolcomponent',{
name:'symbolcomponent',
delimiters:['[[',']]'],
props:['title'],
template:
`
<div class="optionSwitch1" >
<select v-bind:id="'valueSymbol'+title" style="width:110px;margin-top: 25px; margin-bottom: 15px;">
<option value=">" selected>></option>
<option value=">=">>=</option>
<option value="<"><</option>
<option value="<="><=</option>
<option value="!=">=</option>
<option value="!=">!=</option>
</select>
<div class="selectionPopup" style="margin-top: 5px; width: 280px;">
<numberinputcomponent v-bind:title="this.title" val="10" min="1" max="10000000"></numberinputcomponent>
</div>
</div>
`
})
/* ------------------------------ */
/* --- Number Input Component --- */
/* ------------------------------ */
// It corresponds to the following type of number input : " - [ ] + "
var numberinputcomponent = Vue.component('numberinputcomponent',{
name:'numberinputcomponent',
delimiters:['[[',']]'],
props: ['title', 'min', 'max','val'],
template:
`
<div style="padding: 8px 16px;">
<div> [[title]] </div>
<div class="vs-input-number vs-input-number-size-null vs-input-number-primary" style="background-color:white; height:20px;width:100px;">
<button type="button" class="btn-less vs-input-number--button-less" v-on:click="decreaseValue();">
<i class="vs-icon notranslate icon-scale material-icons null">-</i></button>
<input min="this.min" max="this.max" step="1" v-bind:id="'valueInput'+title" v-bind:value="this.valInput" class="valueInput">
<button type="button" class="btn-plus vs-input-number--button-plus" v-on:click="increaseValue();">
<i class="vs-icon notranslate icon-scale material-icons null">+</i></button>
</div>
</div>
`,
methods:{
increaseValue(){ // when the user clicks on "+"
var el = document.getElementById("valueInput"+this.title).value;
this.valInput = el;
this.valInput++;
if(this.valInput>this.max){
alert("The value must be between " + this.min + " and " + this.max);
this.valInput = this.max;
}
},
decreaseValue(){ // when the user clicks on "-"
var el = document.getElementById("valueInput"+this.title).value;
this.valInput = el;
this.valInput--;
if(this.valInput<this.min){
alert("The value must be between " + this.min + " and " + this.max);
this.valInput = this.min;
}
}
},
data(){
return{
valInput:this.val // the value of the input
}
}
})
/* ----------------------- */
/* --- Popup Component --- */
/* ----------------------- */
var popupcomponent = Vue.component('popupcomponent',{
name:'popupcomponent',
delimiters:['[[',']]'],
props: ['title', 'popupType','selectionList'],
component: {'numberinputcomponent': numberinputcomponent},
template:
`
<div class="centerx">
<!-- IF THE USER NEEDS TO ENTER AN INPUT -->
<div v-if="popupType === 'input'">
<vs-popup class="holamundo" v-bind:title="title" :active.sync="isActive">
<center>
<div class="selectionPopup">
<div style="font-size: 17px;"> Amount Type </div>
<!-- div class="v-application" -->
<v-btn-toggle tile color="blue darken-4" group>
<v-btn v-model="switchVolume" v-on:click="volume()"> 📈 Volume </v-btn>
<v-btn v-model="switchPrice" v-on:click="price()"> 💵 Price </v-btn>
</v-btn-toggle>
<!-- /div -->
</div>
<div>
<div v-if="switchVolume" style="font-size: 17px; width: 280px;">
<div>
<vs-input label-placeholder="Enter a percentage" v-model="inputValue"/>
</div>
</div>
<div v-if="switchPrice" style="font-size: 17px; width: 280px;">
<div>
<vs-input label-placeholder="Enter a value" v-model="inputValue"/>
</div>
</div>
</div>
<div style="padding:2% 0">
<vs-button v-on:click="confirmInput()" color="primary" type="border">Confirm
</vs-button>
</div>
</center>
</vs-popup>
</div>
<!-- OPTION POPUP -->
<div v-if="popupType === 'option'">
<vs-popup class="holamundo" v-bind:title="title" :active.sync="isActive">
<center>
<div>
<div class="selectionPopup">
<div style="font-size: 17px;"> Action type </div>
<v-btn-toggle v-model="textOption" tile color="deep-purple accent-3" group>
<v-btn v-on:click="setTypeActionOption('buy')"> Buy </v-btn>
<v-btn v-on:click="setTypeActionOption('sell')"> Sell </v-btn>
</v-btn-toggle>
</div>
<div class="selectionPopup">
<div style="font-size: 17px;"> Amount Type </div>
<!-- div class="v-application" -->
<v-btn-toggle tile color="blue darken-4" group>
<v-btn v-model="switchVolumeOption" v-on:click="volumeOption()"> 📈 Volume </v-btn>
<v-btn v-model="switchPriceOption" v-on:click="priceOption()"> 💵 Price </v-btn>
</v-btn-toggle>
<!-- /div -->
</div>
<div>
<div v-if="switchVolumeOption" style="font-size: 17px; width: 280px;">
<div>
<vs-input label-placeholder="Enter a percentage" v-model="inputValueOption"/>
</div>
</div>
<div v-if="switchPriceOption" style="font-size: 17px; width: 280px;">
<div>
<vs-input label-placeholder="Enter a value" v-model="inputValueOption"/>
</div>
</div>
</div>
<div class="choiceOption" style=" height: auto;">
<center>
<numberinputcomponent title="Profit" val="0" min="0" max="100000000"></numberinputcomponent>
<numberinputcomponent title="Stop Loss" val="0" min="0" max="100000000"></numberinputcomponent>
</center>
</div>
<div style="padding:2% 0">
<vs-button v-on:click="confirmOption()" color="primary" type="border">Confirm</vs-button>
</div>
<div style="padding:2% 0">
<vs-button v-on:click="clearOption()" color="danger" type="border">Clear</vs-button>
</div>
</div>
</center>
</vs-popup>
</div>
<!-- IF THE USER NEEDS TO CHOOSE IN A LIST -->
<div v-if="popupType === 'selection'">
<vs-popup class="holamundo" v-bind:title="title" :active.sync="isActive">
<center>
<div>
<vs-input label-placeholder="Select or type a coinpair" id="search" name="search" v-model="inputValueCurr" v-on:keyup="filter()" />
<div style="height : 10px"></div>
<ul v-bind:id="'selectionMenu'+title">
<li v-for="item in selectionList" v-bind:value="item"><a href="#" v-on:click="updateFilter(item)">[[item]]</a></li>
</ul>
</div>
<div style="padding:2% 0">
<vs-button v-on:click="confirmMenu()" color="primary" type="border">Confirm</vs-button>
</div>
</center>
</vs-popup>
</div>
<!-- CRITERION POPUP -->
<div v-if="popupType === 'criterion'">
<vs-popup class="holamundo" v-bind:title="title" :active.sync="isActive">
<center>
<div class="popupCriterion">
<div class="timeUnit">
<div style="font-size: 17px;"> ⏱ Time Unit </div>
<div>
<select id='selectionMenuTime'>
<option value="1m">1m</option>
<option value="5m">5m</option>
<option value="15m">15m</option>
<option value="30m">30m</option>
<option value="1h" selected>1h</option>
<option value="2h">2h</option>
<option value="4h">4h</option>
<option value="6h">6h</option>
<option value="12h">12h</option>
<option value="1d">1d</option>
</select>
</div>
</div>
<div class="choiceCriterion">
<v-btn-toggle tile color="deep-purple accent-3" group>
<v-btn v-model="switch1" v-on:click="indicator()"> 📈 Indicator </v-btn>
<v-btn v-model="switch2" v-on:click="symbols()"> 📐 Symbol </v-btn>
</v-btn-toggle>
</div>
</div>
<div v-if="switch1" style="font-size: 17px; width: 280px;">
<center>
<div>
<div class="optionSwitch1" style="margin-top: 15px;">
<select id='selectionIndicator'>
<option disabled selected>Select an Indicator </option>
<option value="MA" v-on:click="isMA()">MA</option>
<option value="MACD" v-on:click="isMACD()">MACD</option>
<option value="RSI" v-on:click="isRSI()">RSI</option>
<option value="Stochastic RSI" v-on:click="isSTOCRSI()">Stochastic RSI</option>
<option value="Bollinger Bands" v-on:click="isBOLLINGER()">Bollinger Bands</option>
</select>
</div>
<!-- MA -->
<div v-if="ma" style="margin-top:10px;">
<div class="choicePeriodMARsi">
<div>
<numberinputcomponent title="Period" val="9" min="1" max="200"></numberinputcomponent>
<symbolcomponent title="MA Value"></symbolcomponent>
<div style="padding:3% 0; width: 305px;">
<vs-button v-on:click="confirmMA()" color="primary" type="border">Confirm</vs-button>
</div>
</div>
</div>
</div>
<!-- RSI -->
<div v-if="rsi" style="margin-top:10px;">
<div class="choicePeriodMARsi">
<div>
<numberinputcomponent title="Period" val="9" min="1" max="200"></numberinputcomponent>
<symbolcomponent title="RSI Value"></symbolcomponent>
<div style="padding:3% 0; width: 305px;">
<vs-button v-on:click="confirmRsi()" color="primary" type="border">Confirm</vs-button>
</div>
</div>
</div>
</div>
<!-- MACD -->
<div v-if="macd" class="MACD">
<div class="selectionPopup" style="width:305px;">
<div style="font-size: 17px;"> Line </div>
<v-btn-toggle tile color="deep-purple accent-3" group>
<v-btn v-model="switchMacdLine1" v-on:click="macdLine()"> Line </v-btn>
<v-btn v-model="switchMacdLine2" v-on:click="macdSignalLine()"> Signal </v-btn>
<v-btn v-model="switchMacdLine3" v-on:click="macdHistogram()"> Histogram </v-btn>
</v-btn-toggle>
</div>
<div class="selectionPopup" style="height:auto; width:305px;">
<center>
<numberinputcomponent title="Short Term Period" val="12" min="1" max="200"></numberinputcomponent>
<numberinputcomponent title="Long Term Period" val="26" min="1" max="200"></numberinputcomponent>
<numberinputcomponent title="Signal Term Period" val="9" min="1" max="200"></numberinputcomponent>
</center>
</div>
<symbolcomponent title="MACD Value"></symbolcomponent>
<div style="padding:3% 0; width: 305px;">
<vs-button v-on:click="confirmMACD()" color="primary" type="border">Confirm</vs-button>
</div>
</div>
<!-- STOCHASTIC RSI -->
<div v-if="stocRsi" class="stocRsi">
<div class="selectionPopup" style="width: 305px;">
<div style="font-size: 17px;"> Line </div>
<v-btn-toggle tile color="deep-purple accent-3" group>
<v-btn v-model="switchStocRsiLine1" v-on:click="DLine()"> D </v-btn>
<v-btn v-model="switchStocRsiLine2" v-on:click="KLine()"> K </v-btn>
</v-btn-toggle>
</div>
<div class="choiceStocRsi">
<center>
<numberinputcomponent title="Length RSI" val="14" min="1" max="200"></numberinputcomponent>
<numberinputcomponent title="Length Stoch" val="14" min="1" max="200"></numberinputcomponent>
<numberinputcomponent title="Smooth K" val="3" min="1" max="200"></numberinputcomponent>
<numberinputcomponent title="Smooth D" val="3" min="1" max="200"></numberinputcomponent>
</center>
</div>
<symbolcomponent title="Stochastic RSI Value"></symbolcomponent>
<center>
<div style="padding:3% 0; width: 305px;">
<vs-button v-on:click="confirmStocRsi()" color="primary" type="border">Confirm</vs-button>
</div>
</center>
</div>
</div>
</center>
</div>
<div v-if="switch2" style="font-size: 17px; width: 300px;">
<div>
<div class="optionSwitch2" style="margin-top: 15px;">
<select id='selectionSymbol'>
<option disabled selected>Select a Symbol </option>
<option v-for="item in symbolList" v-on:click="isSymbol()" v-bind:value="item">[[item]]</option>
</select>
</div>
</div>
<div v-if="this.symbol">
<div class="choicePeriodMARsi" style="margin-top: 15px; width:auto;">
<center>
<numberinputcomponent title="Value" val="10" min="1" max="10000000"></numberinputcomponent>
</center>
</div>
<div style="padding:3% 0; width: 305px;">
<vs-button v-on:click="confirmSymbol()" color="primary" type="border">Confirm</vs-button>
</div>
</div>
</div>
<!-- BOLLINGER -->
<div v-if="bollinger">
<div class="selectionPopup" style="width: 370px;">
<div style="font-size: 17px;"> Line </div>
<v-btn-toggle tile color="deep-purple accent-3" group>
<v-btn v-model="switchBollingerLine1" v-on:click="upperBandLine()"> Upper Band </v-btn>
<v-btn v-model="switchBollingerLine2" v-on:click="middleBandLine()"> Middle Band </v-btn>
<v-btn v-model="switchBollingerLine3" v-on:click="lowerBandLine()"> Lower Band </v-btn>
</v-btn-toggle>
</div>
<div class="choicePeriodBollinger">
<center>
<numberinputcomponent title="Standard Deviation" val="2" min="0" max="80"></numberinputcomponent>
<numberinputcomponent title="Period" val="20" min="1" max="80"></numberinputcomponent>
</center>
</div>
<symbolcomponent title="Bollinger Value"></symbolcomponent>
<center>
<div style="padding:3% 0; width: 305px;">
<vs-button v-on:click="confirmBollinger()" color="primary" type="border">Confirm</vs-button>
</div>
</center>
</div>
</center>
</vs-popup>
</div>
<!-- ACTION POPUP -->
<div v-if="popupType === 'action'">
<vs-popup class="holamundo" v-bind:title="title" :active.sync="isActive">
<center>
<div>
<div class="selectionPopup">
<div style="font-size: 17px;"> Action type </div>
<v-btn-toggle v-model="text0" tile color="deep-purple accent-3" group>
<v-btn v-on:click="setTypeAction('buy')"> Buy </v-btn>
<v-btn v-on:click="setTypeAction('sell')"> Sell </v-btn>
</v-btn-toggle>
</div>
<!-- div v-if="switch1" style="font-size: 17px; width: 280px;" -->
<!-- ORDER TYPE -->
<div class="selectionPopup">
<div style="font-size: 17px;"> Order type </div>
<v-btn-toggle v-model="text1" tile color="deep-purple accent-3" group>
<v-btn v-on:click="setTypeOperation('market')" class="myButton"> Market </v-btn>
<v-btn v-on:click="setTypeOperation('limit')" class="myButton"> Limit </v-btn>
</v-btn-toggle>
</div>
<div class="selectionPopup">
<div style="font-size: 17px;"> Trade </div>
<v-btn-toggle v-model="text2" tile color="deep-purple accent-3" group>
<v-btn v-on:click="setTrade('first')"> First </v-btn>
<v-btn v-on:click="setTrade('last')"> Last </v-btn>
<v-btn v-on:click="setTrade('open')"> Open </v-btn>
<v-btn v-on:click="setTrade('all')" > All </v-btn>
</v-btn-toggle>
</div>
<div style="padding:2% 0">
<vs-button v-on:click="confirmAction()" color="primary" type="border">Confirm</vs-button>
</div>
</div>
</center>
</vs-popup>
</div>
<!-- IF WE NEED TO RETRIEVE DATA -->
<div v-if="popupType === 'retrieval'">
<vs-popup class="holamundo" v-bind:title="title" :active.sync="isActive">
<div style="padding:2% 0">
<vs-button v-on:click="showJson()" color="primary" type="border">Retrieve my data!</vs-button>
</div>
<p>
[[this.jsonDataList]]
</p>
</vs-popup>
</div>
</div>
`,
methods: {
isPositiveValue(str) { // checks if a string corresponds to a positive number (float or integer)
if (typeof str !== 'string') {
return false;
}
str = (str).replace(",", "");
str = (str).replace(".", "");
const num = Number(str);
if (Number.isInteger(num) && num > 0) {
return true;
}
return false;
},
/* CONFIRM METHODS */
confirm () { //confirm method when the type of the popup is 'input'
var el = document.getElementById(this.name+'content');
el.innerHTML = this.value; // update the value of the square
this.isActive = false; //closes the popup
},
confirmInput () { //confirm method when the type of the popup is 'input'
if (this.switchVolume && this.inputValue == "") {
alert("Please enter an amount.")
} else if (this.switchPrice && this.inputValue == "") {
alert("Please enter an amount.");
}
else {
var el = document.getElementById(this.name+'content');
var val;
if ((this.inputValue).includes(",")) {
this.inputValue = (this.inputValue).replace(",", ".")
val = parseFloat(this.inputValue);
} else {
val = parseFloat(this.inputValue);
}
if (this.switchVolume && ((val<0) || (val>100))) {
alert("Please enter a percentage whose value is between 0 and 100.")}
else if (this.switchPrice && (val < 0)) {
alert("Please enter a positive value.")
}
if(!this.isPositiveValue(this.inputValue)){
alert("Please enter a positive value.");
}
else {
var jsonString = '"amountType":';
this.nb = val;
el.innerHTML = this.inputValue; // update the value of the square
if (this.switchVolume) {el.innerHTML+= " %"; jsonString = jsonString + '"percent"';}
else { jsonString = jsonString + '"price"'; }
jsonString = jsonString + ',"amount":"' + val + '"';
this.$emit("updateMessage", jsonString);
this.isActive = false; //closes the popup
}
}
},
confirmAction () { //confirm method when the type of the popup is 'selection'
if (this.typeAction == "") {
alert("Please select a type of action.");
}
else if (this.typeOperation == "") {
alert("Please select a type of order.");
}
else if (this.typeTrade == "") {
alert("Please select a type of trade.");
}
else {
var el = document.getElementById(this.name+'content');
var val = this.typeAction
el.innerHTML = val.toUpperCase(); // update the value of the square
var jsonString = "";
if(this.text0==0){ jsonString = jsonString + '"actionType":"buy","orderType":'}
else if(this.text0==1) { jsonString = jsonString + '"actionType":"sell","orderType":' }
if(this.text1==0){ jsonString = jsonString + '"market","trade":' }
else if(this.text1==1){ jsonString = jsonString + '"limit","trade":' }
if(this.text2==0){ jsonString = jsonString + '"first"' }
else if (this.text2==1){ jsonString = jsonString + '"last"' }
else if (this.text2==2){ jsonString = jsonString + '"open"' }
else if (this.text2==3){ jsonString = jsonString + '"all"' }
this.$emit("updateMessage", jsonString);
this.isActive = false; // closes the popup
}
},
confirmOption () { //confirm method when the type of the popup is 'selection'
if (this.typeActionOption == "") {
alert("Please select a type of action.");
}
if (!this.switchPriceOption && !this.switchVolumeOption) {
alert("Please select a type of amount.");
}
if ((this.switchVolumeOption && this.inputValueOption == "") || (this.switchPriceOption && this.inputValueOption == "") ) {
alert("Please enter an amount.")
} else {
var val;
if ((this.inputValueOption).includes(",")) {
this.inputValueOption = (this.inputValueOption).replace(",", ".")
val = parseFloat(this.inputValueOption);
} else {
val = parseFloat(this.inputValueOption);
}
if (this.switchVolumeOption && ((val<0) || (val>100))) {
alert("Please enter a percentage whose value is between 0 and 100.")}
else if (this.switchPrice && (val < 0)) {
alert("Please enter a positive value.")
}
console.log(this.inputValueOption);
if(!this.isPositiveValue(this.inputValueOption)){
alert("Please enter a positive value.");
}
else {
var el = document.getElementById(this.name+'content');
var jsonString = "";
var square = document.getElementById(this.name+'content');
square.style = "line-height: 35px;";
if(this.textOption==0){
jsonString = jsonString + '"actionTypeOption":"buy","amountTypeOption":';
square.innerHTML = "Action : BUY<br />"; }
else if(this.textOption==1) {
jsonString = jsonString + '"actionTypeOption":"sell","amountTypeOption":';
square.innerHTML = "Action : SELL<br />";
}
if (this.switchVolumeOption) {
jsonString = jsonString + '"percent"';
square.innerHTML = square.innerHTML + "Value : " + val + "%<br />" ;
}
else {
jsonString = jsonString + '"price"';
square.innerHTML = square.innerHTML + "Value : " + val + "<br />";
}
jsonString = jsonString + ',"amountOption":"' + "Value : " + val + '", "profit":"';
var el1 = document.getElementById("valueInputProfit").value;
var el2 = document.getElementById("valueInputStop Loss").value;
square.innerHTML = square.innerHTML + "Profit : " + el1 + "<br />Stop Loss : " + el2 ;
jsonString = jsonString + el1 + '", "stopLoss":"' + el2 +'"';
this.$emit("updateMessage", jsonString);
this.isActive = false; // closes the popup
}
}
},
confirmMenu() { //confirm method when the type of the popup is 'selection'
var val = document.getElementById("search");
if(coinpairs.includes(this.inputValueCurr.toUpperCase())){
var el = document.getElementById(this.name+'content');
el.innerHTML = this.inputValueCurr.toUpperCase(); // update the value of the square
//update of the json string
if(this.name.charAt(9)=="1"){ //If it is the 1st block
var jsonString = '"pair":"'+ this.inputValueCurr + '"'
}
else{ // If it is the 5th block
var jsonString = '"currency":"'+ this.inputValueCurr + '"'
}
this.$emit("updateMessage", jsonString);
this.isActive = false; // closes the popup
}
else{
alert("Please select a valid currency.");
}
},
confirmSymbol(){ // checks if the inputs of the symbol part of the criterion popup are corrects
var val = document.getElementById("valueInputValue").value;
var time = document.getElementById('selectionMenuTime').value;
if(!this.isPositiveValue(val)){ alert("The period should be a positive integer"); }
else{
var symb = document.getElementById('selectionSymbol').value;
var square = document.getElementById(this.name+'content');
square.innerHTML = symb + " " + val;
//update of the json string
var jsonString = '"TimeUnit":"'+time+'","comparaison":"mathematics","comparaisonSymbol":"'+symb+'","comparaisonValue":"'+ val + '"'
this.$emit("updateMessage", jsonString);
this.isActive = false; // closes the popup
}
},
confirmMA(){ // checks if the inputs for the MA are corrects
var val = document.getElementById("valueInputPeriod").value;
var time = document.getElementById('selectionMenuTime').value;
if(!this.isPositiveValue(val)){ alert("The period should be a positive integer"); }
else{
if((val=>1) && (val<=200)){
var square = document.getElementById(this.name+'content');
var symb = document.getElementById('valueSymbolMA Value').value;
var val2 = document.getElementById("valueInputMA Value").value;
if(!this.isPositiveValue(val2)){ alert("The MA Value should be a positive integer"); }
else{
square.innerHTML = "MA";
var jsonString = '"TimeUnit":"'+time+'","comparaison":"indicator","indicator":"MA","periodValue":"'+ val;
jsonString = jsonString + '","symbol":"' + symb + '","symbolValue":"' + val2 + '"';
this.$emit("updateMessage", jsonString);
this.isActive=false;
}
}
else{ alert("This period value must be between 1 and 200"); }
}
},
confirmRsi(){ // checks if the inputs for the RSI are corrects
var val = document.getElementById("valueInputPeriod").value;
var time = document.getElementById('selectionMenuTime').value;
if(!this.isPositiveValue(val)){ alert("The period should be a positive integer"); }
else{
if((val=>1) && (val<=200)){
var square = document.getElementById(this.name+'content');
var symb = document.getElementById('valueSymbolRSI Value').value;
var val2 = document.getElementById("valueInputRSI Value").value;
if(!this.isPositiveValue(val2)){ alert("The RSI Value should be a positive integer"); }
else{
square.innerHTML = "RSI";
var jsonString = '"TimeUnit":"'+time+'","comparaison":"indicator","indicator":"RSI","periodValue":"'+ val;
jsonString = jsonString + '","symbol":"' + symb + '","symbolValue":"' + val2 + '"';
this.$emit("updateMessage", jsonString);
this.isActive=false;
}
}
else{ alert("This period value must be between 1 and 200"); }
}
},
confirmMACD(){ // checks if the inputs for the MACD are corrects
if((this.switchMacdLine1==false)&&(this.switchMacdLine2==false)&&(this.switchMacdLine3==false)){
alert("Please select a type of line");
}
else{
var el1 = document.getElementById("valueInputShort Term Period").value;
var el2 = document.getElementById("valueInputLong Term Period").value;
var el3 = document.getElementById("valueInputSignal Term Period").value;
var time = document.getElementById('selectionMenuTime').value;
if((!this.isPositiveValue(el1))||(!this.isPositiveValue(el2))||(!this.isPositiveValue(el3))){
alert("The inputs must be positive integers");
}
else{
if( ((el1=>1) && (el1<=200)) && ((el2=>1) && (el2<=200)) && ((el3=>1) && (el3<=200)) ){
var square = document.getElementById(this.name+'content');
var symb = document.getElementById('valueSymbolMACD Value').value;
var val = document.getElementById("valueInputMACD Value").value;
if(!this.isPositiveValue(val)){ alert("The MACD Value should be a positive integer"); }
else{
var jsonString = '"TimeUnit":"'+time+'","comparaison":"indicator","indicator":"MACD","line":'
if(this.switchMacdLine1){ square.innerHTML = "MACD"; jsonString = jsonString + '"line"'; }
if(this.switchMacdLine2){ square.innerHTML = "MACD"; jsonString = jsonString + '"signal"';}
if(this.switchMacdLine3){ square.innerHTML = "MACD"; jsonString = jsonString + '"histogram"' }
jsonString = jsonString + ', "shortTermPeriod":"' + el1 + '","longTermPeriod":"' + el2 + '","signalTermPeriod":"' + el3;
jsonString = jsonString + '","symbol":"' + symb + '","symbolValue":"' + val + '"';
this.$emit("updateMessage", jsonString);
this.isActive=false;
}
}
else{ alert("The periods should be between 1 and 200."); }
}
}},
confirmBollinger(){ // checks if the inputs for the Bollinger are corrects
if((this.switchBollingerLine1==false)&&(this.switchBollingerLine2==false)&&(this.switchBollingerLine3==false)){
alert("Please select a type of line");
}
else{
var el1 = document.getElementById("valueInputStandard Deviation").value;
var el2 = document.getElementById("valueInputPeriod").value;
var time = document.getElementById('selectionMenuTime').value;
if(((!this.isPositiveValue(el1))&&(el1!=0))||(!this.isPositiveValue(el2))){
alert("The inputs must be positive integers");
}
else{
if( ((el1=>0) && (el1<=80)) && ((el2>=1)&&(el2<=80))){
var square = document.getElementById(this.name+'content');
var symb = document.getElementById('valueSymbolBollinger Value').value;
var val = document.getElementById("valueInputBollinger Value").value;
if(!this.isPositiveValue(val)){ alert("The Bollinger Value should be a positive integer"); }
else{
var jsonString = '"TimeUnit":"'+time+'","comparaison":"indicator","indicator":"StochasticRsi","line":'
if(this.switchBollingerLine1){ square.innerHTML = "Bollinger"; jsonString = jsonString + '"UpperBand",'; }
if(this.switchBollingerLine2){ square.innerHTML = "Bollinger"; jsonString = jsonString + '"MiddleBand",'; }
if(this.switchBollingerLine3){ square.innerHTML = "Bollinger"; jsonString = jsonString + '"LowerBand",'; }
jsonString = jsonString + '"standardDeviation":"' + el1 + '","period":"' + el2;
jsonString = jsonString + '","symbol":"' + symb + '","symbolValue":"' + val + '"';
this.$emit("updateMessage", jsonString);
this.isActive=false;
}
}
else{ alert("The standard deviation must be between 0 and 80 and the period must be between 1 and 80."); }
}
}
},
confirmStocRsi(){ // checks if the inputs for the Stochastic RSI are corrects
if((this.switchStocRsiLine1==false)&&(this.switchStocRsiLine2==false)){
alert("Please select a type of line");
}
else{
var el1 = document.getElementById("valueInputLength RSI").value;
var el2 = document.getElementById("valueInputLength Stoch").value;
var el3 = document.getElementById("valueInputSmooth K").value;
var el4 = document.getElementById("valueInputSmooth D").value;
var time = document.getElementById('selectionMenuTime').value;
if((!this.isPositiveValue(el1))
||(!this.isPositiveValue(el2))
||(!this.isPositiveValue(el3))
||(!this.isPositiveValue(el4))){ alert("The inputs must be positive integers"); }
else{
if( ((el1=>1) && (el1<=200)) && ((el2=>1) && (el2<=200)) && ((el3=>1) && (el3<=200)) && (el4=>1) && (el4<=200)){
var square = document.getElementById(this.name+'content');
var symb = document.getElementById('valueSymbolStochastic RSI Value').value;
var val = document.getElementById("valueInputStochastic RSI Value").value;
if(!this.isPositiveValue(val)){ alert("The Stochastic RSI Value should be a positive integer"); }
else{
var jsonString = '"TimeUnit":"'+time+'","comparaison":"indicator","indicator":"StochasticRsi","line":'
if(this.switchStocRsiLine1){ square.innerHTML = "Stochastic RSI"; jsonString = jsonString + '"D"';}
if(this.switchStocRsiLine2){ square.innerHTML = "Stochastic RSI"; jsonString = jsonString + '"K"'; }
jsonString = jsonString + ',"lengthRSI":"' + el1 + '","lengthStoch":"' + el2 + '","smoothK":"' + el3 + '","smoothD":"' + el4;
jsonString = jsonString + '","symbol":"' + symb + '","symbolValue":"' + val + '"';
this.$emit("updateMessage", jsonString);
this.isActive=false;
}
}
else{ alert("The Stochastic RSI parameters should be between 1 and 200.") }
}
}
},
filter() { // Filter for the 1st and 5th popup
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("search");
filter = input.value.toUpperCase();
ul = document.getElementById('selectionMenu'+this.title);
li = ul.getElementsByTagName("li");
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0];
txtValue = a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}},
updateFilter(item){ // Update the input of the 1st and 5th popup after a pair has been selected
this.inputValueCurr = item;
},
clearOption(){ // Delete the option
var el = document.getElementById(this.name+'content');
var jsonString = "";
var square = document.getElementById(this.name+'content');
square.style = "line-height: 35px;";
square.innerHTML = "";
this.$emit("updateMessage", jsonString);
this.isActive = false; // closes the popup
},
volume() {
this.switchPrice = false;
},
price() {
this.switchVolume = false;
},
volumeOption() {
this.switchPriceOption = false;
},
priceOption() {
this.switchVolumeOption = false;
},
/* SWITCHES METHODS */
indicator(){
this.switch2 = false;
},
macdLine(){
this.switchMacdLine2=false;
this.switchMacdLine3=false;
},
setTypeAction(str) {
this.typeAction = str;
} ,
setTypeActionOption(str) {
this.typeActionOption = str;
} ,
setTypeOperation(str) {
this.typeOperation = str;
} ,
setTrade(str) {
this.typeTrade = str;
},
macdSignalLine(){
this.switchMacdLine1=false;
this.switchMacdLine3=false;
},
macdHistogram(){
this.switchMacdLine1=false;
this.switchMacdLine2=false;
},
upperBandLine(){
this.switchBollingerLine2=false;
this.switchBollingerLine3=false;
},
middleBandLine(){
this.switchBollingerLine1=false;
this.switchBollingerLine3=false;
},
lowerBandLine(){
this.switchBollingerLine1=false;
this.switchBollingerLine2=false;
},
DLine(){
this.switchStocRsiLine2=false;
},
KLine(){
this.switchStocRsiLine1=false;
},
/* CHECK METHODS */
isSymbol(){ // called when a symbol is selected
this.symbol=true;
},
isMA(){ // called when the MA indicator is selected
this.ma = true;
this.macd=false;
this.rsi=false;
this.stocRsi=false;
this.bollinger=false;
},
isMACD(){ // called when the MACD indicator is selected
this.ma = false;
this.macd=true;
this.rsi=false;
this.stocRsi=false;
this.bollinger=false;
},
isRSI(){ // called when the RSI indicator is selected
this.ma = false;
this.macd=false;
this.rsi=true;
this.stocRsi=false;
this.bollinger=false;
},
isSTOCRSI(){ // called when the Stochastic RSI indicator is selected
this.ma = false;
this.macd=false;
this.rsi=false;
this.stocRsi=true;
this.bollinger=false;
},
isBOLLINGER(){ // called when the bollinger indicator is selected
this.ma = false;
this.macd=false;
this.rsi=false;
this.stocRsi=false;
this.bollinger=true;
},