feat: Add persistent settings and multiple layouts support
- Add settings manager to persist symbol, timeframe, and layouts - Support multiple layouts for comprehensive chart analysis - Remove debug screenshots for cleaner logs - Update AI analysis with professional trading prompt - Add multi-screenshot analysis for better trading insights - Update analyze API to use saved settings and multiple layouts
This commit is contained in:
53
app/api/analyze/route.ts
Normal file
53
app/api/analyze/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { aiAnalysisService } from '../../../lib/ai-analysis'
|
||||
import { tradingViewCapture } from '../../../lib/tradingview'
|
||||
import { settingsManager } from '../../../lib/settings'
|
||||
import path from 'path'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const { symbol, layouts, timeframe } = await req.json()
|
||||
|
||||
// Load current settings
|
||||
const settings = await settingsManager.loadSettings()
|
||||
|
||||
// Use provided values or fall back to saved settings
|
||||
const finalSymbol = symbol || settings.symbol
|
||||
const finalTimeframe = timeframe || settings.timeframe
|
||||
const finalLayouts = layouts || settings.layouts
|
||||
|
||||
if (!finalSymbol) {
|
||||
return NextResponse.json({ error: 'Missing symbol' }, { status: 400 })
|
||||
}
|
||||
|
||||
const baseFilename = `${finalSymbol}_${finalTimeframe}_${Date.now()}`
|
||||
const screenshots = await tradingViewCapture.capture(finalSymbol, `${baseFilename}.png`, finalLayouts, finalTimeframe)
|
||||
|
||||
let result
|
||||
if (screenshots.length === 1) {
|
||||
// Single screenshot analysis
|
||||
const filename = path.basename(screenshots[0])
|
||||
result = await aiAnalysisService.analyzeScreenshot(filename)
|
||||
} else {
|
||||
// Multiple screenshots analysis
|
||||
const filenames = screenshots.map(screenshot => path.basename(screenshot))
|
||||
result = await aiAnalysisService.analyzeMultipleScreenshots(filenames)
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
return NextResponse.json({ error: 'Analysis failed' }, { status: 500 })
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
...result,
|
||||
settings: {
|
||||
symbol: finalSymbol,
|
||||
timeframe: finalTimeframe,
|
||||
layouts: finalLayouts
|
||||
},
|
||||
screenshots: screenshots.map(s => path.basename(s))
|
||||
})
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
33
app/api/auto-trading/route.ts
Normal file
33
app/api/auto-trading/route.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { getAutoTradingService } from '../../../lib/auto-trading'
|
||||
|
||||
const autoTradingService = getAutoTradingService()
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const { action, config } = await req.json()
|
||||
if (action === 'start') {
|
||||
autoTradingService.start()
|
||||
return NextResponse.json({ status: 'started' })
|
||||
}
|
||||
if (action === 'stop') {
|
||||
autoTradingService.stop()
|
||||
return NextResponse.json({ status: 'stopped' })
|
||||
}
|
||||
if (action === 'config' && config) {
|
||||
autoTradingService.setConfig(config)
|
||||
return NextResponse.json({ status: 'config updated', config: autoTradingService })
|
||||
}
|
||||
return NextResponse.json({ error: 'Invalid action' }, { status: 400 })
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
// Return current config/status
|
||||
return NextResponse.json({
|
||||
config: autoTradingService,
|
||||
running: !!autoTradingService['intervalId']
|
||||
})
|
||||
}
|
||||
15
app/api/screenshot/route.ts
Normal file
15
app/api/screenshot/route.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { tradingViewCapture } from '../../../lib/tradingview'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const { symbol, filename } = await req.json()
|
||||
if (!symbol || !filename) {
|
||||
return NextResponse.json({ error: 'Missing symbol or filename' }, { status: 400 })
|
||||
}
|
||||
const filePath = await tradingViewCapture.capture(symbol, filename)
|
||||
return NextResponse.json({ filePath })
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
14
app/api/trading-history/route.ts
Normal file
14
app/api/trading-history/route.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import prisma from '../../../lib/prisma'
|
||||
import { NextResponse } from 'next/server'
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const trades = await prisma.trade.findMany({
|
||||
orderBy: { executedAt: 'desc' },
|
||||
take: 50
|
||||
})
|
||||
return NextResponse.json(trades)
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
21
app/api/trading/route.ts
Normal file
21
app/api/trading/route.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { driftTradingService } from '../../../lib/drift-trading'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const params = await req.json()
|
||||
const result = await driftTradingService.executeTrade(params)
|
||||
return NextResponse.json(result)
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const positions = await driftTradingService.getPositions()
|
||||
return NextResponse.json({ positions })
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
7
app/globals.css
Normal file
7
app/globals.css
Normal file
@@ -0,0 +1,7 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
body {
|
||||
font-family: 'Inter', system-ui, sans-serif;
|
||||
}
|
||||
19
app/layout.tsx
Normal file
19
app/layout.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import './globals.css'
|
||||
import type { Metadata } from 'next'
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Trading Bot Dashboard',
|
||||
description: 'AI-powered trading bot dashboard with auto-trading, analysis, and developer tools.'
|
||||
}
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className="bg-gray-950 text-gray-100 min-h-screen">
|
||||
<main className="max-w-5xl mx-auto py-8">
|
||||
{children}
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
11
app/page.tsx
Normal file
11
app/page.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import AIAnalysisPanel from '../components/AIAnalysisPanel'
|
||||
import Dashboard from '../components/Dashboard'
|
||||
|
||||
export default function HomePage() {
|
||||
return (
|
||||
<>
|
||||
<AIAnalysisPanel />
|
||||
<Dashboard />
|
||||
</>
|
||||
)
|
||||
}
|
||||
22
app/screenshots/[filename]/route.ts
Normal file
22
app/screenshots/[filename]/route.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import fs from 'fs/promises'
|
||||
import path from 'path'
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
context: any
|
||||
) {
|
||||
try {
|
||||
const screenshotsDir = path.join(process.cwd(), 'screenshots')
|
||||
const filePath = path.join(screenshotsDir, context.params.filename)
|
||||
const file = await fs.readFile(filePath)
|
||||
return new NextResponse(file, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Content-Disposition': `inline; filename="${context.params.filename}"`
|
||||
}
|
||||
})
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: 404 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user