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):
|
class BacktestCreate(BaseModel):
|
||||||
token: str
|
token: str
|
||||||
|
token_name: Optional[str] = None
|
||||||
chain: str
|
chain: str
|
||||||
timeframe: str
|
timeframe: str
|
||||||
start_date: str
|
start_date: str
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export interface Backtest {
|
|||||||
|
|
||||||
export interface BacktestConfig {
|
export interface BacktestConfig {
|
||||||
token: string;
|
token: string;
|
||||||
|
token_name?: string;
|
||||||
chain: string;
|
chain: string;
|
||||||
timeframe: string;
|
timeframe: string;
|
||||||
start_date: string;
|
start_date: string;
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
import type { Backtest } from '$lib/api';
|
import type { Backtest } from '$lib/api';
|
||||||
|
|
||||||
let botId = $derived($page.params.id);
|
let botId = $derived($page.params.id);
|
||||||
let token = $state('PEPE');
|
let tokenName = $state('');
|
||||||
|
let tokenAddress = $state('');
|
||||||
let timeframe = $state('1h');
|
let timeframe = $state('1h');
|
||||||
let startDate = $state('');
|
let startDate = $state('');
|
||||||
let endDate = $state('');
|
let endDate = $state('');
|
||||||
@@ -43,6 +44,16 @@
|
|||||||
try {
|
try {
|
||||||
const bot = await api.bots.get(botId);
|
const bot = await api.bots.get(botId);
|
||||||
setCurrentBot(bot);
|
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) {
|
} catch (e) {
|
||||||
goto('/dashboard');
|
goto('/dashboard');
|
||||||
}
|
}
|
||||||
@@ -76,7 +87,8 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const backtest = await api.backtest.start(botId, {
|
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,
|
timeframe,
|
||||||
start_date: startDate,
|
start_date: startDate,
|
||||||
end_date: endDate
|
end_date: endDate
|
||||||
@@ -133,16 +145,18 @@
|
|||||||
|
|
||||||
<form onsubmit={(e) => { e.preventDefault(); startBacktest(); }}>
|
<form onsubmit={(e) => { e.preventDefault(); startBacktest(); }}>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="field">
|
<div class="field token-info">
|
||||||
<label for="token">Token</label>
|
<label>Token</label>
|
||||||
<input type="text" id="token" bind:value={token} required />
|
<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>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label for="timeframe">Timeframe</label>
|
<label for="timeframe">Timeframe</label>
|
||||||
<select id="timeframe" bind:value={timeframe}>
|
<select id="timeframe" bind:value={timeframe}>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<option value="1h">1 hour (recommended)</option>
|
<option value="1h">1 hour (recommended)</option>
|
||||||
<option value="4h">4 hours</option>
|
<option value="4h">4 hours</option>
|
||||||
<option value="1d">1 day</option>
|
<option value="1d">1 day</option>
|
||||||
@@ -360,6 +374,27 @@
|
|||||||
gap: 0.5rem;
|
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 {
|
label {
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
color: #ccc;
|
color: #ccc;
|
||||||
|
|||||||
Reference in New Issue
Block a user