feat(ui): strategy config form and backend endpoint
This commit is contained in:
@@ -121,13 +121,50 @@ function setupEventListeners() {
|
||||
}
|
||||
});
|
||||
|
||||
// Form submissions
|
||||
// Strategy config form submission (real backend call)
|
||||
const strategyForm = document.getElementById('strategy-config-form');
|
||||
if (strategyForm) {
|
||||
strategyForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const payload = {
|
||||
name: document.getElementById('strategy-name').value,
|
||||
type: document.getElementById('strategy-type').value,
|
||||
initialCapital: Number(document.getElementById('initial-capital').value),
|
||||
entryLookback: Number(document.getElementById('entry-lookback').value),
|
||||
exitLookback: Number(document.getElementById('exit-lookback').value),
|
||||
riskPerTrade: Number(document.getElementById('risk-per-trade').value),
|
||||
maxPositions: Number(document.getElementById('max-positions').value),
|
||||
notes: document.getElementById('strategy-notes').value,
|
||||
};
|
||||
fetch('/api/strategy-config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.status === 'ok') {
|
||||
showToast('Strategy configuration saved', 'success');
|
||||
} else {
|
||||
showToast('Failed to save configuration', 'danger');
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Error saving strategy config', err);
|
||||
showToast('Error saving configuration', 'danger');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Generic form submissions (fallback)
|
||||
const forms = document.querySelectorAll('form');
|
||||
forms.forEach(form => {
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
showToast('Settings saved successfully', 'success');
|
||||
});
|
||||
if (form.id !== 'strategy-config-form') {
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
showToast('Settings saved successfully', 'success');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Toggle buttons
|
||||
|
||||
Reference in New Issue
Block a user