feat: add trading stats to AI context and one-click deployment data clearing

- Add historical trading statistics to AI decision context with language detection
- Remove win rate from metrics, focus on profit factor, sharpe ratio, win/loss ratio
- Add option to clear trading data tables during one-click deployment
- Add sqlite to Docker runtime for container-based data clearing
This commit is contained in:
tinkle-community
2025-12-28 22:09:47 +08:00
parent d74867c220
commit b228412821
6 changed files with 281 additions and 2 deletions

View File

@@ -128,6 +128,38 @@ pull_images() {
echo -e "${GREEN}✓ Images pulled${NC}"
}
# Ask user if they want to clear trading data
ask_clear_trading_data() {
local db_file="data/data.db"
# Only ask if database file exists
if [ ! -f "$db_file" ]; then
CLEAR_TRADING_DATA="no"
return 0
fi
echo ""
echo -e "${YELLOW}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${YELLOW}Do you want to clear trading data? (orders, fills, positions)${NC}"
echo -e "${BLUE} • trader_orders (Order records)${NC}"
echo -e "${BLUE} • trader_fills (Fill/execution records)${NC}"
echo -e "${BLUE} • trader_positions (Position records)${NC}"
echo -e "${YELLOW}═══════════════════════════════════════════════════════════════${NC}"
echo ""
echo -e "${BLUE}Type 'yes' to clear tables, press Enter or any other input to skip${NC}"
echo -n "Input: "
read -r confirm
if [ "$confirm" == "yes" ]; then
CLEAR_TRADING_DATA="yes"
echo -e "${YELLOW}Trading data will be cleared after services start...${NC}"
else
CLEAR_TRADING_DATA="no"
echo -e "${BLUE}Skipping data clear${NC}"
fi
echo ""
}
# Start services
start_services() {
echo -e "${YELLOW}Starting NOFX services...${NC}"
@@ -135,6 +167,28 @@ start_services() {
echo -e "${GREEN}✓ Services started${NC}"
}
# Clear trading data via container (called after services are ready)
clear_trading_data() {
if [ "$CLEAR_TRADING_DATA" != "yes" ]; then
return 0
fi
echo -e "${YELLOW}Clearing trading data tables via container...${NC}"
# Wait a moment for database to be ready
sleep 2
# Execute SQL to clear tables via docker exec
$COMPOSE_CMD exec -T backend sh -c "sqlite3 /app/data/data.db 'DELETE FROM trader_fills; DELETE FROM trader_orders; DELETE FROM trader_positions;'" 2>/dev/null
if [ $? -eq 0 ]; then
echo -e "${GREEN}✓ Trading data tables cleared${NC}"
else
echo -e "${RED}Failed to clear trading data. You can manually run:${NC}"
echo -e "${BLUE} $COMPOSE_CMD exec backend sqlite3 /app/data/data.db 'DELETE FROM trader_fills; DELETE FROM trader_orders; DELETE FROM trader_positions;'${NC}"
fi
}
# Wait for services
wait_for_services() {
echo -e "${YELLOW}Waiting for services to be ready...${NC}"
@@ -224,8 +278,10 @@ main() {
download_files
generate_env
pull_images
ask_clear_trading_data
start_services
wait_for_services
clear_trading_data
print_success
}