diff --git a/src/api/cta_strategy.ts b/src/api/cta_strategy.ts new file mode 100644 index 0000000..694497a --- /dev/null +++ b/src/api/cta_strategy.ts @@ -0,0 +1,69 @@ +import request from '../utils/request' + +"CTA strategy" + +"strategy list" +const get_strategy_list = () => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + }) +} + +"upload a strategy" +const upload_strategy = () => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + }) +} + +"load a strategy" +const load_strategy = (strategy_id: string) => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + }) +} + +"unload a strategy" +const unload_strategy = (strategy_id: string) => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + }) +} + +"start a strategy" +const start_strategy = (strategy_id: string) => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + }) +} + +"stop a strategy" +const stop_strategy = (strategy_id: string) => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + }) +} + +"remove a strategy" +const remove_strategy = (strategy_id: string) => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + }) +} + +export { + get_strategy_list, + upload_strategy, + load_strategy, + unload_strategy, + start_strategy, + stop_strategy, + remove_strategy +} \ No newline at end of file diff --git a/src/api/trader.ts b/src/api/trader.ts new file mode 100644 index 0000000..e5912eb --- /dev/null +++ b/src/api/trader.ts @@ -0,0 +1,11 @@ +import request from '../utils/request' + +const get_stock_data = (data: Object) => { + return request({ + url: '/auth/api/v1/trader', + method: 'PUT', + data: data + }) +} + +export { get_stock_data } \ No newline at end of file diff --git a/src/components/layout/NavBar.vue b/src/components/layout/NavBar.vue index 88dee1a..a8a15fe 100644 --- a/src/components/layout/NavBar.vue +++ b/src/components/layout/NavBar.vue @@ -49,7 +49,7 @@ const doLogin = () => { } const doLogout = () => { dialogVisible.value = false - logout(tenant.id).then(() => { + logout(tenant.id).catch(() => { console.log(1) }).finally(() => { tenant.logout() router.push({ path: '/login' diff --git a/src/router/index.ts b/src/router/index.ts index d2819c8..c2c10fb 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -61,6 +61,13 @@ const routes: Array = [ name: '一键打包' } }, + { + path: '/trader', + component: () => import('../view/trader/index.vue'), + meta: { + name: 'trader' + } + }, ] }, { diff --git a/src/service/trader.ts b/src/service/trader.ts new file mode 100644 index 0000000..613763d --- /dev/null +++ b/src/service/trader.ts @@ -0,0 +1,209 @@ +import * as echarts from 'echarts' +const upColor = '#ec0000' +const upBorderColor = '#8A0000' +const downColor = '#00da3c' +const downBorderColor = '#008F28' +import { EChartsOption } from 'echarts' + +type DataItem = [string, number, number, number, number, number, number]; + +const option: EChartsOption = { + dataset: { + source: [] + }, + title: { + text: '' + }, + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'line' + } + }, + toolbox: { + feature: { + dataZoom: { + yAxisIndex: false + } + } + }, + grid: [ + { + left: '10%', + right: '10%', + bottom: 200 + }, + { + left: '10%', + right: '10%', + height: 80, + bottom: 80 + } + ], + xAxis: [ + { + type: 'category', + boundaryGap: false, + // inverse: true, + axisLine: { onZero: false }, + splitLine: { show: false }, + min: 'dataMin', + max: 'dataMax' + }, + { + type: 'category', + gridIndex: 1, + boundaryGap: false, + axisLine: { onZero: false }, + axisTick: { show: false }, + splitLine: { show: false }, + axisLabel: { show: false }, + min: 'dataMin', + max: 'dataMax' + } + ], + yAxis: [ + { + scale: true, + splitArea: { + show: true + } + }, + { + scale: true, + gridIndex: 1, + splitNumber: 2, + axisLabel: { show: false }, + axisLine: { show: false }, + axisTick: { show: false }, + splitLine: { show: false } + } + ], + dataZoom: [ + { + type: 'inside', + xAxisIndex: [0, 1], + start: 10, + end: 100 + }, + { + show: true, + xAxisIndex: [0, 1], + type: 'slider', + bottom: 10, + start: 10, + end: 100 + } + ], + visualMap: { + show: false, + seriesIndex: 1, + dimension: 6, + pieces: [ + { + value: 1, + color: upColor + }, + { + value: -1, + color: downColor + } + ] + }, + series: [ + { + type: 'candlestick', + itemStyle: { + color: upColor, + color0: downColor, + borderColor: upBorderColor, + borderColor0: downBorderColor + }, + encode: { + x: 0, + y: [1, 4, 3, 2] + } + }, + { + name: 'Volumn', + type: 'bar', + xAxisIndex: 1, + yAxisIndex: 1, + itemStyle: { + color: '#7fbe9e' + }, + large: true, + encode: { + x: 0, + y: 5 + } + } + ] +} + +const generateOHLC = (count: number) => { + let data: DataItem[] = []; + + let xValue = +new Date(2011, 0, 1); + let minute = 60 * 1000; + let baseValue = Math.random() * 12000; + let boxVals = new Array(4); + let dayRange = 12; + + for (let i = 0; i < count; i++) { + baseValue = baseValue + Math.random() * 20 - 10; + + for (let j = 0; j < 4; j++) { + boxVals[j] = (Math.random() - 0.5) * dayRange + baseValue; + } + boxVals.sort(); + + let openIdx = Math.round(Math.random() * 3); + let closeIdx = Math.round(Math.random() * 2); + if (closeIdx === openIdx) { + closeIdx++; + } + let volumn = boxVals[3] * (1000 + Math.random() * 500); + + // ['open', 'close', 'lowest', 'highest', 'volumn'] + // [1, 4, 3, 2] + data[i] = [ + echarts.format.formatTime('yyyy-MM-dd\nhh:mm:ss', (xValue += minute)), + +boxVals[openIdx].toFixed(2), // open + +boxVals[3].toFixed(2), // highest + +boxVals[0].toFixed(2), // lowest + +boxVals[closeIdx].toFixed(2), // close + +volumn.toFixed(0), + getSign(data, i, +boxVals[openIdx], +boxVals[closeIdx], 4) // sign + ]; + } + + return data; +} + +const getSign = ( + data: DataItem[], + dataIndex: number, + openVal: number, + closeVal: number, + closeDimIdx: number +) => { + var sign + if (openVal > closeVal) { + sign = -1 + } else if (openVal < closeVal) { + sign = 1 + } else { + sign = + dataIndex > 0 + ? // If close === open, compare with close of last record + data[dataIndex - 1][closeDimIdx] <= closeVal + ? 1 + : -1 + : // No record of previous, set to be positive + 1 + } + return sign +} + +export { generateOHLC, option } \ No newline at end of file diff --git a/src/view/dashboard/index.vue b/src/view/dashboard/index.vue index 510108d..f097291 100644 --- a/src/view/dashboard/index.vue +++ b/src/view/dashboard/index.vue @@ -1,7 +1,7 @@ diff --git a/src/view/trader/cta_strategy.vue b/src/view/trader/cta_strategy.vue new file mode 100644 index 0000000..3b1920e --- /dev/null +++ b/src/view/trader/cta_strategy.vue @@ -0,0 +1,142 @@ + + + + + \ No newline at end of file diff --git a/src/view/trader/index.vue b/src/view/trader/index.vue new file mode 100644 index 0000000..2fc0ab1 --- /dev/null +++ b/src/view/trader/index.vue @@ -0,0 +1,63 @@ + + + + + \ No newline at end of file