bbgo_origin/frontend/pages/strategies.tsx

169 lines
4.2 KiB
TypeScript
Raw Normal View History

2022-06-14 09:30:33 +00:00
import DashboardLayout from '../layouts/DashboardLayout';
import { styled } from '@mui/styles';
2022-06-15 11:02:24 +00:00
import { queryStrategiesMetrics } from '../api/bbgo';
2022-06-15 10:57:28 +00:00
import { useEffect, useState } from 'react';
2022-06-14 09:30:33 +00:00
const StrategyContainer = styled('section')(() => ({
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-around',
width: '400px',
height: '400px',
border: '1px solid rgb(248, 149, 35)',
borderRadius: '10px',
2022-06-15 11:02:24 +00:00
padding: '10px',
2022-06-14 09:30:33 +00:00
}));
const Strategy = styled('div')(() => ({
fontSize: '20px',
}));
const StatusSign = styled('span')(() => ({
width: '10px',
height: '10px',
display: 'block',
backgroundColor: 'rgb(113, 218, 113)',
borderRadius: '50%',
2022-06-15 11:02:24 +00:00
marginRight: '5px',
2022-06-14 09:30:33 +00:00
}));
const RunningTime = styled('div')(() => ({
display: 'flex',
alignItems: 'center',
2022-06-15 11:02:24 +00:00
}));
2022-06-14 09:30:33 +00:00
const Description = styled('div')(() => ({
color: 'rgb(140, 140, 140)',
2022-06-15 11:02:24 +00:00
'& .duration': {
2022-06-15 10:57:28 +00:00
marginLeft: '3px',
},
2022-06-15 11:02:24 +00:00
}));
2022-06-14 09:30:33 +00:00
const Summary = styled('div')(() => ({
width: '100%',
display: 'flex',
justifyContent: 'space-around',
backgroundColor: 'rgb(255, 245, 232)',
2022-06-15 11:02:24 +00:00
}));
2022-06-14 09:30:33 +00:00
const SummaryBlock = styled('div')(() => ({
2022-06-15 11:02:24 +00:00
padding: '5px 0 5px 0',
2022-06-14 09:30:33 +00:00
}));
const StatsTitle = styled('div')(() => ({
2022-06-15 11:02:24 +00:00
margin: '0 0 10px 0',
2022-06-14 09:30:33 +00:00
}));
const StatsValue = styled('div')(() => ({
marginBottom: '10px',
color: 'rgb(123, 169, 90)',
}));
2022-06-15 10:57:28 +00:00
const Percentage = styled('div')(() => ({
2022-06-14 09:30:33 +00:00
color: 'rgb(123, 169, 90)',
}));
const Stats = styled('div')(() => ({
display: 'grid',
gridTemplateColumns: '1fr 1fr 1fr',
columnGap: '10px',
2022-06-15 11:02:24 +00:00
rowGap: '20px',
2022-06-14 09:30:33 +00:00
}));
2022-06-15 11:02:24 +00:00
export default function Strategies() {
2022-06-15 10:57:28 +00:00
const [details, setDetails] = useState([]);
useEffect(() => {
queryStrategiesMetrics().then((value) => {
setDetails(value);
2022-06-15 11:02:24 +00:00
});
}, []);
2022-06-14 09:30:33 +00:00
return (
<DashboardLayout>
2022-06-15 10:57:28 +00:00
{details.map((element) => {
2022-06-15 11:02:24 +00:00
return <Detail key={element.id} data={element} />;
2022-06-15 10:57:28 +00:00
})}
</DashboardLayout>
);
}
2022-06-15 11:02:24 +00:00
export function Detail({ data }) {
const { strategy, stats, startTime } = data;
const totalProfitsPercentage = (stats.totalProfits / stats.investment) * 100;
const gridProfitsPercentage = (stats.gridProfits / stats.investment) * 100;
const gridAprPercentage = (stats.gridProfits / 5) * 365;
2022-06-15 10:57:28 +00:00
const now = Date.now();
const durationMilliseconds = now - startTime;
const seconds = durationMilliseconds / 1000;
const day = Math.floor(seconds / (60 * 60 * 24));
2022-06-15 11:02:24 +00:00
const hour = Math.floor((seconds % (60 * 60 * 24)) / 3600);
const min = Math.floor(((seconds % (60 * 60 * 24)) % 3600) / 60);
2022-06-15 10:57:28 +00:00
return (
2022-06-15 11:02:24 +00:00
<StrategyContainer>
<Strategy>{strategy}</Strategy>
<div>{data[strategy].symbol}</div>
<RunningTime>
<StatusSign />
<Description>
Running for
<span className="duration">{day}</span>D
<span className="duration">{hour}</span>H
<span className="duration">{min}</span>M
</Description>
</RunningTime>
<Description>
0 arbitrages in 24 hours / Total <span>{stats.totalArbs}</span>{' '}
arbitrages
</Description>
<Summary>
<SummaryBlock>
<StatsTitle>Investment USDT</StatsTitle>
<div>{stats.investment}</div>
</SummaryBlock>
<SummaryBlock>
<StatsTitle>Total Profit USDT</StatsTitle>
<StatsValue>{stats.totalProfits}</StatsValue>
<Percentage>{totalProfitsPercentage}%</Percentage>
</SummaryBlock>
</Summary>
<Stats>
<div>
<StatsTitle>Grid Profits</StatsTitle>
<StatsValue>{stats.gridProfits}</StatsValue>
<Percentage>{gridProfitsPercentage}%</Percentage>
</div>
<div>
<StatsTitle>Floating PNL</StatsTitle>
<StatsValue>{stats.floatingPNL}</StatsValue>
</div>
<div>
<StatsTitle>Grid APR</StatsTitle>
<Percentage>{gridAprPercentage}%</Percentage>
</div>
<div>
<StatsTitle>Current Price</StatsTitle>
<div>{stats.currentPrice}</div>
</div>
<div>
<StatsTitle>Price Range</StatsTitle>
<div>
{stats.lowestPrice}~{stats.highestPrice}
</div>
</div>
</Stats>
</StrategyContainer>
);
}