2020-08-17 19:15:15 +00:00
|
|
|
<template>
|
2020-12-28 19:34:54 +00:00
|
|
|
<v-chart
|
|
|
|
v-if="trades.length > 0"
|
2021-05-24 14:24:46 +00:00
|
|
|
:option="hourlyChartOptions"
|
2020-12-28 19:34:54 +00:00
|
|
|
autoresize
|
|
|
|
:theme="getChartTheme"
|
|
|
|
/>
|
2020-08-17 19:15:15 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue, Prop } from 'vue-property-decorator';
|
2020-12-28 19:34:54 +00:00
|
|
|
import { Getter } from 'vuex-class';
|
2020-08-17 19:15:15 +00:00
|
|
|
|
|
|
|
import ECharts from 'vue-echarts';
|
2020-08-17 20:07:20 +00:00
|
|
|
|
2020-08-29 09:23:39 +00:00
|
|
|
import { Trade } from '@/types';
|
2020-08-17 19:15:15 +00:00
|
|
|
import { timestampHour } from '@/shared/formatters';
|
2021-05-24 14:39:02 +00:00
|
|
|
import { EChartsOption } from 'echarts';
|
2020-08-17 19:15:15 +00:00
|
|
|
|
2021-05-24 15:45:20 +00:00
|
|
|
import { use } from 'echarts/core';
|
|
|
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
|
|
import { LineChart, BarChart } from 'echarts/charts';
|
|
|
|
import {
|
|
|
|
TitleComponent,
|
|
|
|
TooltipComponent,
|
|
|
|
LegendComponent,
|
|
|
|
VisualMapComponent,
|
|
|
|
VisualMapPiecewiseComponent,
|
|
|
|
} from 'echarts/components';
|
|
|
|
|
|
|
|
use([
|
|
|
|
BarChart,
|
|
|
|
LineChart,
|
|
|
|
CanvasRenderer,
|
|
|
|
TitleComponent,
|
|
|
|
TooltipComponent,
|
|
|
|
LegendComponent,
|
|
|
|
VisualMapComponent,
|
|
|
|
VisualMapPiecewiseComponent,
|
|
|
|
]);
|
|
|
|
|
2020-08-17 19:15:15 +00:00
|
|
|
// Define Column labels here to avoid typos
|
2020-08-18 18:51:16 +00:00
|
|
|
const CHART_PROFIT = 'Profit %';
|
2020-08-17 19:15:15 +00:00
|
|
|
const CHART_TRADE_COUNT = 'Trade Count';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
|
|
|
'v-chart': ECharts,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class HourlyChart extends Vue {
|
2020-08-29 15:47:05 +00:00
|
|
|
@Prop({ required: true }) trades!: Trade[];
|
2020-08-17 19:15:15 +00:00
|
|
|
|
2020-08-31 15:47:26 +00:00
|
|
|
@Prop({ default: true, type: Boolean }) showTitle!: boolean;
|
|
|
|
|
2020-12-28 19:34:54 +00:00
|
|
|
@Getter getChartTheme!: string;
|
|
|
|
|
2020-08-17 19:15:15 +00:00
|
|
|
get hourlyData() {
|
|
|
|
const res = new Array(24);
|
|
|
|
for (let i = 0; i < 24; i += 1) {
|
2020-08-17 20:07:20 +00:00
|
|
|
res[i] = { hour: i, hourDesc: `${i}h`, profit: 0.0, count: 0.0 };
|
2020-08-17 19:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0, len = this.trades.length; i < len; i += 1) {
|
|
|
|
const trade = this.trades[i];
|
|
|
|
if (trade.close_timestamp) {
|
|
|
|
const hour = timestampHour(trade.close_timestamp);
|
|
|
|
|
2020-12-02 19:03:17 +00:00
|
|
|
res[hour].profit += trade.profit_ratio;
|
2020-08-17 19:15:15 +00:00
|
|
|
res[hour].count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-05-24 14:39:02 +00:00
|
|
|
get hourlyChartOptions(): EChartsOption {
|
2020-08-17 19:15:15 +00:00
|
|
|
return {
|
|
|
|
title: {
|
|
|
|
text: 'Hourly Profit',
|
2020-08-31 15:47:26 +00:00
|
|
|
show: this.showTitle,
|
2020-08-17 19:15:15 +00:00
|
|
|
},
|
|
|
|
dataset: {
|
|
|
|
dimensions: ['hourDesc', 'profit', 'count'],
|
|
|
|
source: this.hourlyData,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: {
|
|
|
|
type: 'line',
|
|
|
|
label: {
|
|
|
|
backgroundColor: '#6a7985',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
data: [CHART_PROFIT, CHART_TRADE_COUNT],
|
2020-08-19 17:27:59 +00:00
|
|
|
right: '5%',
|
2020-08-17 19:15:15 +00:00
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
type: 'category',
|
|
|
|
},
|
|
|
|
yAxis: [
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: CHART_PROFIT,
|
|
|
|
splitLine: {
|
|
|
|
show: false,
|
|
|
|
},
|
|
|
|
nameRotate: 90,
|
|
|
|
nameLocation: 'middle',
|
|
|
|
nameGap: 30,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: CHART_TRADE_COUNT,
|
|
|
|
nameRotate: 90,
|
|
|
|
nameLocation: 'middle',
|
|
|
|
nameGap: 30,
|
|
|
|
},
|
|
|
|
],
|
2020-10-04 17:24:21 +00:00
|
|
|
visualMap: [
|
|
|
|
{
|
|
|
|
dimension: 1,
|
|
|
|
seriesIndex: 0,
|
|
|
|
show: false,
|
|
|
|
pieces: [
|
|
|
|
{
|
2021-04-10 07:14:21 +00:00
|
|
|
max: 0.0,
|
2020-10-04 17:24:21 +00:00
|
|
|
min: -2,
|
|
|
|
color: 'red',
|
|
|
|
},
|
|
|
|
{
|
2021-04-10 07:14:21 +00:00
|
|
|
min: 0.0,
|
2020-10-04 17:24:21 +00:00
|
|
|
max: 2,
|
|
|
|
color: 'green',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2020-08-17 19:15:15 +00:00
|
|
|
series: [
|
|
|
|
{
|
|
|
|
type: 'line',
|
|
|
|
name: CHART_PROFIT,
|
2021-01-05 18:29:57 +00:00
|
|
|
animation: false,
|
2020-08-17 20:07:20 +00:00
|
|
|
// symbol: 'none',
|
2020-08-17 19:15:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'bar',
|
|
|
|
name: CHART_TRADE_COUNT,
|
2021-01-05 18:29:57 +00:00
|
|
|
animation: false,
|
2020-10-04 17:24:21 +00:00
|
|
|
itemStyle: {
|
|
|
|
color: 'rgba(150,150,150,0.3)',
|
|
|
|
},
|
2020-08-17 19:15:15 +00:00
|
|
|
yAxisIndex: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2020-08-18 05:05:40 +00:00
|
|
|
<style scoped>
|
|
|
|
.echarts {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
</style>
|