Add files using upload-large-folder tool
Browse files- src/app/layout.tsx +11 -0
- src/app/page.tsx +16 -0
- src/components/Chart.tsx +55 -0
- src/types/lightweight-charts.d.ts +32 -0
src/app/layout.tsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default function RootLayout({
|
| 2 |
+
children,
|
| 3 |
+
}: {
|
| 4 |
+
children: React.ReactNode
|
| 5 |
+
}) {
|
| 6 |
+
return (
|
| 7 |
+
<html lang="en">
|
| 8 |
+
<body>{children}</body>
|
| 9 |
+
</html>
|
| 10 |
+
)
|
| 11 |
+
}
|
src/app/page.tsx
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
import { Chart } from '../components/Chart'
|
| 3 |
+
|
| 4 |
+
export default function Home() {
|
| 5 |
+
const handleRoboClick = () => {
|
| 6 |
+
console.log('Robo clicked - AI analysis triggered')
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
return (
|
| 10 |
+
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
| 11 |
+
<div className="w-full max-w-5xl">
|
| 12 |
+
<Chart onRoboClick={handleRoboClick} />
|
| 13 |
+
</div>
|
| 14 |
+
</main>
|
| 15 |
+
)
|
| 16 |
+
}
|
src/components/Chart.tsx
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use client"
|
| 2 |
+
import { useEffect, useRef } from 'react'
|
| 3 |
+
import * as LightweightCharts from 'lightweight-charts'
|
| 4 |
+
|
| 5 |
+
interface ChartProps {
|
| 6 |
+
onRoboClick: () => void
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export const Chart: React.FC<ChartProps> = ({ onRoboClick }) => {
|
| 10 |
+
const chartContainerRef = useRef<HTMLDivElement>(null)
|
| 11 |
+
const chartRef = useRef<any>(null)
|
| 12 |
+
|
| 13 |
+
useEffect(() => {
|
| 14 |
+
if (!chartContainerRef.current) return
|
| 15 |
+
|
| 16 |
+
chartRef.current = LightweightCharts.createChart(chartContainerRef.current, {
|
| 17 |
+
width: chartContainerRef.current.clientWidth,
|
| 18 |
+
height: 500,
|
| 19 |
+
layout: {
|
| 20 |
+
background: { color: '#1A1A1A' },
|
| 21 |
+
textColor: '#d1d4dc',
|
| 22 |
+
}
|
| 23 |
+
})
|
| 24 |
+
|
| 25 |
+
const series = chartRef.current.addCandlestickSeries()
|
| 26 |
+
|
| 27 |
+
const fetchData = async () => {
|
| 28 |
+
const response = await fetch('http://localhost:5000/fetch_candles')
|
| 29 |
+
const data = await response.json()
|
| 30 |
+
series.setData(data)
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
fetchData()
|
| 34 |
+
|
| 35 |
+
const roboIcon = document.createElement('div')
|
| 36 |
+
roboIcon.innerHTML = '🤖'
|
| 37 |
+
roboIcon.style.position = 'absolute'
|
| 38 |
+
roboIcon.style.top = '10px'
|
| 39 |
+
roboIcon.style.left = '10px'
|
| 40 |
+
roboIcon.style.fontSize = '24px'
|
| 41 |
+
roboIcon.style.cursor = 'pointer'
|
| 42 |
+
roboIcon.onclick = onRoboClick
|
| 43 |
+
chartContainerRef.current.appendChild(roboIcon)
|
| 44 |
+
|
| 45 |
+
return () => {
|
| 46 |
+
if (chartRef.current) {
|
| 47 |
+
chartRef.current.remove()
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
}, [onRoboClick])
|
| 51 |
+
|
| 52 |
+
return (
|
| 53 |
+
<div ref={chartContainerRef} className="w-full h-[500px] relative" />
|
| 54 |
+
)
|
| 55 |
+
}
|
src/types/lightweight-charts.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare module 'lightweight-charts' {
|
| 2 |
+
export type Time = number | string;
|
| 3 |
+
export type LineStyle = number;
|
| 4 |
+
|
| 5 |
+
export interface ChartOptions {
|
| 6 |
+
width: number;
|
| 7 |
+
height: number;
|
| 8 |
+
layout?: {
|
| 9 |
+
background?: { color?: string };
|
| 10 |
+
textColor?: string;
|
| 11 |
+
};
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export interface CandlestickData {
|
| 15 |
+
time: Time;
|
| 16 |
+
open: number;
|
| 17 |
+
high: number;
|
| 18 |
+
low: number;
|
| 19 |
+
close: number;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
export interface ISeriesApi<T> {
|
| 23 |
+
setData(data: CandlestickData[]): void;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
export interface IChartApi {
|
| 27 |
+
addCandlestickSeries(): ISeriesApi<'Candlestick'>;
|
| 28 |
+
remove(): void;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export function createChart(container: HTMLElement, options: ChartOptions): IChartApi;
|
| 32 |
+
}
|