Spaces:
Running
Running
File size: 8,397 Bytes
9daec70 a7c51d1 0949511 9daec70 0949511 324d1d0 a47b139 9daec70 0949511 9daec70 ee3d880 13edb8d ee3d880 13edb8d ee3d880 cc6b4fc 0949511 cc6b4fc 0949511 cc6b4fc 0949511 cc6b4fc 0949511 cc6b4fc 0949511 cc6b4fc aa8bc9a 9daec70 ee3d880 9daec70 |
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 |
// Trading interface functionality
document.addEventListener('DOMContentLoaded', () => {
// Initialize tooltips
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
tooltipTriggerList.forEach(tooltipTriggerEl => {
new bootstrap.Tooltip(tooltipTriggerEl);
});
// Tab functionality
const tabButtons = document.querySelectorAll('.flex.border-b.border-gray-700 > button, .analysis-tabs > button');
tabButtons.forEach((button, index) => {
button.addEventListener('click', () => {
// Remove active class from all buttons
tabButtons.forEach(btn => {
btn.classList.remove('text-blue-400', 'border-b-2', 'border-blue-400');
btn.classList.add('text-gray-400');
});
// Add active class to clicked button
button.classList.add('text-blue-400', 'border-b-2', 'border-blue-400');
button.classList.remove('text-gray-400');
// Hide all tab contents
document.querySelectorAll('[data-tab-content]').forEach(tabContent => {
tabContent.classList.add('hidden');
});
// Show corresponding tab content
const tabContents = ['orders', 'positions', 'history', 'bot', 'scanner', 'indicator', 'grid'];
document.querySelector(`[data-tab-content="${tabContents[index]}"]`).classList.remove('hidden');
});
});
// Activate first tab by default
if (tabButtons.length > 0) {
tabButtons[0].click();
}
// Order form validation
const orderForm = document.querySelector('#order-form');
if (orderForm) {
orderForm.addEventListener('submit', (e) => {
e.preventDefault();
// Validate and submit order
});
}
});
// Trading Bot functionality
let trainingInterval = null;
function startTrainingBot() {
const episodes = parseInt(document.getElementById('bot-episodes').value);
let currentEpisode = 0;
// Update UI
document.getElementById('start-training').disabled = true;
document.getElementById('stop-training').disabled = false;
document.getElementById('training-status').textContent = 'Training...';
// Simulate training progress
trainingInterval = setInterval(() => {
currentEpisode++;
const progress = (currentEpisode / episodes) * 100;
// Update metrics
document.getElementById('current-episode').textContent = `${currentEpisode}/${episodes}`;
document.getElementById('avg-reward').textContent = (Math.random() * 10).toFixed(2);
document.getElementById('win-rate').textContent = `${Math.min(100, Math.floor(progress * 0.8))}%`;
// Complete training
if (currentEpisode >= episodes) {
stopTrainingBot();
document.getElementById('training-status').textContent = 'Completed';
}
}, 1000);
}
function stopTrainingBot() {
clearInterval(trainingInterval);
document.getElementById('start-training').disabled = false;
document.getElementById('stop-training').disabled = true;
document.getElementById('training-status').textContent = 'Stopped';
}
// Initialize bot controls
document.addEventListener('DOMContentLoaded', () => {
const startBtn = document.getElementById('start-training');
const stopBtn = document.getElementById('stop-training');
const startTradingBtn = document.getElementById('start-trading');
const stopTradingBtn = document.getElementById('stop-trading');
const paperModeBtn = document.getElementById('paper-mode');
const liveModeBtn = document.getElementById('live-mode');
if (startBtn) {
startBtn.addEventListener('click', startTrainingBot);
}
if (stopBtn) {
stopBtn.addEventListener('click', stopTrainingBot);
}
// Trading buttons
if (startTradingBtn) {
startTradingBtn.addEventListener('click', () => {
startTradingBtn.disabled = true;
stopTradingBtn.disabled = false;
document.getElementById('running-status').textContent = 'Yes';
document.getElementById('last-action').textContent = 'Started trading';
});
}
if (stopTradingBtn) {
stopTradingBtn.addEventListener('click', () => {
startTradingBtn.disabled = false;
stopTradingBtn.disabled = true;
document.getElementById('running-status').textContent = 'No';
document.getElementById('last-action').textContent = 'Stopped trading';
});
}
// Paper/Live toggle
if (paperModeBtn && liveModeBtn) {
paperModeBtn.addEventListener('click', () => {
paperModeBtn.classList.add('bg-gray-800', 'text-white');
paperModeBtn.classList.remove('text-gray-400');
liveModeBtn.classList.remove('bg-gray-800', 'text-white');
liveModeBtn.classList.add('text-gray-400');
});
liveModeBtn.addEventListener('click', () => {
liveModeBtn.classList.add('bg-gray-800', 'text-white');
liveModeBtn.classList.remove('text-gray-400');
paperModeBtn.classList.remove('bg-gray-800', 'text-white');
paperModeBtn.classList.add('text-gray-400');
});
}
});
// Simulate live price updates and update footer
function startLivePrices() {
const pairs = ['BTC/USDT', 'ETH/USDT', 'SOL/USDT'];
setInterval(() => {
pairs.forEach(pair => {
const change = (Math.random() * 0.2 - 0.1).toFixed(2);
const currentPrice = parseFloat(document.querySelector('.live-price')?.textContent.split(' ')[0].replace(/,/g, '') || '25432.12');
const newPrice = (currentPrice * (1 + parseFloat(change)/100)).toFixed(2);
const direction = parseFloat(change) >= 0 ? 'β²' : 'βΌ';
const colorClass = parseFloat(change) >= 0 ? 'price-up' : 'price-down';
// Update main chart price
const priceEl = document.querySelector('.live-price');
if (priceEl) {
priceEl.textContent = `${formatPrice(newPrice)} ${direction}`;
priceEl.className = `text-xs ml-1 ${parseFloat(change) >= 0 ? 'text-green-400' : 'text-red-400'}`;
}
// Update footer price
const footerPrice = document.querySelector('custom-footer')?.shadowRoot.getElementById('current-price');
const footerChange = document.querySelector('custom-footer')?.shadowRoot.getElementById('price-change');
if (footerPrice && footerChange) {
footerPrice.textContent = formatPrice(newPrice);
footerChange.textContent = `${parseFloat(change) >= 0 ? '+' : ''}${change}%`;
footerChange.className = `price-change ${colorClass}`;
}
});
}, 1000);
}
document.addEventListener('DOMContentLoaded', () => {
startLivePrices();
// Simulate bot status changes
setInterval(() => {
const botStatus = document.querySelector('custom-footer')?.shadowRoot.getElementById('bot-status');
const indicator = botStatus?.querySelector('.status-indicator');
if (botStatus && indicator) {
const isActive = Math.random() > 0.3;
if (isActive) {
botStatus.innerHTML = '<span class="status-indicator" style="background:#10b981"></span> Active';
} else {
botStatus.innerHTML = '<span class="status-indicator" style="background:#ef4444"></span> Paused';
}
}
}, 5000);
});
// Custom indicator event handling
document.addEventListener('indicator-created', (e) => {
const { fn, config } = e.detail;
console.log('Custom indicator created:', config);
// Here you would typically add the indicator to your chart
// For TradingView widget you would use:
// widget.chart().createStudy('Custom Study', false, false, [/* inputs */], (study) => {
// study.setCallback({
// onData: (data) => {
// const result = fn(data);
// if (result) {
// data.setValue(result.value);
// if (result.color) data.setLineColor(result.color);
// }
// }
// });
// });
});
// Utility functions
function formatPrice(price) {
return parseFloat(price).toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
}
function formatAmount(amount) {
return parseFloat(amount).toLocaleString('en-US', {
minimumFractionDigits: 4,
maximumFractionDigits: 4
});
} |