Spaces:
Running

volatilitybot-pro / components /bot-controls.js
Fraqim's picture
Add martingale 0.5 incase of a loss to recover
fab03ee verified
Raw History Blame Contribute Delete
12.1 kB
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);