import React, {useEffect, useState} from 'react'; import moment from 'moment'; import TradingViewChart from './TradingViewChart'; import {BalanceMap, ReportSummary} from "../types"; import { Badge, Container, createStyles, Grid, Group, Paper, SimpleGrid, Skeleton, Table, Text, ThemeIcon, Title } from '@mantine/core'; import {ArrowDownRight, ArrowUpRight,} from 'tabler-icons-react'; const useStyles = createStyles((theme) => ({ root: { paddingTop: theme.spacing.xl * 1.5, paddingBottom: theme.spacing.xl * 1.5, }, label: { fontFamily: `Greycliff CF, ${theme.fontFamily}`, }, })); interface StatsGridIconsProps { data: { title: string; value: string; diff?: number dir?: string; desc?: string; }[]; } function StatsGridIcons({data}: StatsGridIconsProps) { const {classes} = useStyles(); const stats = data.map((stat) => { const DiffIcon = stat.diff && stat.diff > 0 ? ArrowUpRight : ArrowDownRight; const DirIcon = stat.dir && stat.dir == "up" ? ArrowUpRight : ArrowDownRight; return (
{stat.title} {stat.dir ? ({color: stat.dir == "up" ? theme.colors.teal[6] : theme.colors.red[6]})} size={16} radius="xs" > : null} {stat.value}
{stat.diff ? ({color: stat.diff && stat.diff > 0 ? theme.colors.teal[6] : theme.colors.red[6]})} size={38} radius="md" > : null}
{stat.diff ? 0 ? 'teal' : 'red'} weight={700}> {stat.diff}% {' '} {stat.diff && stat.diff > 0 ? 'increase' : 'decrease'} compared to last month : null} {stat.desc ? ( {stat.desc} ) : null}
); }); return (
{stats}
); } interface ReportDetailsProps { basePath: string; runID: string; } const fetchReportSummary = (basePath: string, runID: string) => { return fetch( `${basePath}/${runID}/summary.json`, ) .then((res) => res.json()) .catch((e) => { console.error("failed to fetch index", e) }); } const skeleton = ; interface BalanceDetailsProps { balances: BalanceMap; } const BalanceDetails = (props: BalanceDetailsProps) => { const rows = Object.entries(props.balances).map(([k, v]) => { return {k} {v.available} ; }); return {rows}
Currency Balance
; }; const ReportDetails = (props: ReportDetailsProps) => { const [reportSummary, setReportSummary] = useState() useEffect(() => { fetchReportSummary(props.basePath, props.runID).then((summary: ReportSummary) => { console.log("summary", props.runID, summary); setReportSummary(summary) }) }, [props.runID]) if (!reportSummary) { return

Loading {props.runID}

; } const strategyName = props.runID.split("_")[1] const runID = props.runID.split("_").pop() const totalProfit = Math.round(reportSummary.symbolReports.map((report) => report.pnl.profit).reduce((prev, cur) => prev + cur) * 100) / 100 const totalUnrealizedProfit = Math.round(reportSummary.symbolReports.map((report) => report.pnl.unrealizedProfit).reduce((prev, cur) => prev + cur) * 100) / 100 const totalTrades = reportSummary.symbolReports.map((report) => report.pnl.numTrades).reduce((prev, cur) => prev + cur) || 0 const totalBuyVolume = reportSummary.symbolReports.map((report) => report.pnl.buyVolume).reduce((prev, cur) => prev + cur) || 0 const totalSellVolume = reportSummary.symbolReports.map((report) => report.pnl.sellVolume).reduce((prev, cur) => prev + cur) || 0 const volumeUnit = reportSummary.symbolReports.length == 1 ? reportSummary.symbolReports[0].market.baseCurrency : ''; return
Strategy: {strategyName} {reportSummary.sessions.map((session) => Exchange: {session})} {reportSummary.symbols.map((symbol) => Symbol: {symbol})} {reportSummary.startTime.toString()} — {reportSummary.endTime.toString()} ~ { moment.duration((new Date(reportSummary.endTime)).getTime() - (new Date(reportSummary.startTime)).getTime()).humanize() } Run ID: {runID}
= 0 ? "up" : "down"}, { title: "Unr. Profit", value: totalUnrealizedProfit.toString() + "$", dir: totalUnrealizedProfit > 0 ? "up" : "down" }, {title: "Trades", value: totalTrades.toString()}, {title: "Buy Vol", value: totalBuyVolume.toString() + ` ${volumeUnit}`}, {title: "Sell Vol", value: totalSellVolume.toString() + ` ${volumeUnit}`}, ]}/> Initial Total Balances Final Total Balances { /* {skeleton} */ }
{ reportSummary.symbols.map((symbol: string, i: number) => { return }) }
; }; export default ReportDetails;