Spaces:
Running
Running
File size: 7,182 Bytes
ffcb172 | 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 | // Trade Copier Application
class TradeCopierApp {
constructor() {
this.config = {
status: "running",
pollInterval: 2.0,
accounts: [],
positions: [],
stats: {}
};
this.init();
}
async init() {
await this.loadConfig();
this.renderStats();
this.setupEventListeners();
feather.replace();
}
async loadConfig() {
try {
// In a real app, this would fetch from an API
this.config = {
status: "running",
pollInterval: 2.0,
accounts: [
{
name: "Gold Account",
login: 12345678,
server: "MetaQuotes-Demo",
status: "connected",
multiplier: 1.5,
reverse: true,
maxLotPerTrade: 5.00,
maxLotPerSymbol: 10.00,
allowedSymbols: ["EURUSD", "GBPUSD", "XAUUSD", "US30"],
blockedSymbols: ["BTCUSD", "ETHUSD"]
},
{
name: "Silver Account",
login: 87654321,
server: "ICMarkets-Live",
status: "connected",
multiplier: 1.0,
reverse: false,
maxLotPerTrade: 2.00,
maxLotPerSymbol: 5.00,
allowedSymbols: null,
blockedSymbols: null
},
{
name: "Bronze Account",
login: 56781234,
server: "Pepperstone-Demo",
status: "disconnected",
multiplier: 0.5,
reverse: false,
maxLotPerTrade: 1.00,
maxLotPerSymbol: 2.00,
allowedSymbols: ["EURUSD", "GBPUSD"],
blockedSymbols: ["XAUUSD", "US30"]
}
],
positions: [
{
sourceTicket: 123456,
symbol: "EURUSD",
type: "buy",
volume: 1.50,
sl: 1.0850,
tp: 1.0950,
target: "Gold Account",
status: "active",
time: "10:23:45"
},
{
sourceTicket: 123457,
symbol: "GBPUSD",
type: "sell",
volume: 0.75,
sl: 1.2450,
tp: 1.2350,
target: "Silver Account",
status: "active",
time: "10:45:12"
},
{
sourceTicket: 123458,
symbol: "XAUUSD",
type: "buy",
volume: 0.25,
sl: 1950.00,
tp: 1980.00,
target: "Bronze Account",
status: "pending",
time: "11:03:27"
}
],
stats: {
targetAccounts: 3,
copiedTrades: 24,
todaysPnl: 1245.67,
avgLatency: 42
}
};
} catch (error) {
console.error("Failed to load config:", error);
}
}
renderStats() {
document.querySelectorAll('[data-stat="targetAccounts"]').forEach(el => {
el.textContent = this.config.stats.targetAccounts;
});
document.querySelectorAll('[data-stat="copiedTrades"]').forEach(el => {
el.textContent = this.config.stats.copiedTrades;
});
document.querySelectorAll('[data-stat="todaysPnl"]').forEach(el => {
el.textContent = `$${this.config.stats.todaysPnl.toFixed(2)}`;
});
document.querySelectorAll('[data-stat="avgLatency"]').forEach(el => {
el.textContent = `${this.config.stats.avgLatency}ms`;
});
}
setupEventListeners() {
// Start/Stop button
document.getElementById('startStopBtn').addEventListener('click', () => this.toggleCopierStatus());
// Refresh button
document.querySelector('[data-action="refresh"]').addEventListener('click', () => this.refreshData());
// Modal controls
document.querySelectorAll('[data-modal-close]').forEach(btn => {
btn.addEventListener('click', (e) => {
const modalId = e.target.getAttribute('data-modal-close');
this.closeModal(modalId);
});
});
}
toggleCopierStatus() {
const btn = document.getElementById('startStopBtn');
if (this.config.status === 'running') {
this.config.status = 'stopped';
btn.innerHTML = '<i data-feather="power" class="mr-2"></i><span>Start Copier</span>';
btn.classList.remove('bg-fuchsia-600', 'hover:bg-fuchsia-700');
btn.classList.add('bg-green-600', 'hover:bg-green-700');
} else {
this.config.status = 'running';
btn.innerHTML = '<i data-feather="power" class="mr-2"></i><span>Stop Copier</span>';
btn.classList.remove('bg-green-600', 'hover:bg-green-700');
btn.classList.add('bg-fuchsia-600', 'hover:bg-fuchsia-700');
}
feather.replace();
}
openModal(modalId) {
document.getElementById(modalId).classList.remove('hidden');
}
closeModal(modalId) {
document.getElementById(modalId).classList.add('hidden');
}
async refreshData() {
try {
await this.loadConfig();
this.renderStats();
// Show notification
this.showToast('Data refreshed successfully', 'success');
} catch (error) {
this.showToast('Failed to refresh data', 'error');
console.error("Refresh error:", error);
}
}
showToast(message, type = 'info') {
const toast = document.createElement('div');
toast.className = `fixed top-4 right-4 px-4 py-2 rounded-md shadow-lg text-white ${
type === 'success' ? 'bg-green-600' :
type === 'error' ? 'bg-red-600' : 'bg-blue-600'
}`;
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
setTimeout(() => toast.remove(), 300);
}, 3000);
}
}
// Initialize the app when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
window.tradeCopierApp = new TradeCopierApp();
}); |