Spaces:
Running

File size: 12,095 Bytes
fab03ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class CustomBotControls extends HTMLElement {
    constructor() {
        super();
        this.attachShadow({ mode: 'open' });
        this.isRunning = false;
    }

    connectedCallback() {
        this.render();
        this.attachEventListeners();
    }

    render() {
        this.shadowRoot.innerHTML = `
            <style>
                :host {
                    display: block;
                }
                .panel {
                    background: rgba(30, 41, 59, 0.6);
                    backdrop-filter: blur(12px);
                    border: 1px solid rgba(255, 255, 255, 0.05);
                    border-radius: 1rem;
                    padding: 1.5rem;
                }
                .control-group {
                    margin-bottom: 1rem;
                }
                label {
                    display: block;
                    font-size: 0.875rem;
                    color: #94a3b8;
                    margin-bottom: 0.5rem;
                    font-weight: 500;
                }
                select, input {
                    width: 100%;
                    background: rgba(15, 23, 42, 0.8);
                    border: 1px solid #334155;
                    color: white;
                    padding: 0.5rem 0.75rem;
                    border-radius: 0.5rem;
                    font-size: 0.875rem;
                    transition: all 0.2s;
                }
                select:focus, input:focus {
                    outline: none;
                    border-color: #6366f1;
                    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
                }
                .toggle-btn {
                    width: 100%;
                    padding: 0.75rem;
                    border-radius: 0.75rem;
                    font-weight: 600;
                    font-size: 0.875rem;
                    transition: all 0.2s;
                    cursor: pointer;
                    border: none;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    gap: 0.5rem;
                }
                .start-btn {
                    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
                    color: white;
                    box-shadow: 0 4px 6px -1px rgba(16, 185, 129, 0.2);
                }
                .start-btn:hover {
                    transform: translateY(-1px);
                    box-shadow: 0 6px 8px -1px rgba(16, 185, 129, 0.3);
                }
                .stop-btn {
                    background: linear-gradient(135deg, #f43f5e 0%, #e11d48 100%);
                    color: white;
                    box-shadow: 0 4px 6px -1px rgba(244, 63, 94, 0.2);
                }
                .stop-btn:hover {
                    transform: translateY(-1px);
                    box-shadow: 0 6px 8px -1px rgba(244, 63, 94, 0.3);
                }
                .status-badge {
                    display: inline-flex;
                    align-items: center;
                    gap: 0.5rem;
                    padding: 0.25rem 0.75rem;
                    border-radius: 9999px;
                    font-size: 0.75rem;
                    font-weight: 600;
                    background: rgba(244, 63, 94, 0.1);
                    color: #f43f5e;
                    border: 1px solid rgba(244, 63, 94, 0.2);
                }
                .status-badge.running {
                    background: rgba(16, 185, 129, 0.1);
                    color: #10b981;
                    border-color: rgba(16, 185, 129, 0.2);
                }
                .strategy-info {
                    font-size: 0.75rem;
                    color: #64748b;
                    margin-top: 0.25rem;
                    font-style: italic;
                }
            </style>
            <div class="panel">
                <div class="flex items-center justify-between mb-4">
                    <h3 class="text-lg font-bold text-white flex items-center gap-2">
                        <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="text-primary-400">
                            <rect x="2" y="3" width="20" height="14" rx="2" ry="2"></rect>
                            <line x1="8" y1="21" x2="16" y2="21"></line>
                            <line x1="12" y1="17" x2="12" y2="21"></line>
                        </svg>
                        Bot Configuration
                    </h3>
                    <span id="bot-status" class="status-badge">Stopped</span>
                </div>
                <div class="control-group">
                    <label>Trading Strategy</label>
                    <select id="strategy">
                        <option value="martingale">Martingale Recovery</option>
                        <option value="martingale-0.5">Martingale 0.5 Recovery</option>
                        <option value="trend">Trend Following</option>
                        <option value="reversal">Reversal Trading</option>
                        <option value="random">Random Walk</option>
                    </select>
                    <div class="strategy-info" id="strategy-desc">Double stake after loss to recover previous losses</div>
                </div>
<div class="grid grid-cols-2 gap-3">
                    <div class="control-group">
                        <label>Base Stake ($)</label>
                        <input type="number" id="stake" value="10" min="1" step="1">
                    </div>
                    <div class="control-group">
                        <label>Max Stake ($)</label>
                        <input type="number" id="max-stake" value="1000" min="10" step="10">
                    </div>
                </div>

                <div class="grid grid-cols-2 gap-3">
                    <div class="control-group">
                        <label>Duration (min)</label>
                        <select id="duration">
                            <option value="1">1 Minute</option>
                            <option value="5" selected>5 Minutes</option>
                            <option value="15">15 Minutes</option>
                            <option value="60">1 Hour</option>
                        </select>
                    </div>
                    <div class="control-group">
                        <label>Index</label>
                        <select id="index">
                            <option value="R_10">Volatility 10</option>
                            <option value="R_25">Volatility 25</option>
                            <option value="R_50">Volatility 50</option>
                            <option value="R_75" selected>Volatility 75</option>
                            <option value="R_100">Volatility 100</option>
                        </select>
                    </div>
                </div>

                <div class="grid grid-cols-2 gap-3 mb-4">
                    <div class="control-group">
                        <label>Take Profit ($)</label>
                        <input type="number" id="target-profit" value="100" min="10">
                    </div>
                    <div class="control-group">
                        <label>Stop Loss ($)</label>
                        <input type="number" id="stop-loss" value="500" min="10">
                    </div>
                </div>

                <button id="toggle-btn" class="toggle-btn start-btn">
                    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                        <polygon points="5 3 19 12 5 21 5 3"></polygon>
                    </svg>
                    Start Bot
                </button>

                <div class="mt-4 p-3 rounded-lg bg-slate-800/50 border border-slate-700">
                    <div class="flex items-center gap-2 text-xs text-slate-400">
                        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="text-amber-400">
                            <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
                            <line x1="12" y1="9" x2="12" y2="13"></line>
                            <line x1="12" y1="17" x2="12.01" y2="17"></line>
                        </svg>
                        <span>Risk Warning: Trading involves significant risk. Past performance does not guarantee future results.</span>
                    </div>
                </div>
            </div>
        `;
    }

    attachEventListeners() {
        const toggleBtn = this.shadowRoot.getElementById('toggle-btn');
        const strategySelect = this.shadowRoot.getElementById('strategy');
        const strategyDesc = this.shadowRoot.getElementById('strategy-desc');
        
        toggleBtn.addEventListener('click', () => {
            this.isRunning = !this.isRunning;
            this.updateButtonState();
            
            // Dispatch event to main script
            const event = new CustomEvent(this.isRunning ? 'start-bot' : 'stop-bot', {
                bubbles: true,
                composed: true
            });
            this.dispatchEvent(event);
            
            // Update config
            this.dispatchConfigChange();
        });
        strategySelect.addEventListener('change', (e) => {
            const descriptions = {
                martingale: 'Double stake after loss to recover previous losses',
                'martingale-0.5': 'Increase stake by 50% after loss for gradual recovery',
                trend: 'Follow the market trend direction',
                reversal: 'Trade against the current trend',
                random: 'Random entry points for testing'
            };
            strategyDesc.textContent = descriptions[e.target.value];
            this.dispatchConfigChange();
        });
// Listen for all input changes
        this.shadowRoot.querySelectorAll('input, select').forEach(input => {
            input.addEventListener('change', () => this.dispatchConfigChange());
        });
    }

    updateButtonState() {
        const btn = this.shadowRoot.getElementById('toggle-btn');
        const status = this.shadowRoot.getElementById('bot-status');
        
        if (this.isRunning) {
            btn.className = 'toggle-btn stop-btn';
            btn.innerHTML = `
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
                </svg>
                Stop Bot
            `;
            status.textContent = 'Running';
            status.className = 'status-badge running';
        } else {
            btn.className = 'toggle-btn start-btn';
            btn.innerHTML = `
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                    <polygon points="5 3 19 12 5 21 5 3"></polygon>
                </svg>
                Start Bot
            `;
            status.textContent = 'Stopped';
            status.className = 'status-badge';
        }
    }

    dispatchConfigChange() {
        const config = {
            strategy: this.shadowRoot.getElementById('strategy').value,
            stake: this.shadowRoot.getElementById('stake').value,
            maxStake: this.shadowRoot.getElementById('max-stake').value,
            duration: this.shadowRoot.getElementById('duration').value,
            targetProfit: this.shadowRoot.getElementById('target-profit').value,
            stopLoss: this.shadowRoot.getElementById('stop-loss').value
        };
        
        const event = new CustomEvent('config-change', {
            detail: config,
            bubbles: true,
            composed: true
        });
        this.dispatchEvent(event);
    }
}

customElements.define('custom-bot-controls', CustomBotControls);