mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +00:00
add exchange session panel
This commit is contained in:
parent
e6a182f707
commit
3e3b21c59f
|
@ -2,6 +2,13 @@ import axios from "axios";
|
||||||
|
|
||||||
const baseURL = process.env.NODE_ENV === "development" ? "http://localhost:8080" : ""
|
const baseURL = process.env.NODE_ENV === "development" ? "http://localhost:8080" : ""
|
||||||
|
|
||||||
|
export function querySessions(cb) {
|
||||||
|
axios.get(baseURL + '/api/sessions', {})
|
||||||
|
.then(response => {
|
||||||
|
cb(response.data.sessions)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function queryAssets(cb) {
|
export function queryAssets(cb) {
|
||||||
axios.get(baseURL + '/api/assets', {})
|
axios.get(baseURL + '/api/assets', {})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|
41
frontend/components/ExchangeSessionTabPanel.js
Normal file
41
frontend/components/ExchangeSessionTabPanel.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import Paper from "@material-ui/core/Paper";
|
||||||
|
import Box from "@material-ui/core/Box";
|
||||||
|
import Tabs from "@material-ui/core/Tabs";
|
||||||
|
import Tab from "@material-ui/core/Tab";
|
||||||
|
import Link from "@material-ui/core/Link";
|
||||||
|
import React, {useEffect, useState} from "react";
|
||||||
|
import {querySessions} from '../api/bbgo'
|
||||||
|
|
||||||
|
export default function ExchangeSessionTabPanel() {
|
||||||
|
const [tabIndex, setTabIndex] = React.useState(0);
|
||||||
|
const handleTabClick = (event, newValue) => {
|
||||||
|
setTabIndex(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
const [sessions, setSessions] = useState({})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
querySessions((sessions) => {
|
||||||
|
setSessions(sessions)
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return <Paper>
|
||||||
|
<Box m={4}>
|
||||||
|
<Tabs
|
||||||
|
value={tabIndex}
|
||||||
|
onChange={handleTabClick}
|
||||||
|
indicatorColor="primary"
|
||||||
|
textColor="primary"
|
||||||
|
>
|
||||||
|
<Tab label="Item One"/>
|
||||||
|
<Tab label="Item Two"/>
|
||||||
|
<Tab label="Item Three"/>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
|
<Link href="/about" color="secondary">
|
||||||
|
Go to the about page
|
||||||
|
</Link>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
}
|
|
@ -2,34 +2,7 @@ import React, {useEffect, useState} from 'react';
|
||||||
|
|
||||||
import {ResponsivePie} from '@nivo/pie';
|
import {ResponsivePie} from '@nivo/pie';
|
||||||
import {queryAssets} from '../api/bbgo';
|
import {queryAssets} from '../api/bbgo';
|
||||||
|
import {currencyColor} from '../src/utils';
|
||||||
function currencyColor(currency) {
|
|
||||||
switch (currency) {
|
|
||||||
case "BTC":
|
|
||||||
return "#f69c3d"
|
|
||||||
case "ETH":
|
|
||||||
return "#497493"
|
|
||||||
case "MCO":
|
|
||||||
return "#032144"
|
|
||||||
case "OMG":
|
|
||||||
return "#2159ec"
|
|
||||||
case "LTC":
|
|
||||||
return "#949494"
|
|
||||||
case "USDT":
|
|
||||||
return "#2ea07b"
|
|
||||||
case "SAND":
|
|
||||||
return "#2E9AD0"
|
|
||||||
case "XRP":
|
|
||||||
return "#00AAE4"
|
|
||||||
case "BCH":
|
|
||||||
return "#8DC351"
|
|
||||||
case "MAX":
|
|
||||||
return "#2D4692"
|
|
||||||
case "TWD":
|
|
||||||
return "#4A7DED"
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function reduceAssetsBy(assets, field, minimum) {
|
function reduceAssetsBy(assets, field, minimum) {
|
||||||
let as = []
|
let as = []
|
||||||
|
@ -56,7 +29,7 @@ function reduceAssetsBy(assets, field, minimum) {
|
||||||
return as
|
return as
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TotalAssets() {
|
export default function TotalAssetsPie() {
|
||||||
const [assets, setAssets] = useState({})
|
const [assets, setAssets] = useState({})
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -83,16 +56,15 @@ export default function TotalAssets() {
|
||||||
sliceLabelsTextColor="#fff"
|
sliceLabelsTextColor="#fff"
|
||||||
legends={[
|
legends={[
|
||||||
{
|
{
|
||||||
anchor: 'bottom',
|
anchor: 'right',
|
||||||
direction: 'row',
|
direction: 'column',
|
||||||
justify: false,
|
justify: false,
|
||||||
translateX: 0,
|
translateX: 0,
|
||||||
translateY: 56,
|
translateY: 0,
|
||||||
itemsSpacing: 0,
|
itemsSpacing: 5,
|
||||||
itemWidth: 100,
|
itemWidth: 120,
|
||||||
itemHeight: 18,
|
itemHeight: 24,
|
||||||
itemTextColor: '#999',
|
itemTextColor: '#999',
|
||||||
itemDirection: 'left-to-right',
|
|
||||||
itemOpacity: 1,
|
itemOpacity: 1,
|
||||||
symbolSize: 18,
|
symbolSize: 18,
|
||||||
symbolShape: 'circle',
|
symbolShape: 'circle',
|
66
frontend/components/TotalAssetsSummary.js
Normal file
66
frontend/components/TotalAssetsSummary.js
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
import {useEffect, useState} from "react";
|
||||||
|
import {queryAssets} from "../api/bbgo";
|
||||||
|
import Card from '@material-ui/core/Card';
|
||||||
|
import CardContent from '@material-ui/core/CardContent';
|
||||||
|
import Typography from '@material-ui/core/Typography';
|
||||||
|
import {makeStyles} from '@material-ui/core/styles';
|
||||||
|
|
||||||
|
function aggregateAssetsBy(assets, field) {
|
||||||
|
let total = 0.0
|
||||||
|
for (let key in assets) {
|
||||||
|
if (assets[key]) {
|
||||||
|
let a = assets[key]
|
||||||
|
let value = a[field]
|
||||||
|
total += value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
root: {
|
||||||
|
minWidth: 275,
|
||||||
|
},
|
||||||
|
bullet: {
|
||||||
|
display: 'inline-block',
|
||||||
|
margin: '0 2px',
|
||||||
|
transform: 'scale(0.8)',
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontSize: 14,
|
||||||
|
},
|
||||||
|
pos: {
|
||||||
|
marginTop: 12,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function TotalAssetSummary() {
|
||||||
|
const classes = useStyles();
|
||||||
|
const [assets, setAssets] = useState({})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
queryAssets((assets) => {
|
||||||
|
setAssets(assets)
|
||||||
|
})
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return <Card className={classes.root} variant="outlined">
|
||||||
|
<CardContent>
|
||||||
|
<Typography className={classes.title} color="textSecondary" gutterBottom>
|
||||||
|
Total Account Balance
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="h5" component="h2">
|
||||||
|
{Math.round(aggregateAssetsBy(assets, "inBTC") * 1e8) / 1e8} <span>BTC</span>
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography className={classes.pos} color="textSecondary">
|
||||||
|
Estimated Value
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography variant="h5" component="h3">
|
||||||
|
{Math.round(aggregateAssetsBy(assets, "inUSD") * 100) / 100} <span>USD</span>
|
||||||
|
</Typography>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
}
|
|
@ -7,20 +7,23 @@ import Box from '@material-ui/core/Box';
|
||||||
import Link from '@material-ui/core/Link';
|
import Link from '@material-ui/core/Link';
|
||||||
import Grid from '@material-ui/core/Grid';
|
import Grid from '@material-ui/core/Grid';
|
||||||
import Paper from '@material-ui/core/Paper';
|
import Paper from '@material-ui/core/Paper';
|
||||||
|
import Tabs from '@material-ui/core/Tabs';
|
||||||
|
import Tab from '@material-ui/core/Tab';
|
||||||
|
|
||||||
import TotalAssets from '../components/TotalAssets';
|
import TotalAssetsPie from '../components/TotalAssetsPie';
|
||||||
|
import TotalAssetSummary from '../components/TotalAssetsSummary';
|
||||||
|
|
||||||
|
import ExchangeSessionTabPanel from '../components/ExchangeSessionTabPanel';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
|
||||||
flexGrow: 1,
|
|
||||||
},
|
|
||||||
paper: {
|
paper: {
|
||||||
height: 140,
|
height: 140,
|
||||||
width: 200,
|
width: 200,
|
||||||
},
|
},
|
||||||
totalAssetsPaper: {
|
totalAssetsBox: {
|
||||||
height: 300,
|
height: 300,
|
||||||
},
|
},
|
||||||
|
totalAssetsSummary: {},
|
||||||
control: {
|
control: {
|
||||||
padding: theme.spacing(2),
|
padding: theme.spacing(2),
|
||||||
},
|
},
|
||||||
|
@ -29,39 +32,30 @@ const useStyles = makeStyles((theme) => ({
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container maxWidth="lg">
|
<Container>
|
||||||
<Box my={4}>
|
<Paper className={classes.totalAssetsSummary}>
|
||||||
<Typography variant="h4" component="h1" gutterBottom>
|
<Box m={4}>
|
||||||
|
<Typography variant="h4" component="h2" gutterBottom>
|
||||||
Total Assets
|
Total Assets
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Paper className={classes.totalAssetsPaper}>
|
<Grid container spacing={3}>
|
||||||
<TotalAssets/>
|
<Grid item xs={12} md={6}>
|
||||||
</Paper>
|
<TotalAssetSummary/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid item xs={12} md={6}>
|
||||||
|
<Box className={classes.totalAssetsBox}>
|
||||||
|
<TotalAssetsPie/>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box my={4}>
|
|
||||||
|
|
||||||
<Grid container className={classes.root}>
|
|
||||||
<Grid item xs={12}>
|
|
||||||
<Grid container justify="center">
|
|
||||||
<Grid item>
|
|
||||||
<Paper className={classes.paper}>
|
|
||||||
</Paper>
|
|
||||||
</Grid>
|
|
||||||
<Grid item>
|
|
||||||
<Paper className={classes.paper}>
|
|
||||||
</Paper>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<Link href="/about" color="secondary">
|
|
||||||
Go to the about page
|
|
||||||
</Link>
|
|
||||||
</Box>
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
<ExchangeSessionTabPanel/>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
28
frontend/src/utils.js
Normal file
28
frontend/src/utils.js
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
export function currencyColor(currency) {
|
||||||
|
switch (currency) {
|
||||||
|
case "BTC":
|
||||||
|
return "#f69c3d"
|
||||||
|
case "ETH":
|
||||||
|
return "#497493"
|
||||||
|
case "MCO":
|
||||||
|
return "#032144"
|
||||||
|
case "OMG":
|
||||||
|
return "#2159ec"
|
||||||
|
case "LTC":
|
||||||
|
return "#949494"
|
||||||
|
case "USDT":
|
||||||
|
return "#2ea07b"
|
||||||
|
case "SAND":
|
||||||
|
return "#2E9AD0"
|
||||||
|
case "XRP":
|
||||||
|
return "#00AAE4"
|
||||||
|
case "BCH":
|
||||||
|
return "#8DC351"
|
||||||
|
case "MAX":
|
||||||
|
return "#2D4692"
|
||||||
|
case "TWD":
|
||||||
|
return "#4A7DED"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user