Skip to content

Commit

Permalink
feat: add support for annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Dec 28, 2024
1 parent 02976a9 commit ecd687b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ declare global {
const generateBacktestMetricRows: typeof import('./utils/backtestMetrics')['generateBacktestMetricRows']
const generateBacktestSettingRows: typeof import('./utils/backtestMetrics')['generateBacktestSettingRows']
const generateCandleSeries: typeof import('./utils/charts/candleChartSeries')['generateCandleSeries']
const generateMarkArea: typeof import('./utils/charts/tradeChartData')['generateMarkArea']
const generateTradeSeries: typeof import('./utils/charts/tradeChartData')['generateTradeSeries']
const getActivePinia: typeof import('pinia')['getActivePinia']
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
Expand Down Expand Up @@ -447,6 +448,7 @@ declare module 'vue' {
readonly generateBacktestMetricRows: UnwrapRef<typeof import('./utils/backtestMetrics')['generateBacktestMetricRows']>
readonly generateBacktestSettingRows: UnwrapRef<typeof import('./utils/backtestMetrics')['generateBacktestSettingRows']>
readonly generateCandleSeries: UnwrapRef<typeof import('./utils/charts/candleChartSeries')['generateCandleSeries']>
readonly generateMarkArea: UnwrapRef<typeof import('./utils/charts/tradeChartData')['generateMarkArea']>
readonly generateTradeSeries: UnwrapRef<typeof import('./utils/charts/tradeChartData')['generateTradeSeries']>
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
Expand Down
1 change: 1 addition & 0 deletions src/components/charts/CandleChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function updateChart(initial = false) {
// open, close, low, high
y: [colOpen, colClose, colLow, colHigh],
},
...generateMarkArea(props.dataset),
},
{
name: 'Volume',
Expand Down
12 changes: 12 additions & 0 deletions src/types/candleTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export interface PairHistoryPayload {
columns?: string[];
}

export interface MarkArea {
type: 'area';
start?: string;
end?: string;
y_start?: number;
y_end?: number;
color?: string;
label?: string;
}

export interface PairHistory {
strategy: string;
pair: string;
Expand All @@ -42,6 +52,8 @@ export interface PairHistory {
all_columns?: string[];
/** Actual data */
data: number[][];
annotations: MarkArea[];

length: number;
/** Number of buy signals in this response */
buy_signals: number;
Expand Down
35 changes: 34 additions & 1 deletion src/utils/charts/tradeChartData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Order, PairHistory, Trade, BTOrder } from '@/types';

import type { ScatterSeriesOption } from 'echarts';
import type { MarkAreaComponentOption, ScatterSeriesOption } from 'echarts';

function buildTooltipCost(order: Order | BTOrder, quoteCurrency: string): string {
return `${order.ft_order_side === 'buy' ? '+' : '-'}${formatPriceCurrency(
Expand Down Expand Up @@ -225,3 +225,36 @@ export function generateTradeSeries(
}
return tradesSeries;
}

export function generateMarkArea(dataset: PairHistory): { markArea?: MarkAreaComponentOption } {
if (!dataset.annotations) return {};

const markArea: MarkAreaComponentOption = {
label: {
position: 'insideTop',
},
data: dataset.annotations
.filter((area) => area.type == 'area')
.map((area) => {
return [
{
xAxis: area.start,
yAxis: area.y_start,
itemStyle: {
color: area.color,
},
label: {
formatter: area.label,
},
},
{
xAxis: area.end,
yAxis: area.y_end,
},
];
}),
};
return {
markArea,
};
}

0 comments on commit ecd687b

Please sign in to comment.