fix: trade log Invalid Date and equity curve duplicate timestamp crash
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- TradeLog: use created_at (from API) instead of timestamp for date display - EquityCurve: deduplicate data by day before passing to lightweight-charts, preventing "data must be asc ordered by time" assertion failure when multiple snapshots exist on the same day Made-with: Cursor
This commit is contained in:
parent
4f60ef453f
commit
e92cbc1bc4
2 changed files with 10 additions and 5 deletions
|
|
@ -68,10 +68,14 @@ export function EquityCurve({ data, height = 300 }: EquityCurveProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!seriesRef.current || !data.length) return;
|
if (!seriesRef.current || !data.length) return;
|
||||||
|
|
||||||
const chartData = data.map((point) => ({
|
const byDay = new Map<string, number>();
|
||||||
time: point.timestamp.split('T')[0] as string,
|
for (const point of data) {
|
||||||
value: point.value,
|
const day = point.timestamp.split('T')[0];
|
||||||
}));
|
byDay.set(day, point.value);
|
||||||
|
}
|
||||||
|
const chartData = Array.from(byDay.entries())
|
||||||
|
.sort(([a], [b]) => a.localeCompare(b))
|
||||||
|
.map(([time, value]) => ({ time, value }));
|
||||||
|
|
||||||
seriesRef.current.setData(chartData as any);
|
seriesRef.current.setData(chartData as any);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ interface Trade {
|
||||||
pnl: number | null;
|
pnl: number | null;
|
||||||
strategy_name: string;
|
strategy_name: string;
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
|
created_at: string;
|
||||||
status: string;
|
status: string;
|
||||||
signal_detail?: {
|
signal_detail?: {
|
||||||
direction: string;
|
direction: string;
|
||||||
|
|
@ -210,7 +211,7 @@ export default function TradeLog() {
|
||||||
{trade.strategy_name}
|
{trade.strategy_name}
|
||||||
</td>
|
</td>
|
||||||
<td className="py-3 px-4 text-slate-400 text-xs">
|
<td className="py-3 px-4 text-slate-400 text-xs">
|
||||||
{new Date(trade.timestamp).toLocaleString()}
|
{new Date(trade.created_at || trade.timestamp).toLocaleString()}
|
||||||
</td>
|
</td>
|
||||||
<td className="py-3 px-4 text-slate-400">
|
<td className="py-3 px-4 text-slate-400">
|
||||||
<svg
|
<svg
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue