-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpapertrader.html
More file actions
1114 lines (1012 loc) · 62.8 KB
/
papertrader.html
File metadata and controls
1114 lines (1012 loc) · 62.8 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rocking M Paper Trader</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;600&family=Barlow+Condensed:wght@300;400;600;700;800&display=swap');
:root {
--bg:#e8eaed;--bg2:#f2f4f6;--bg3:#ffffff;--bg-header:#1a2330;
--border:#c4cad2;--border2:#a8b2bc;
--green:#007a3d;--green-lt:#00a651;--green-bg:#e6f4ec;--green-hi:#00cc66;
--blue:#0055a5;--blue-lt:#0077cc;
--red:#cc2200;--red-bg:#fdecea;
--amber:#c47a00;--amber-bg:#fff8e6;
--text:#1a1f26;--text-mid:#3d4a57;--text-dim:#6b7a8a;
--mono:'IBM Plex Mono',monospace;--sans:'Barlow Condensed',sans-serif;
--serif:'Georgia','Times New Roman',serif;
}
*{margin:0;padding:0;box-sizing:border-box;}
body{background:var(--bg);color:var(--text);font-family:var(--sans);font-size:14px;min-height:100vh;}
/* ── Header ── */
.top-bar{background:var(--bg-header);border-bottom:3px solid var(--green-lt);padding:12px 28px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px;}
.logo-badge{display:flex;align-items:center;gap:16px;}
.badge-mark{width:68px;height:76px;background:#111a24;border:1.5px solid var(--green-lt);border-radius:6px;display:flex;flex-direction:column;align-items:center;justify-content:flex-start;padding-top:6px;flex-shrink:0;position:relative;}
.badge-rocking{font-family:var(--sans);font-size:8px;font-weight:800;letter-spacing:4px;color:var(--green-hi);text-transform:uppercase;line-height:1;}
.badge-m{font-family:var(--serif);font-size:50px;font-weight:700;color:#fff;line-height:1;margin-top:-2px;}
.badge-sub{font-family:var(--sans);font-size:7px;font-weight:600;letter-spacing:3px;color:#3d5570;text-transform:uppercase;position:absolute;bottom:5px;}
.brand-text{display:flex;flex-direction:column;gap:2px;}
.brand-title{font-family:var(--sans);font-size:26px;font-weight:800;letter-spacing:3px;text-transform:uppercase;color:#fff;line-height:1;}
.brand-title span{color:var(--green-hi);}
.brand-sub-text{font-family:var(--mono);font-size:9px;color:#4a6070;letter-spacing:2px;margin-top:3px;text-transform:uppercase;}
.nav-links{display:flex;gap:16px;align-items:center;}
.nav-link{font-family:var(--mono);font-size:10px;letter-spacing:2px;color:#4a6070;text-decoration:none;text-transform:uppercase;transition:color .15s;}
.nav-link:hover{color:var(--green-hi);}
.shell{max-width:1400px;margin:0 auto;padding:20px 24px 40px;}
/* ── Setup panel ── */
.setup-panel{background:var(--bg3);border:1px solid var(--border);border-top:3px solid var(--green);padding:18px 20px;margin-bottom:16px;box-shadow:0 1px 4px rgba(0,0,0,.08);}
.setup-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:12px;margin-bottom:12px;}
.fgroup{display:flex;flex-direction:column;gap:4px;}
.flabel{font-family:var(--mono);font-size:9px;color:var(--text-dim);letter-spacing:2px;text-transform:uppercase;}
.finput{font-family:var(--mono);font-size:12px;background:var(--bg2);border:1px solid var(--border);color:var(--text);padding:6px 10px;outline:none;transition:border-color .15s;width:100%;}
.finput:focus{border-color:var(--green);background:#fff;}
select.finput{cursor:pointer;}
/* ── Chain tier note ── */
.chain-tier-note{font-family:var(--mono);font-size:9px;color:var(--text-dim);letter-spacing:1px;margin-top:4px;display:block;line-height:1.6;}
.chain-tier-note strong{color:var(--amber);}
/* ── Portfolio stats ── */
.portfolio-row{display:flex;gap:8px;margin-bottom:16px;flex-wrap:wrap;}
.pcard{background:var(--bg3);border:1px solid var(--border);border-left:4px solid var(--green);padding:10px 14px;flex:1;min-width:120px;box-shadow:0 1px 3px rgba(0,0,0,.07);}
.pcard.red-card{border-left-color:var(--red);}
.pcard.amber-card{border-left-color:var(--amber);}
.pcard.blue-card{border-left-color:var(--blue);}
.pcard.hot-card{border-left-color:var(--green-lt);}
.pcard-label{font-family:var(--mono);font-size:9px;color:var(--text-dim);letter-spacing:2px;text-transform:uppercase;margin-bottom:4px;}
.pcard-val{font-family:var(--mono);font-size:18px;color:var(--text);font-weight:600;}
/* ── Entry panel ── */
.entry-panel{background:var(--bg3);border:1px solid var(--border);border-top:3px solid var(--blue);padding:18px 20px;margin-bottom:16px;box-shadow:0 1px 4px rgba(0,0,0,.08);}
.sec-hdr{font-family:var(--sans);font-size:14px;font-weight:800;letter-spacing:3px;text-transform:uppercase;color:var(--text);border-bottom:2px solid var(--green);padding-bottom:6px;margin-bottom:14px;}
.entry-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(140px,1fr));gap:10px;margin-bottom:12px;}
/* ── Stop/TP config ── */
.risk-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:12px;}
.risk-box{background:var(--bg2);border:1px solid var(--border);padding:14px 16px;}
.risk-box-title{font-family:var(--mono);font-size:10px;letter-spacing:2px;text-transform:uppercase;margin-bottom:10px;display:flex;align-items:center;gap:8px;}
.risk-box-title.stop{color:var(--red);}
.risk-box-title.tp{color:var(--green);}
.risk-row{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;margin-bottom:8px;align-items:flex-end;}
.tp-row{display:grid;grid-template-columns:1fr 1fr 1fr auto;gap:8px;margin-bottom:8px;align-items:flex-end;}
/* ── Buttons ── */
.btn{font-family:var(--sans);font-size:14px;font-weight:700;letter-spacing:2px;text-transform:uppercase;padding:8px 20px;border:2px solid var(--green);background:var(--green);color:#fff;cursor:pointer;transition:all .15s;box-shadow:0 1px 4px rgba(0,122,61,.2);}
.btn:hover{background:var(--green-lt);border-color:var(--green-lt);}
.btn:disabled{opacity:.4;cursor:not-allowed;}
.btn-red{border-color:var(--red);background:var(--red);}
.btn-red:hover{background:#e03300;border-color:#e03300;}
.btn-amber{border-color:var(--amber);background:var(--amber);}
.btn-amber:hover{background:#d48800;}
.btn-sm{font-family:var(--mono);font-size:10px;letter-spacing:1px;padding:5px 12px;border:1px solid var(--border2);background:var(--bg3);color:var(--text-mid);cursor:pointer;transition:all .15s;}
.btn-sm:hover{border-color:var(--green);color:var(--green);background:var(--green-bg);}
.btn-icon{background:transparent;border:none;cursor:pointer;font-size:12px;color:var(--text-dim);padding:2px 6px;transition:color .15s;}
.btn-icon:hover{color:var(--red);}
/* ── Positions table ── */
.tbl-wrap{overflow-x:auto;border:1px solid var(--border);background:var(--bg3);box-shadow:0 2px 8px rgba(0,0,0,.08);margin-bottom:16px;}
table{width:100%;border-collapse:collapse;font-family:var(--mono);font-size:11px;}
thead tr{background:var(--bg-header);}
th{padding:9px 10px;text-align:left;font-size:8px;letter-spacing:2px;color:#a0b4c4;text-transform:uppercase;white-space:nowrap;border-right:1px solid rgba(255,255,255,.06);}
th:last-child{border-right:none;}
tbody tr{border-bottom:1px solid var(--border);transition:background .1s;}
tbody tr:nth-child(even){background:#f7f9fb;}
tbody tr:hover{background:#edf5f0!important;}
td{padding:8px 10px;white-space:nowrap;color:var(--text);border-right:1px solid rgba(196,202,210,.4);}
td:last-child{border-right:none;}
.pos-up{color:var(--green);font-weight:600;}
.pos-dn{color:var(--red);font-weight:600;}
.pos-neu{color:var(--text-dim);}
/* ── Chain tags — full set matching screener ── */
.chain-tag{font-size:9px;letter-spacing:1px;padding:2px 7px;text-transform:uppercase;font-weight:600;border-radius:2px;display:inline-block;}
.ct-solana {background:#2d1a4a;color:#c49fff;border:1px solid #9945ff;}
.ct-eth {background:#1a2040;color:#aabfff;border:1px solid #6699ff;}
.ct-base {background:#001a3a;color:#88aaff;border:1px solid #4488ff;}
.ct-bsc {background:#2a2000;color:#f0d060;border:1px solid #f0b800;}
.ct-arbitrum {background:#001a2a;color:#70ccff;border:1px solid #12aaff;}
.ct-optimism {background:#2a0000;color:#ff9090;border:1px solid #ff4444;}
.ct-polygon {background:#1a0a30;color:#b080ff;border:1px solid #8247e5;}
.ct-avax {background:#2a0505;color:#ff8080;border:1px solid #e84142;}
.ct-sui {background:#001830;color:#90c8ff;border:1px solid #4da2ff;}
.ct-tron {background:#2a0005;color:#ff6070;border:1px solid #ff0013;}
.ct-blast {background:#1a1a00;color:#f0f060;border:1px solid #fcfc03;}
.ct-berachain{background:#1a0a00;color:#d2691e;border:1px solid #8b4513;}
.ct-cosmos {background:#120a1e;color:#b090d0;border:1px solid #6f4e8a;}
.ct-other {background:#1a2330;color:#8fa0b0;border:1px solid #3d5570;}
.badge{font-size:9px;letter-spacing:1px;padding:2px 6px;border:1px solid var(--border2);color:var(--text-dim);text-transform:uppercase;background:var(--bg2);}
.empty-msg{text-align:center;padding:40px 20px;font-family:var(--mono);font-size:12px;color:var(--text-dim);letter-spacing:2px;}
/* ── Remi log ── */
.remi-log{background:var(--bg-header);border:1px solid #2a3a4a;padding:12px 16px;max-height:180px;overflow-y:auto;margin-bottom:16px;}
.remi-log-hdr{font-family:var(--mono);font-size:9px;letter-spacing:3px;color:var(--green-hi);text-transform:uppercase;margin-bottom:8px;}
.log-entry{display:flex;gap:10px;margin-bottom:6px;font-family:var(--mono);font-size:10px;line-height:1.6;}
.log-time{color:#3d5570;min-width:60px;flex-shrink:0;}
.log-ok{color:var(--green-hi);}
.log-warn{color:#f0a030;}
.log-err{color:#ff5540;}
.log-info{color:#8fa0b0;}
/* ── Closed trades ── */
.closed-tbl td.win{color:var(--green);font-weight:600;}
.closed-tbl td.loss{color:var(--red);font-weight:600;}
.closed-tbl td.scratch{color:var(--amber);}
/* ── Override modal ── */
.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.6);z-index:1000;display:none;align-items:center;justify-content:center;}
.modal-overlay.show{display:flex;}
.modal{background:var(--bg3);border:1px solid var(--border);border-top:3px solid var(--amber);padding:24px;width:480px;max-width:90vw;box-shadow:0 8px 32px rgba(0,0,0,.3);}
.modal-title{font-family:var(--sans);font-size:16px;font-weight:800;letter-spacing:2px;text-transform:uppercase;color:var(--text);margin-bottom:16px;}
.modal-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:16px;}
.modal-btns{display:flex;gap:8px;justify-content:flex-end;}
.export-row{display:flex;gap:8px;margin-top:8px;}
/* ── Footer ── */
footer{margin-top:20px;padding-top:14px;border-top:2px solid var(--border);display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;}
footer span{font-family:var(--mono);font-size:9px;color:var(--text-dim);letter-spacing:1px;}
footer a{color:var(--green-hi);text-decoration:none;}
footer a:hover{text-decoration:underline;}
.toast{position:fixed;bottom:20px;right:20px;background:var(--bg-header);border:1px solid var(--green-lt);padding:10px 18px;font-family:var(--mono);font-size:11px;color:var(--green-hi);letter-spacing:1px;z-index:10000;opacity:0;transform:translateY(8px);transition:all .2s;pointer-events:none;box-shadow:0 4px 16px rgba(0,0,0,.2);}
.toast.show{opacity:1;transform:translateY(0);}
.spinner{display:inline-block;width:10px;height:10px;border:2px solid var(--border2);border-top-color:var(--green);border-radius:50%;animation:spin .7s linear infinite;vertical-align:middle;margin-right:6px;}
@keyframes spin{to{transform:rotate(360deg)}}
@media(max-width:700px){
.risk-grid{grid-template-columns:1fr;}
.shell{padding:16px 12px 40px;}
}
</style>
</head>
<body>
<!-- Header -->
<div class="top-bar">
<div class="logo-badge">
<div class="badge-mark">
<span class="badge-rocking">Rocking</span>
<svg width="54" height="13" viewBox="0 0 54 13" fill="none" style="display:block;margin:2px 0 -4px">
<path d="M 2 11 Q 27 2 52 11" stroke="#00cc66" stroke-width="2.5" stroke-linecap="round" fill="none"/>
</svg>
<span class="badge-m">M</span>
<span class="badge-sub">Crypto</span>
</div>
<div class="brand-text">
<div class="brand-title">ROCKING <span>M</span> PAPER TRADER</div>
<div class="brand-sub-text">Simulated trading · AI training data · No real money</div>
</div>
</div>
<div class="nav-links">
<a href="screener.html" class="nav-link">◈ Screener</a>
<a href="remi.html" class="nav-link">◈ Ask Remi</a>
<a href="index.html" class="nav-link">◈ Home</a>
</div>
</div>
<div class="shell">
<!-- Disclaimer -->
<div style="margin-bottom:16px;padding:12px 18px;background:var(--amber-bg);border:1px solid var(--border);border-left:4px solid var(--amber);font-family:var(--mono);font-size:10px;color:var(--text-mid);letter-spacing:1px;line-height:1.8;">
<strong style="color:var(--amber)">PAPER TRADING ONLY</strong> —
This simulator uses real market data but virtual money. No real funds are used or at risk.
Simulated results do not guarantee real trading performance. For research and AI training purposes only.
</div>
<!-- Account Setup -->
<div class="setup-panel">
<div class="sec-hdr" style="border-color:var(--green)">Account Setup</div>
<div class="setup-grid">
<div class="fgroup">
<span class="flabel">Starting Balance ($)</span>
<input class="finput" type="number" id="start-balance" value="1000" min="100" step="100">
</div>
<div class="fgroup">
<span class="flabel">Max Positions (2-10)</span>
<input class="finput" type="number" id="max-positions" value="5" min="2" max="10">
</div>
<div class="fgroup">
<span class="flabel">Capital Reserve (%)</span>
<input class="finput" type="number" id="reserve-pct" value="20" min="0" max="50" step="5">
</div>
<div class="fgroup">
<span class="flabel">Max Hold Time</span>
<select class="finput" id="max-hold">
<option value="0">No limit</option>
<option value="24">24 hours</option>
<option value="48">48 hours</option>
<option value="72">72 hours</option>
</select>
</div>
</div>
<div style="display:flex;gap:8px;flex-wrap:wrap;">
<button class="btn" onclick="initAccount()">▶ Initialize Account</button>
<button class="btn-sm" onclick="resetAccount()" style="border-color:var(--red);color:var(--red)">✎ Reset Account</button>
</div>
</div>
<!-- Portfolio Stats -->
<div class="portfolio-row">
<div class="pcard"><div class="pcard-label">Total Balance</div><div class="pcard-val" id="stat-balance">$0.00</div></div>
<div class="pcard hot-card"><div class="pcard-label">Available</div><div class="pcard-val" id="stat-available" style="color:var(--green-lt)">$0.00</div></div>
<div class="pcard blue-card"><div class="pcard-label">In Positions</div><div class="pcard-val" id="stat-invested" style="color:var(--blue)">$0.00</div></div>
<div class="pcard amber-card"><div class="pcard-label">Reserved</div><div class="pcard-val" id="stat-reserved" style="color:var(--amber)">$0.00</div></div>
<div class="pcard"><div class="pcard-label">Open P&L</div><div class="pcard-val" id="stat-pnl">$0.00</div></div>
<div class="pcard"><div class="pcard-label">Total Trades</div><div class="pcard-val" id="stat-trades">0</div></div>
<div class="pcard hot-card"><div class="pcard-label">Win Rate</div><div class="pcard-val" id="stat-winrate" style="font-size:14px">—</div></div>
</div>
<!-- New Position Entry -->
<div class="entry-panel">
<div class="sec-hdr" style="border-color:var(--blue)">Open New Position</div>
<div class="entry-grid">
<div class="fgroup">
<span class="flabel">Chain</span>
<select class="finput" id="entry-chain">
<optgroup label="── Tier 1 · GoPlus Security ──">
<option value="solana">Solana</option>
<option value="eth">Ethereum</option>
<option value="base">Base</option>
<option value="bsc">BSC</option>
<option value="arbitrum">Arbitrum</option>
<option value="optimism">Optimism</option>
</optgroup>
<optgroup label="── Tier 2 · Price Data Only ──">
<option value="polygon_pos">Polygon</option>
<option value="avax">Avalanche</option>
<option value="sui-network">Sui</option>
<option value="tron">Tron</option>
<option value="blast">Blast</option>
<option value="berachain">Berachain</option>
<option value="cosmos">Cosmos</option>
</optgroup>
</select>
<span class="chain-tier-note"><strong>Tier 2 chains:</strong> price data only — no GoPlus security data available. Do extra research before trading.</span>
</div>
<div class="fgroup" style="grid-column:span 2">
<span class="flabel">Pool or Token Address</span>
<input class="finput" type="text" id="entry-address" placeholder="Paste pool address from screener or token address...">
<span style="font-family:var(--mono);font-size:9px;color:var(--text-dim);letter-spacing:1px;margin-top:3px;display:block">Accepts pool address (GeckoTerminal) or token contract address</span>
</div>
<div class="fgroup">
<span class="flabel">Token Symbol</span>
<input class="finput" type="text" id="entry-symbol" placeholder="TOKEN">
</div>
<div class="fgroup">
<span class="flabel">Position Size ($)</span>
<input class="finput" type="number" id="entry-size" placeholder="100" min="1" step="10">
</div>
<div class="fgroup">
<span class="flabel">Slippage Tolerance (%)</span>
<select class="finput" id="entry-slippage">
<option value="1">1%</option>
<option value="3" selected>3%</option>
<option value="5">5%</option>
<option value="10">10%</option>
</select>
</div>
<div class="fgroup">
<span class="flabel">Liquidity Floor ($)</span>
<input class="finput" type="number" id="entry-liq-floor" value="5000" min="0" step="500" title="Emergency exit if liquidity drops below this amount">
<span style="font-family:var(--mono);font-size:9px;color:var(--text-dim);letter-spacing:1px;margin-top:3px;display:block">Emergency exit if liq drops below this</span>
</div>
<div class="fgroup" style="grid-column:span 2">
<span class="flabel">Entry Reason (filters & signals)</span>
<input class="finput" type="text" id="entry-reason" placeholder="e.g. liq>20k, 1h>15%, age<1h, low pool%, clean chart">
<span style="font-family:var(--mono);font-size:9px;color:var(--text-dim);letter-spacing:1px;margin-top:3px;display:block">Used for ElizaOS training data — be specific about what caught your eye</span>
</div>
</div>
<!-- Stop Loss Config -->
<div class="risk-grid">
<div class="risk-box">
<div class="risk-box-title stop">▼ Stop Loss Levels</div>
<div class="risk-row">
<div class="fgroup"><span class="flabel">Level 1 Loss %</span><input class="finput" type="number" id="sl1-pct" value="15" min="1" max="50"></div>
<div class="fgroup"><span class="flabel">Sell %</span><input class="finput" type="number" id="sl1-sell" value="50" min="1" max="99"></div>
<div class="fgroup"><span class="flabel">Enabled</span><select class="finput" id="sl1-on"><option value="1">Yes</option><option value="0">No</option></select></div>
</div>
<div class="risk-row">
<div class="fgroup"><span class="flabel">Level 2 Loss %</span><input class="finput" type="number" id="sl2-pct" value="30" min="1" max="90"></div>
<div class="fgroup"><span class="flabel">Sell %</span><input class="finput" style="background:#fdecea" type="number" value="100" disabled></div>
<div class="fgroup"><span class="flabel">Enabled</span><select class="finput" id="sl2-on"><option value="1">Yes</option><option value="0">No</option></select></div>
</div>
</div>
<div class="risk-box">
<div class="risk-box-title tp">▲ Take Profit Levels</div>
<div class="tp-row">
<div class="fgroup"><span class="flabel">TP1 Gain %</span><input class="finput" type="number" id="tp1-pct" value="25" min="1"></div>
<div class="fgroup"><span class="flabel">Sell %</span><input class="finput" type="number" id="tp1-sell" value="25" min="1" max="100"></div>
<div class="fgroup"><span class="flabel">Enabled</span><select class="finput" id="tp1-on"><option value="1">Yes</option><option value="0">No</option></select></div>
<div></div>
</div>
<div class="tp-row">
<div class="fgroup"><span class="flabel">TP2 Gain %</span><input class="finput" type="number" id="tp2-pct" value="50" min="1"></div>
<div class="fgroup"><span class="flabel">Sell %</span><input class="finput" type="number" id="tp2-sell" value="25" min="1" max="100"></div>
<div class="fgroup"><span class="flabel">Enabled</span><select class="finput" id="tp2-on"><option value="1">Yes</option><option value="0">No</option></select></div>
<div></div>
</div>
<div class="tp-row">
<div class="fgroup"><span class="flabel">TP3 Gain %</span><input class="finput" type="number" id="tp3-pct" value="100" min="1"></div>
<div class="fgroup"><span class="flabel">Sell %</span><input class="finput" type="number" id="tp3-sell" value="25" min="1" max="100"></div>
<div class="fgroup"><span class="flabel">Enabled</span><select class="finput" id="tp3-on"><option value="1">Yes</option><option value="0">No</option></select></div>
<div></div>
</div>
<div class="tp-row">
<div class="fgroup"><span class="flabel">Trailing Stop %</span><input class="finput" type="number" id="trail-pct" value="15" min="1" max="50"></div>
<div class="fgroup"><span class="flabel">Sell remainder</span><input class="finput" style="background:#e6f4ec" type="text" value="100%" disabled></div>
<div class="fgroup"><span class="flabel">Enabled</span><select class="finput" id="trail-on"><option value="1">Yes</option><option value="0">No</option></select></div>
<div></div>
</div>
<div class="tp-row">
<div class="fgroup"><span class="flabel">Activate After Gain %</span><input class="finput" type="number" id="trail-activate-pct" value="25" min="0" max="500" title="Trailing stop only activates after price gains this much from entry"></div>
<div class="fgroup"><span class="flabel">Activate After (mins)</span><input class="finput" type="number" id="trail-activate-mins" value="15" min="0" max="1440" title="Trailing stop only activates after this many minutes from entry"></div>
<div class="fgroup" style="grid-column:span 2"><span class="flabel" style="color:var(--text-dim)">Trail activates when BOTH conditions are met</span><div style="font-family:var(--mono);font-size:9px;color:var(--text-dim);padding:6px 10px;background:var(--bg2);border:1px solid var(--border);letter-spacing:1px">Set to 0 to disable each condition individually</div></div>
</div>
</div>
</div>
<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center;">
<button class="btn" id="fetch-btn" onclick="fetchAndEnter()">▶ FETCH PRICE & ENTER</button>
<button class="btn-sm" onclick="fetchPrice()"><span class="spinner" id="fetch-spin" style="display:none"></span>FETCH PRICE ONLY</button>
<span style="font-family:var(--mono);font-size:11px;color:var(--text-dim)" id="fetched-price"></span>
</div>
</div>
<!-- Open Positions -->
<div class="sec-hdr">Open Positions <span id="pos-refresh-countdown" style="font-size:10px;color:var(--text-dim);font-weight:400;letter-spacing:1px;margin-left:12px"></span></div>
<div class="tbl-wrap">
<table>
<thead>
<tr>
<th>Chain</th><th>Symbol</th><th>Entry $</th><th>Current $</th>
<th>Size</th><th>Remaining%</th><th>P&L $</th><th>P&L %</th>
<th>Peak $</th><th>Age</th><th>SL1</th><th>SL2</th>
<th>TP1</th><th>TP2</th><th>TP3</th><th>Trail</th>
<th>Entry Reason</th><th>Actions</th>
</tr>
</thead>
<tbody id="positions-body">
<tr><td colspan="18" class="empty-msg">No open positions — enter a trade above</td></tr>
</tbody>
</table>
</div>
<!-- Remi Event Log -->
<div class="remi-log">
<div class="remi-log-hdr">◈ Remi Event Log</div>
<div id="remi-log-body"></div>
</div>
<!-- Closed Trades -->
<div class="sec-hdr">Closed Trades</div>
<div class="tbl-wrap">
<table class="closed-tbl">
<thead>
<tr>
<th>Date</th><th>Chain</th><th>Symbol</th><th>Entry $</th><th>Exit $</th>
<th>Size</th><th>Gas</th><th>P&L $</th><th>P&L %</th>
<th>Entry Reason</th><th>Exit Reason</th><th>Duration</th>
</tr>
</thead>
<tbody id="closed-body">
<tr><td colspan="12" class="empty-msg">No closed trades yet</td></tr>
</tbody>
</table>
</div>
<div class="export-row">
<button class="btn-sm" onclick="exportCSV()">↓ Export CSV</button>
<button class="btn-sm" onclick="exportJSON()">↓ Export JSON (ElizaOS)</button>
<button class="btn-sm" onclick="exportRemiLog()">↓ Export Remi Log</button>
</div>
<footer>
<span>Rocking M Paper Trader · Simulated only · No real funds</span>
<span>
<span><a href="screener.html">Screener</a> · <a href="remi.html">Ask Remi</a> · <a href="https://github.com/RockingMScreener/rocking-m-screener">GitHub</a> · <a href="https://x.com/Rockingmscreen" target="_blank" rel="noopener noreferrer">X</a> · <a href="https://discord.gg/Z2VWxUcpy" target="_blank" rel="noopener noreferrer">Discord</a></span>
</span>
<span>Prices via GeckoTerminal · 13 Chains · Refreshes every 60s</span>
</footer>
</div>
<!-- Override Modal -->
<div class="modal-overlay" id="override-modal">
<div class="modal">
<div class="modal-title">✎ Override Position Levels</div>
<input type="hidden" id="override-pos-id">
<div class="modal-grid">
<div class="fgroup"><span class="flabel">SL1 Loss %</span><input class="finput" type="number" id="ov-sl1-pct"></div>
<div class="fgroup"><span class="flabel">SL1 Sell %</span><input class="finput" type="number" id="ov-sl1-sell"></div>
<div class="fgroup"><span class="flabel">SL2 Loss %</span><input class="finput" type="number" id="ov-sl2-pct"></div>
<div class="fgroup"><span class="flabel">SL2 Enabled</span><select class="finput" id="ov-sl2-on"><option value="1">Yes</option><option value="0">No</option></select></div>
<div class="fgroup"><span class="flabel">TP1 Gain %</span><input class="finput" type="number" id="ov-tp1-pct"></div>
<div class="fgroup"><span class="flabel">TP1 Sell %</span><input class="finput" type="number" id="ov-tp1-sell"></div>
<div class="fgroup"><span class="flabel">TP2 Gain %</span><input class="finput" type="number" id="ov-tp2-pct"></div>
<div class="fgroup"><span class="flabel">TP2 Sell %</span><input class="finput" type="number" id="ov-tp2-sell"></div>
<div class="fgroup"><span class="flabel">TP3 Gain %</span><input class="finput" type="number" id="ov-tp3-pct"></div>
<div class="fgroup"><span class="flabel">TP3 Sell %</span><input class="finput" type="number" id="ov-tp3-sell"></div>
<div class="fgroup"><span class="flabel">Trailing Stop %</span><input class="finput" type="number" id="ov-trail-pct"></div>
<div class="fgroup"><span class="flabel">Trail Enabled</span><select class="finput" id="ov-trail-on"><option value="1">Yes</option><option value="0">No</option></select></div>
<div class="fgroup"><span class="flabel">Activate After Gain %</span><input class="finput" type="number" id="ov-trail-activate-pct"></div>
<div class="fgroup"><span class="flabel">Activate After (mins)</span><input class="finput" type="number" id="ov-trail-activate-mins"></div>
</div>
<div class="modal-btns">
<button class="btn-sm" onclick="closeOverride()">Cancel</button>
<button class="btn btn-amber" onclick="saveOverride()">Save Override</button>
</div>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
// ── Chain config — all 13 chains ───────────────────────────────
// gas: simulated transaction cost in USD
// failRate: probability of slippage failure (0–1)
// gecko: GeckoTerminal network ID
// tier: 1 = GoPlus security available, 2 = price data only
const CHAINS = {
// ── Tier 1 ──
solana: { label:'Solana', tag:'ct-solana', gas:0.50, failRate:0.02, gecko:'solana', tier:1 },
eth: { label:'Ethereum', tag:'ct-eth', gas:8.00, failRate:0.04, gecko:'eth', tier:1 },
base: { label:'Base', tag:'ct-base', gas:0.50, failRate:0.02, gecko:'base', tier:1 },
bsc: { label:'BSC', tag:'ct-bsc', gas:1.00, failRate:0.03, gecko:'bsc', tier:1 },
arbitrum: { label:'Arbitrum', tag:'ct-arbitrum', gas:1.50, failRate:0.02, gecko:'arbitrum', tier:1 },
optimism: { label:'Optimism', tag:'ct-optimism', gas:1.50, failRate:0.02, gecko:'optimism', tier:1 },
// ── Tier 2 ──
polygon_pos: { label:'Polygon', tag:'ct-polygon', gas:0.25, failRate:0.02, gecko:'polygon_pos', tier:2 },
avax: { label:'Avalanche', tag:'ct-avax', gas:1.00, failRate:0.02, gecko:'avax', tier:2 },
'sui-network':{ label:'Sui', tag:'ct-sui', gas:0.25, failRate:0.02, gecko:'sui-network', tier:2 },
tron: { label:'Tron', tag:'ct-tron', gas:1.00, failRate:0.03, gecko:'tron', tier:2 },
blast: { label:'Blast', tag:'ct-blast', gas:0.50, failRate:0.02, gecko:'blast', tier:2 },
berachain: { label:'Berachain', tag:'ct-berachain', gas:0.50, failRate:0.03, gecko:'berachain', tier:2 },
cosmos: { label:'Cosmos', tag:'ct-cosmos', gas:0.10, failRate:0.02, gecko:'cosmos', tier:2 },
};
// ── State ──────────────────────────────────────────────────────
let account = null;
let positions = [];
let closed = [];
let remiLog = [];
let refreshTimer = null;
let refreshCountdown = 60;
const STORAGE_KEY = 'rm_papertrader_v1';
// ── Persistence ────────────────────────────────────────────────
function save() {
localStorage.setItem(STORAGE_KEY, JSON.stringify({ account, positions, closed, remiLog }));
}
function load() {
const d = localStorage.getItem(STORAGE_KEY);
if (d) {
try {
const p = JSON.parse(d);
account = p.account || null;
positions = p.positions || [];
closed = p.closed || [];
remiLog = p.remiLog || [];
} catch(e) {}
}
}
// ── Account ────────────────────────────────────────────────────
function initAccount() {
const bal = parseFloat(document.getElementById('start-balance').value) || 1000;
const maxP = Math.min(10, Math.max(2, parseInt(document.getElementById('max-positions').value) || 5));
const res = Math.min(50, Math.max(0, parseFloat(document.getElementById('reserve-pct').value) || 20));
const hold = parseInt(document.getElementById('max-hold').value) || 0;
if (account && positions.length > 0) {
if (!confirm('You have open positions. Reinitializing will close them. Continue?')) return;
}
account = { balance: bal, startBalance: bal, maxPositions: maxP, reservePct: res, maxHoldHours: hold, createdAt: Date.now() };
positions = [];
save();
remiLog_add('Account initialized. Balance: ' + fUsd(bal) + ' | Max positions: ' + maxP + ' | Reserve: ' + res + '% | Hold limit: ' + (hold ? hold + 'h' : 'none'), 'ok');
renderAll();
startRefresh();
toast('Account initialized — ready to trade');
}
function resetAccount() {
if (!confirm('Reset everything? All positions, trades, and logs will be cleared.')) return;
account = null; positions = []; closed = []; remiLog = [];
save();
stopRefresh();
renderAll();
toast('Account reset');
}
// ── Chain helper ───────────────────────────────────────────────
function getChain(chainKey) {
return CHAINS[chainKey] || { label: chainKey, tag: 'ct-other', gas: 1.00, failRate: 0.03, gecko: chainKey, tier: 2 };
}
// ── Price fetch ────────────────────────────────────────────────
async function resolveAddress(chain, address) {
const gecko = getChain(chain).gecko;
const poolUrl = `https://api.geckoterminal.com/api/v2/networks/${gecko}/pools/${address}`;
const poolResp = await fetch(poolUrl, { headers: { Accept: 'application/json;version=20230302' }});
if (poolResp.ok) {
const json = await poolResp.json();
if (json.data) return { poolAddress: address, isToken: false };
}
const tokenUrl = `https://api.geckoterminal.com/api/v2/networks/${gecko}/tokens/${address}/pools?page=1`;
const tokenResp = await fetch(tokenUrl, { headers: { Accept: 'application/json;version=20230302' }});
if (!tokenResp.ok) throw new Error('Address not found as pool or token on ' + getChain(chain).label);
const tokenJson = await tokenResp.json();
const pools = tokenJson.data || [];
if (!pools.length) throw new Error('No pools found for this token on ' + getChain(chain).label);
pools.sort((a, b) => parseFloat(b.attributes?.reserve_in_usd||0) - parseFloat(a.attributes?.reserve_in_usd||0));
const topPool = pools[0];
return { poolAddress: topPool.attributes?.address, isToken: true, liq: parseFloat(topPool.attributes?.reserve_in_usd||0), dex: topPool.attributes?.dex_id || 'unknown', poolCount: pools.length };
}
async function getPoolData(chain, poolAddress) {
const gecko = getChain(chain).gecko;
const url = `https://api.geckoterminal.com/api/v2/networks/${gecko}/pools/${poolAddress}`;
const r = await fetch(url, { headers: { Accept: 'application/json;version=20230302' }});
if (!r.ok) throw new Error('HTTP ' + r.status);
const json = await r.json();
const attrs = json.data?.attributes;
if (!attrs) throw new Error('Pool data not found');
const price = parseFloat(attrs.base_token_price_usd || 0);
const liq = parseFloat(attrs.reserve_in_usd || 0);
if (!price) throw new Error('Price not found');
return { price, liq };
}
async function getPriceAndLiq(chain, poolAddress) {
return await getPoolData(chain, poolAddress);
}
async function fetchPrice() {
const addr = document.getElementById('entry-address').value.trim();
const chain = document.getElementById('entry-chain').value;
if (!addr) { toast('Enter a pool address first'); return; }
const spin = document.getElementById('fetch-spin');
const priceEl = document.getElementById('fetched-price');
spin.style.display = 'inline-block';
priceEl.textContent = 'Resolving address...';
priceEl.style.color = 'var(--text-dim)';
try {
const resolved = await resolveAddress(chain, addr);
if (resolved.isToken) {
document.getElementById('entry-address').value = resolved.poolAddress;
}
const { price, liq } = await getPriceAndLiq(chain, resolved.poolAddress);
const tierNote = getChain(chain).tier === 2 ? ' · Tier 2 chain — no GoPlus security data' : '';
priceEl.textContent = 'Price: ' + fPrice(price) + ' | Liquidity: ' + fUsd(liq) + (resolved.isToken ? ' (auto-resolved)' : '') + tierNote;
priceEl.style.color = getChain(chain).tier === 2 ? 'var(--amber)' : 'var(--green)';
toast('Price fetched: ' + fPrice(price));
} catch(e) {
priceEl.textContent = 'Fetch failed — ' + e.message;
priceEl.style.color = 'var(--red)';
}
spin.style.display = 'none';
}
// ── Slippage simulation ────────────────────────────────────────
function simulateSlippage(chain, slippageTol, action) {
const failRate = getChain(chain).failRate;
if (Math.random() < failRate) {
return { success: false, type: 'fail', msg: action + ' failed — transaction rejected due to slippage on ' + getChain(chain).label + '. Retry with higher tolerance?' };
}
if (Math.random() < 0.30) {
const impact = Math.random() * (slippageTol / 100);
return { success: true, type: 'impact', impact, msg: action + ' executed with ' + (impact * 100).toFixed(1) + '% slippage impact on ' + getChain(chain).label };
}
return { success: true, type: 'clean', impact: 0, msg: action + ' executed cleanly on ' + getChain(chain).label };
}
// ── Enter position ─────────────────────────────────────────────
async function fetchAndEnter() {
if (!account) { toast('Initialize account first'); return; }
const addr = document.getElementById('entry-address').value.trim();
const chain = document.getElementById('entry-chain').value;
const symbol = document.getElementById('entry-symbol').value.trim().toUpperCase() || 'TOKEN';
const size = parseFloat(document.getElementById('entry-size').value) || 0;
const slip = parseInt(document.getElementById('entry-slippage').value) || 3;
if (!addr) { toast('Enter a pool address'); return; }
if (!size) { toast('Enter a position size'); return; }
if (positions.length >= account.maxPositions) { toast('Max positions reached (' + account.maxPositions + ')'); return; }
const reserved = account.balance * (account.reservePct / 100);
const available = Math.max(0, account.balance - reserved);
if (size > available) { toast('Insufficient available balance. Available: ' + fUsd(available)); return; }
const chainMeta = getChain(chain);
const gas = chainMeta.gas;
let price, resolvedPoolAddress = addr;
try {
document.getElementById('fetch-btn').disabled = true;
document.getElementById('fetch-btn').textContent = 'FETCHING...';
const resolved = await resolveAddress(chain, addr);
resolvedPoolAddress = resolved.poolAddress;
if (resolved.isToken) {
remiLog_add('Token address resolved for ' + symbol + ' — ' + resolved.poolCount + ' pool(s) on ' + chainMeta.label + '. Using highest liquidity pool on ' + resolved.dex + ' (' + fUsd(resolved.liq) + ' liq)', 'info');
document.getElementById('entry-address').value = resolvedPoolAddress;
}
const data = await getPriceAndLiq(chain, resolvedPoolAddress);
price = data.price;
} catch(e) {
remiLog_add('Address resolution failed for ' + symbol + ' on ' + chainMeta.label + ' — ' + e.message, 'err');
toast('Fetch failed — ' + e.message);
document.getElementById('fetch-btn').disabled = false;
document.getElementById('fetch-btn').innerHTML = '▶ FETCH PRICE & ENTER';
return;
}
// Tier 2 warning in log
if (chainMeta.tier === 2) {
remiLog_add('WARNING: ' + chainMeta.label + ' is a Tier 2 chain — no GoPlus security data available. Verify token manually before trading.', 'warn');
}
let entryPrice = price;
let slip_result;
let attempts = 0;
const maxAttempts = 3;
const slipTolerances = [slip, slip * 2, slip * 3];
while (attempts < maxAttempts) {
slip_result = simulateSlippage(chain, slipTolerances[attempts], 'Entry');
if (slip_result.success) {
entryPrice = price * (1 + slip_result.impact);
break;
}
attempts++;
const extraGas = gas * 0.5;
account.balance -= extraGas;
remiLog_add('Entry attempt ' + attempts + ' failed for ' + symbol + ' — retry ' + attempts + '/' + maxAttempts + '. Extra gas: ' + fUsd(extraGas), 'warn');
if (attempts >= maxAttempts) {
remiLog_add('Entry abandoned for ' + symbol + ' after ' + maxAttempts + ' failed attempts.', 'err');
toast('Entry failed after ' + maxAttempts + ' attempts — slippage too high');
save();
document.getElementById('fetch-btn').disabled = false;
document.getElementById('fetch-btn').innerHTML = '▶ FETCH PRICE & ENTER';
return;
}
}
account.balance -= gas;
account.balance -= size;
const pos = {
id: Date.now(),
chain,
symbol,
poolAddress: resolvedPoolAddress,
entryPrice: entryPrice,
currentPrice: entryPrice,
peakPrice: entryPrice,
size,
remainingPct: 100,
remainingValue: size,
gas,
enteredAt: Date.now(),
sl1: { pct: parseFloat(document.getElementById('sl1-pct').value)||15, sell: parseFloat(document.getElementById('sl1-sell').value)||50, on: document.getElementById('sl1-on').value==='1', triggered: false },
sl2: { pct: parseFloat(document.getElementById('sl2-pct').value)||30, sell: 100, on: document.getElementById('sl2-on').value==='1', triggered: false },
tp1: { pct: parseFloat(document.getElementById('tp1-pct').value)||25, sell: parseFloat(document.getElementById('tp1-sell').value)||25, on: document.getElementById('tp1-on').value==='1', triggered: false },
tp2: { pct: parseFloat(document.getElementById('tp2-pct').value)||50, sell: parseFloat(document.getElementById('tp2-sell').value)||25, on: document.getElementById('tp2-on').value==='1', triggered: false },
tp3: { pct: parseFloat(document.getElementById('tp3-pct').value)||100, sell: parseFloat(document.getElementById('tp3-sell').value)||25, on: document.getElementById('tp3-on').value==='1', triggered: false },
trail: { pct: parseFloat(document.getElementById('trail-pct').value)||15, on: document.getElementById('trail-on').value==='1', triggered: false, activatePct: parseFloat(document.getElementById('trail-activate-pct').value)||0, activateMins: parseFloat(document.getElementById('trail-activate-mins').value)||0 },
liqFloor: parseFloat(document.getElementById('entry-liq-floor').value)||0,
entryReason: document.getElementById('entry-reason').value.trim() || 'No reason recorded',
maxHoldHours: account.maxHoldHours,
tier: chainMeta.tier,
};
positions.push(pos);
save();
remiLog_add(slip_result.msg, slip_result.type === 'clean' ? 'ok' : 'warn');
remiLog_add('Opened ' + symbol + ' on ' + chainMeta.label + ' [Tier ' + chainMeta.tier + '] | Entry: ' + fPrice(entryPrice) + ' | Size: ' + fUsd(size) + ' | Gas: ' + fUsd(gas), 'ok');
renderAll();
toast('Position opened: ' + symbol);
document.getElementById('fetch-btn').disabled = false;
document.getElementById('fetch-btn').innerHTML = '▶ FETCH PRICE & ENTER';
document.getElementById('entry-address').value = '';
document.getElementById('entry-symbol').value = '';
document.getElementById('entry-reason').value = '';
document.getElementById('fetched-price').textContent = '';
}
// ── Price refresh loop ─────────────────────────────────────────
function startRefresh() {
stopRefresh();
refreshCountdown = 60;
updateCountdown();
refreshTimer = setInterval(async () => {
refreshCountdown--;
updateCountdown();
if (refreshCountdown <= 0) {
refreshCountdown = 60;
await refreshPrices();
}
}, 1000);
}
function stopRefresh() {
if (refreshTimer) clearInterval(refreshTimer);
document.getElementById('pos-refresh-countdown').textContent = '';
}
function updateCountdown() {
const el = document.getElementById('pos-refresh-countdown');
el.textContent = positions.length > 0 ? 'Price refresh in ' + refreshCountdown + 's' : '';
}
async function refreshPrices() {
if (!positions.length) return;
for (let pos of positions) {
try {
const { price, liq } = await getPriceAndLiq(pos.chain, pos.poolAddress);
pos.currentPrice = price;
pos.currentLiq = liq;
if (price > pos.peakPrice) pos.peakPrice = price;
if (pos.liqFloor && pos.liqFloor > 0 && liq < pos.liqFloor && !pos.liqExitTriggered) {
pos.liqExitTriggered = true;
const gas = getChain(pos.chain).gas;
closePartial(pos, 100, price, 'EMERGENCY EXIT — Liquidity on ' + pos.symbol + ' dropped to ' + fUsd(liq) + ' (floor: ' + fUsd(pos.liqFloor) + '). WARNING: In real trading this exit may have failed. Classic rug pull pattern.', gas);
remiLog_add('LIQUIDITY COLLAPSE on ' + pos.symbol + ' — ' + fUsd(liq) + ' remaining. Emergency exit triggered.', 'err');
continue;
}
checkLevels(pos);
} catch(e) {
remiLog_add('Price refresh failed for ' + pos.symbol + ' — ' + e.message, 'warn');
}
}
checkHoldTimers();
save();
renderAll();
}
// ── Level checks ───────────────────────────────────────────────
function checkLevels(pos) {
if (pos.remainingPct <= 0) return;
const pct = ((pos.currentPrice - pos.entryPrice) / pos.entryPrice) * 100;
const gas = getChain(pos.chain).gas;
if (pos.sl2.on && !pos.sl2.triggered && pct <= -pos.sl2.pct) {
const slip = simulateSlippage(pos.chain, 5, 'Stop Loss L2');
const exitPct = slip.success ? pos.currentPrice * (1 - slip.impact) : pos.currentPrice * 0.97;
closePartial(pos, 100, exitPct, 'Stop Loss Level 2 on ' + pos.symbol + ' — ' + pos.sl2.pct + '% loss. Full exit.' + (slip.type !== 'clean' ? ' ' + slip.msg : ''), gas);
pos.sl2.triggered = true;
return;
}
if (pos.sl1.on && !pos.sl1.triggered && pct <= -pos.sl1.pct) {
const slip = simulateSlippage(pos.chain, 3, 'Stop Loss L1');
const exitPrice = slip.success ? pos.currentPrice * (1 - slip.impact) : pos.currentPrice * 0.98;
closePartial(pos, pos.sl1.sell, exitPrice, 'Stop Loss Level 1 on ' + pos.symbol + ' — ' + pos.sl1.pct + '% loss. Sold ' + pos.sl1.sell + '%.' + (slip.type !== 'clean' ? ' ' + slip.msg : ''), gas * 0.5);
pos.sl1.triggered = true;
}
[
{ cfg: pos.tp1, label: 'Take Profit 1' },
{ cfg: pos.tp2, label: 'Take Profit 2' },
{ cfg: pos.tp3, label: 'Take Profit 3' },
].forEach(({ cfg, label }) => {
if (cfg.on && !cfg.triggered && pct >= cfg.pct) {
const slip = simulateSlippage(pos.chain, 2, label);
const exitPrice = slip.success ? pos.currentPrice * (1 - slip.impact) : pos.currentPrice * 0.99;
closePartial(pos, cfg.sell, exitPrice, label + ' on ' + pos.symbol + ' — ' + cfg.pct + '% target hit. Sold ' + cfg.sell + '%.' + (slip.type !== 'clean' ? ' ' + slip.msg : ''), gas * 0.5);
cfg.triggered = true;
}
});
if (pos.trail.on && !pos.trail.triggered && pos.remainingPct > 0) {
const ageMinutes = (Date.now() - pos.enteredAt) / 60000;
const gainFromEntry = ((pos.currentPrice - pos.entryPrice) / pos.entryPrice) * 100;
const activatePct = pos.trail.activatePct || 0;
const activateMins = pos.trail.activateMins || 0;
const pctCondition = activatePct === 0 || gainFromEntry >= activatePct;
const timeCondition = activateMins === 0 || ageMinutes >= activateMins;
const isActive = pctCondition && timeCondition;
const dropFromPeak = ((pos.peakPrice - pos.currentPrice) / pos.peakPrice) * 100;
if (isActive && dropFromPeak >= pos.trail.pct) {
const slip = simulateSlippage(pos.chain, 3, 'Trailing Stop');
const exitPrice = slip.success ? pos.currentPrice * (1 - slip.impact) : pos.currentPrice * 0.98;
closePartial(pos, 100, exitPrice, 'Trailing stop on ' + pos.symbol + ' — dropped ' + dropFromPeak.toFixed(1) + '% from peak ' + fPrice(pos.peakPrice) + '.' + (slip.type !== 'clean' ? ' ' + slip.msg : ''), gas * 0.5);
pos.trail.triggered = true;
} else if (!isActive && dropFromPeak >= pos.trail.pct) {
remiLog_add('Trailing stop on ' + pos.symbol + ' not yet active — ' + (!pctCondition ? 'waiting for +' + activatePct + '% gain' : 'waiting for ' + activateMins + ' min hold'), 'info');
}
}
}
function checkHoldTimers() {
positions.forEach(pos => {
if (!pos.maxHoldHours || pos.maxHoldHours === 0) return;
const ageHours = (Date.now() - pos.enteredAt) / 3600000;
if (ageHours >= pos.maxHoldHours && pos.remainingPct > 0) {
const gas = getChain(pos.chain).gas;
closePartial(pos, 100, pos.currentPrice, 'Maximum hold time (' + pos.maxHoldHours + 'h) reached on ' + pos.symbol + '. Closed at market.', gas * 0.5);
}
});
}
function closePartial(pos, sellPct, exitPrice, reason, gasCost) {
const sellFraction = sellPct / 100;
const sellValue = pos.remainingValue * sellFraction;
const priceRatio = exitPrice / pos.entryPrice;
const exitValue = sellValue * priceRatio;
const pnl = exitValue - sellValue - gasCost;
account.balance += Math.max(0, exitValue - gasCost);
pos.remainingPct -= sellPct * (pos.remainingPct / 100);
pos.remainingValue -= sellValue;
closed.unshift({
id: Date.now(),
date: new Date().toLocaleDateString(),
chain: pos.chain,
symbol: pos.symbol,
entryPrice: pos.entryPrice,
exitPrice,
size: sellValue,
gas: gasCost,
pnl,
pnlPct: (pnl / sellValue) * 100,
reason,
entryReason: pos.entryReason || 'No reason recorded',
durationMs: Date.now() - pos.enteredAt,
outcome: pnl >= 0 ? 'win' : 'loss',
tier: pos.tier || 1,
});
remiLog_add(reason, pnl >= 0 ? 'ok' : 'err');
if (pos.remainingPct <= 0.5) positions = positions.filter(p => p.id !== pos.id);
}
// ── Manual close ───────────────────────────────────────────────
function manualClose(posId) {
const pos = positions.find(p => p.id === posId);
if (!pos) return;
if (!confirm('Close entire position in ' + pos.symbol + '?')) return;
const gas = getChain(pos.chain).gas;
closePartial(pos, 100, pos.currentPrice, 'Manually closed by trader at ' + fPrice(pos.currentPrice), gas);
save();
renderAll();
toast('Position closed: ' + pos.symbol);
}
// ── Override modal ─────────────────────────────────────────────
function openOverride(posId) {
const pos = positions.find(p => p.id === posId);
if (!pos) return;
document.getElementById('override-pos-id').value = posId;
document.getElementById('ov-sl1-pct').value = pos.sl1.pct;
document.getElementById('ov-sl1-sell').value = pos.sl1.sell;
document.getElementById('ov-sl2-pct').value = pos.sl2.pct;
document.getElementById('ov-sl2-on').value = pos.sl2.on ? '1' : '0';
document.getElementById('ov-tp1-pct').value = pos.tp1.pct;
document.getElementById('ov-tp1-sell').value = pos.tp1.sell;
document.getElementById('ov-tp2-pct').value = pos.tp2.pct;
document.getElementById('ov-tp2-sell').value = pos.tp2.sell;
document.getElementById('ov-tp3-pct').value = pos.tp3.pct;
document.getElementById('ov-tp3-sell').value = pos.tp3.sell;
document.getElementById('ov-trail-pct').value = pos.trail.pct;
document.getElementById('ov-trail-on').value = pos.trail.on ? '1' : '0';
document.getElementById('ov-trail-activate-pct').value = pos.trail.activatePct || 0;
document.getElementById('ov-trail-activate-mins').value = pos.trail.activateMins || 0;
document.getElementById('override-modal').classList.add('show');
}
function closeOverride() { document.getElementById('override-modal').classList.remove('show'); }
function saveOverride() {
const posId = parseInt(document.getElementById('override-pos-id').value);
const pos = positions.find(p => p.id === posId);
if (!pos) return;
pos.sl1.pct = parseFloat(document.getElementById('ov-sl1-pct').value) || pos.sl1.pct;
pos.sl1.sell = parseFloat(document.getElementById('ov-sl1-sell').value) || pos.sl1.sell;
pos.sl2.pct = parseFloat(document.getElementById('ov-sl2-pct').value) || pos.sl2.pct;
pos.sl2.on = document.getElementById('ov-sl2-on').value === '1';
pos.tp1.pct = parseFloat(document.getElementById('ov-tp1-pct').value) || pos.tp1.pct;
pos.tp1.sell = parseFloat(document.getElementById('ov-tp1-sell').value) || pos.tp1.sell;
pos.tp2.pct = parseFloat(document.getElementById('ov-tp2-pct').value) || pos.tp2.pct;
pos.tp2.sell = parseFloat(document.getElementById('ov-tp2-sell').value) || pos.tp2.sell;
pos.tp3.pct = parseFloat(document.getElementById('ov-tp3-pct').value) || pos.tp3.pct;
pos.tp3.sell = parseFloat(document.getElementById('ov-tp3-sell').value) || pos.tp3.sell;
pos.trail.pct = parseFloat(document.getElementById('ov-trail-pct').value) || pos.trail.pct;
pos.trail.on = document.getElementById('ov-trail-on').value === '1';
pos.trail.activatePct = parseFloat(document.getElementById('ov-trail-activate-pct').value)|| 0;
pos.trail.activateMins = parseFloat(document.getElementById('ov-trail-activate-mins').value)|| 0;
save();
closeOverride();
remiLog_add('Position levels overridden for ' + pos.symbol, 'info');
renderAll();
toast('Levels updated for ' + pos.symbol);
}
// ── Remi log ───────────────────────────────────────────────────
function remiLog_add(msg, type='info') {
remiLog.unshift({ time: new Date().toLocaleTimeString(), msg, type });
if (remiLog.length > 100) remiLog.pop();
renderRemiLog();
}
function renderRemiLog() {
const body = document.getElementById('remi-log-body');
if (!remiLog.length) { body.innerHTML = '<div class="log-entry"><span class="log-info">Remi is watching the market...</span></div>'; return; }
body.innerHTML = remiLog.slice(0,20).map(e =>
`<div class="log-entry"><span class="log-time">${e.time}</span><span class="log-${e.type}">${e.msg}</span></div>`
).join('');
}
// ── Render ─────────────────────────────────────────────────────
function renderAll() { renderPortfolio(); renderPositions(); renderClosed(); renderRemiLog(); }
function renderPortfolio() {
if (!account) {
['stat-balance','stat-available','stat-invested','stat-reserved','stat-pnl','stat-trades','stat-winrate'].forEach(id => document.getElementById(id).textContent = '—');
return;
}
const reserved = account.balance * (account.reservePct / 100);
const available = Math.max(0, account.balance - reserved);
const openPnl = positions.reduce((s,p) => s + (p.remainingValue * ((p.currentPrice - p.entryPrice) / p.entryPrice)), 0);
const wins = closed.filter(t => t.outcome === 'win').length;
const total = wins + closed.filter(t => t.outcome === 'loss').length;
document.getElementById('stat-balance').textContent = fUsd(account.balance);
document.getElementById('stat-available').textContent = fUsd(available);
document.getElementById('stat-invested').textContent = fUsd(positions.reduce((s,p) => s + p.remainingValue, 0));
document.getElementById('stat-reserved').textContent = fUsd(reserved);
const pnlEl = document.getElementById('stat-pnl');
pnlEl.textContent = (openPnl >= 0 ? '+' : '') + fUsd(openPnl);
pnlEl.style.color = openPnl > 0 ? 'var(--green)' : openPnl < 0 ? 'var(--red)' : 'var(--text)';
document.getElementById('stat-trades').textContent = closed.length;
document.getElementById('stat-winrate').textContent = total ? ((wins/total)*100).toFixed(1)+'%' : '—';
}
function getChainTag(chainKey) {
const meta = getChain(chainKey);
return `<span class="chain-tag ${meta.tag}">${meta.label}</span>`;
}
function renderPositions() {
const body = document.getElementById('positions-body');
if (!positions.length) {
body.innerHTML = '<tr><td colspan="18" class="empty-msg">No open positions</td></tr>';
return;
}
body.innerHTML = positions.map(pos => {
const pct = ((pos.currentPrice - pos.entryPrice) / pos.entryPrice) * 100;
const pnlVal = pos.remainingValue * (pct / 100);
const pnlCls = pct > 0 ? 'pos-up' : pct < 0 ? 'pos-dn' : 'pos-neu';
const ageH = ((Date.now() - pos.enteredAt) / 3600000).toFixed(1);
const fmtLvl = (cfg, triggered) => cfg.on ? (triggered ? '<span style="color:var(--green-hi)">✓</span>' : cfg.pct + '%') : '<span style="color:var(--text-dim)">off</span>';