Spaces:
Running
Running
Download script.js from jfand/metatrade-mirror-master: direct link, hf CLI and curl.
- Browser
- Download file 7.18 kB
-
https://huggingface.co/spaces/jfand/metatrade-mirror-master/resolve/main/script.js
- Command line
-
hf download hf://spaces/jfand/metatrade-mirror-master/script.js
-
curl -L -o script.js https://huggingface.co/spaces/jfand/metatrade-mirror-master/resolve/main/script.js
7.18 kB
| // 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(); | |
| }); |