cleanup and fixed initial capital / commision / splippage

This commit is contained in:
Boki 2025-07-03 19:39:19 -04:00
parent 70da2c68e5
commit d14380d740
19 changed files with 1344 additions and 33 deletions

View file

@ -0,0 +1,69 @@
import { createContainer } from './src/simple-container';
import fetch from 'node-fetch';
async function testApiResponse() {
console.log('Testing API Response Values...\n');
// First, create the container and start the server
const container = await createContainer({
database: {
mongodb: { enabled: false, uri: '' },
postgres: { enabled: false, uri: '' },
questdb: { enabled: false, host: '', port: 0 },
dragonfly: { enabled: false }
}
});
// Run a simple backtest via API
const backtestRequest = {
strategy: 'sma-crossover',
symbols: ['AAPL'],
startDate: '2023-01-01',
endDate: '2023-02-01',
initialCapital: 100000,
config: {
commission: 0.001,
slippage: 0.0001,
dataFrequency: '1d'
}
};
try {
console.log('Sending backtest request...');
const response = await fetch('http://localhost:2003/api/backtest/run', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(backtestRequest)
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json();
console.log('\n=== API RESPONSE ===');
console.log(JSON.stringify(result, null, 2));
if (result.metrics) {
console.log('\n=== METRICS VALUES ===');
console.log(`Total Return: ${result.metrics.totalReturn}`);
console.log(`Sharpe Ratio: ${result.metrics.sharpeRatio}`);
console.log(`Max Drawdown: ${result.metrics.maxDrawdown}`);
console.log(`Win Rate: ${result.metrics.winRate}`);
console.log(`Total Trades: ${result.metrics.totalTrades}`);
}
} catch (error) {
console.error('API call failed:', error);
}
console.log('\n=== TEST COMPLETE ===');
process.exit(0);
}
testApiResponse().catch(error => {
console.error('Test failed:', error);
process.exit(1);
});