2020-08-17 19:15:15 +00:00
|
|
|
<template>
|
2020-08-17 20:07:20 +00:00
|
|
|
<v-chart v-if="trades.length > 0" :options="hourlyChartOptions" />
|
2020-08-17 19:15:15 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Vue, Prop } from 'vue-property-decorator';
|
|
|
|
|
|
|
|
import ECharts from 'vue-echarts';
|
2020-08-17 20:07:20 +00:00
|
|
|
|
2020-08-17 19:15:15 +00:00
|
|
|
import 'echarts/lib/chart/bar';
|
|
|
|
import 'echarts/lib/chart/line';
|
|
|
|
import 'echarts/lib/component/title';
|
|
|
|
import 'echarts/lib/component/tooltip';
|
|
|
|
import 'echarts/lib/component/legend';
|
2020-08-17 20:07:20 +00:00
|
|
|
import 'echarts/lib/component/visualMap';
|
|
|
|
import 'echarts/lib/component/visualMapPiecewise';
|
2020-08-17 19:15:15 +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';
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
@Prop({ required: true }) trades!: Array<Trade>;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
res[hour].profit += trade.close_profit;
|
|
|
|
res[hour].count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hourlyChartOptions() {
|
|
|
|
return {
|
|
|
|
title: {
|
|
|
|
text: 'Hourly Profit',
|
|
|
|
show: true,
|
|
|
|
},
|
|
|
|
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-08-17 20:07:20 +00:00
|
|
|
visualMap: {
|
|
|
|
dimension: 1,
|
|
|
|
seriesIndex: 0,
|
|
|
|
show: false,
|
|
|
|
pieces: [
|
|
|
|
{
|
2020-08-18 18:51:16 +00:00
|
|
|
max: -0.001,
|
2020-08-19 15:31:52 +00:00
|
|
|
min: -2,
|
2020-08-18 18:51:16 +00:00
|
|
|
color: 'red',
|
2020-08-17 20:07:20 +00:00
|
|
|
},
|
|
|
|
{
|
2020-08-18 18:51:16 +00:00
|
|
|
min: -0.01,
|
|
|
|
max: 2,
|
|
|
|
color: 'green',
|
2020-08-17 20:07:20 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-08-17 19:15:15 +00:00
|
|
|
series: [
|
|
|
|
{
|
|
|
|
type: 'line',
|
|
|
|
name: CHART_PROFIT,
|
|
|
|
color: 'black',
|
2020-08-17 20:07:20 +00:00
|
|
|
// symbol: 'none',
|
2020-08-17 19:15:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'bar',
|
|
|
|
name: CHART_TRADE_COUNT,
|
|
|
|
color: 'rgba(150,150,150,0.3)',
|
|
|
|
yAxisIndex: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped></style>
|