feat: auto-fill token from strategy config in backtest page
This commit is contained in:
@@ -69,6 +69,7 @@ class BotResponse(BaseModel):
|
||||
|
||||
class BacktestCreate(BaseModel):
|
||||
token: str
|
||||
token_name: Optional[str] = None
|
||||
chain: str
|
||||
timeframe: str
|
||||
start_date: str
|
||||
|
||||
@@ -72,6 +72,7 @@ export interface Backtest {
|
||||
|
||||
export interface BacktestConfig {
|
||||
token: string;
|
||||
token_name?: string;
|
||||
chain: string;
|
||||
timeframe: string;
|
||||
start_date: string;
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
import type { Backtest } from '$lib/api';
|
||||
|
||||
let botId = $derived($page.params.id);
|
||||
let token = $state('PEPE');
|
||||
let tokenName = $state('');
|
||||
let tokenAddress = $state('');
|
||||
let timeframe = $state('1h');
|
||||
let startDate = $state('');
|
||||
let endDate = $state('');
|
||||
@@ -43,6 +44,16 @@
|
||||
try {
|
||||
const bot = await api.bots.get(botId);
|
||||
setCurrentBot(bot);
|
||||
|
||||
// Extract token info from strategy config
|
||||
const strategy = bot.strategy_config;
|
||||
if (strategy) {
|
||||
// Try conditions first, then actions
|
||||
const condition = strategy.conditions?.[0];
|
||||
const action = strategy.actions?.[0];
|
||||
tokenName = condition?.token || action?.token || '';
|
||||
tokenAddress = condition?.token_address || action?.token_address || '';
|
||||
}
|
||||
} catch (e) {
|
||||
goto('/dashboard');
|
||||
}
|
||||
@@ -76,7 +87,8 @@
|
||||
|
||||
try {
|
||||
const backtest = await api.backtest.start(botId, {
|
||||
token,
|
||||
token: tokenAddress, // Use token address from strategy
|
||||
token_name: tokenName, // Also send token name for display
|
||||
timeframe,
|
||||
start_date: startDate,
|
||||
end_date: endDate
|
||||
@@ -133,16 +145,18 @@
|
||||
|
||||
<form onsubmit={(e) => { e.preventDefault(); startBacktest(); }}>
|
||||
<div class="form-row">
|
||||
<div class="field">
|
||||
<label for="token">Token</label>
|
||||
<input type="text" id="token" bind:value={token} required />
|
||||
<div class="field token-info">
|
||||
<label>Token</label>
|
||||
<div class="token-display">
|
||||
<span class="token-name">{tokenName || 'Not configured'}</span>
|
||||
{#if tokenAddress}
|
||||
<span class="token-address">{tokenAddress.slice(0, 10)}...{tokenAddress.slice(-8)}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="timeframe">Timeframe</label>
|
||||
<select id="timeframe" bind:value={timeframe}>
|
||||
|
||||
|
||||
|
||||
<option value="1h">1 hour (recommended)</option>
|
||||
<option value="4h">4 hours</option>
|
||||
<option value="1d">1 day</option>
|
||||
@@ -360,6 +374,27 @@
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.token-display {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
padding: 0.75rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border: 1px solid rgba(255, 255, 255, 0.2);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.token-name {
|
||||
font-weight: 600;
|
||||
color: #667eea;
|
||||
}
|
||||
|
||||
.token-address {
|
||||
font-size: 0.8rem;
|
||||
color: #888;
|
||||
font-family: 'Monaco', 'Menlo', monospace;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 0.9rem;
|
||||
color: #ccc;
|
||||
|
||||
Reference in New Issue
Block a user