From 766dea9c243a96f382144b81b25133a07ad1f2ea Mon Sep 17 00:00:00 2001 From: simple321vip Date: Sun, 11 Sep 2022 22:24:22 +0800 Subject: [PATCH] add element icon, add flask client, add strategy route, api modify --- src/api/cta_strategy.ts | 116 +++++++++++++------ src/main.ts | 8 ++ src/router/index.ts | 14 +++ src/utils/request.ts | 6 +- src/view/trader/cta_strategy.vue | 157 ++++++++++++++------------ src/view/trader/cta_strategy_file.vue | 126 +++++++++++++++++++++ 6 files changed, 314 insertions(+), 113 deletions(-) create mode 100644 src/view/trader/cta_strategy_file.vue diff --git a/src/api/cta_strategy.ts b/src/api/cta_strategy.ts index 64a4e9e..c119629 100644 --- a/src/api/cta_strategy.ts +++ b/src/api/cta_strategy.ts @@ -1,69 +1,113 @@ -import { service2 } from '../utils/request' +import { trader_service } from '../utils/request' "CTA strategy" -"strategy list" -const get_strategy_list = () => { - return service2({ - url: '/auth/api/v1/trader', +"strategy file list" +const get_strategy_files = () => { + return trader_service({ + url: '/trader/api/v1/strategy_file', + method: 'GET', + }) +} + +"upload a strategy file" +const upload_strategy_file = (file: any) => { + const formData = new FormData(); + formData.append("file", file) + return trader_service({ + url: '/trader/api/v1/strategy_file', + method: 'POST', + data: formData, + headers: { + 'Content-Type': 'multipart/form-data', + } + }) +} + +"load a strategy file" +const load_strategy_file = (file_name: string) => { + return trader_service({ + url: '/trader/api/v1/strategy_file/' + file_name, method: 'PUT', }) } -"upload a strategy" -const upload_strategy = () => { - return service2({ - url: '/auth/api/v1/trader', - method: 'PUT', +"unload a strategy file" +const unload_strategy_file = (class_name: string) => { + return trader_service({ + url: '/trader/api/v1/strategy_file/' + class_name, + method: 'PATCH', }) } -"load a strategy" -const load_strategy = (strategy_id: string) => { - return service2({ - url: '/auth/api/v1/trader', - method: 'PUT', +"remove a strategy file" +const remove_strategy_file = (file_name: string) => { + return trader_service({ + url: '/trader/api/v1/strategy_file/' + file_name, + method: 'DELETE', }) } -"unload a strategy" -const unload_strategy = (strategy_id: string) => { - return service2({ - url: '/auth/api/v1/trader', - method: 'PUT', + +"get strategy list" +const get_strategies = () => { + return trader_service({ + url: '/trader/api/v1/strategies', + method: 'GET', + }) +} + +"create a strategy" +const create_strategy = () => { + return trader_service({ + url: '/trader/api/v1/strategy', + method: 'POST', + data: {} }) } "start a strategy" -const start_strategy = (strategy_id: string) => { - return service2({ - url: '/auth/api/v1/trader', +const start_strategy = (strategy_name: string) => { + return trader_service({ + url: '/trader/api/v1/strategy/' + strategy_name, method: 'PUT', }) } "stop a strategy" -const stop_strategy = (strategy_id: string) => { - return service2({ - url: '/auth/api/v1/trader', - method: 'PUT', +const stop_strategy = (strategy_name: string) => { + return trader_service({ + url: '/trader/api/v1/strategy/' + strategy_name, + method: 'PATCH', }) } "remove a strategy" -const remove_strategy = (strategy_id: string) => { - return service2({ - url: '/auth/api/v1/trader', - method: 'PUT', +const remove_strategy = (strategy_name: string) => { + return trader_service({ + url: '/trader/api/v1/strategy/' + strategy_name, + method: 'DELETE', + }) +} + +"get a strategy status" +const get_strategy_status = (strategy_name: string) => { + return trader_service({ + url: '/trader/api/v1/strategy/status/' + strategy_name, + method: 'GET', }) } export { - get_strategy_list, - upload_strategy, - load_strategy, - unload_strategy, + get_strategy_files, + upload_strategy_file, + load_strategy_file, + unload_strategy_file, + remove_strategy_file, + get_strategies, + create_strategy, start_strategy, stop_strategy, - remove_strategy + remove_strategy, + get_strategy_status } \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index a7c7e61..aa1f634 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,8 +7,16 @@ import router from './router' import { createPinia } from 'pinia' const store = createPinia() +import * as ElementPlusIconsVue from '@element-plus/icons-vue' + let app = createApp(App) + +for (const [key, component] of Object.entries(ElementPlusIconsVue)) { + app.component(key, component) +} + + app.use(router) app.use(ElementPlus) app.use(store) diff --git a/src/router/index.ts b/src/router/index.ts index c2c10fb..8bcab45 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -68,6 +68,20 @@ const routes: Array = [ name: 'trader' } }, + { + path: '/strategy', + component: () => import('../view/trader/cta_strategy_file.vue'), + meta: { + name: '策略文件管理' + } + }, + { + path: '/strategy_instance', + component: () => import('../view/trader/cta_strategy.vue'), + meta: { + name: '策略管理' + } + }, ] }, { diff --git a/src/utils/request.ts b/src/utils/request.ts index cf19357..16921c5 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -10,7 +10,7 @@ const service = axios.create( ) // violin-trader -const service2 = axios.create( +const trader_service = axios.create( { baseURL: import.meta.env.VITE_APP_URL2 as string, timeout: 5000 @@ -35,7 +35,7 @@ service.interceptors.request.use( } ) -service2.interceptors.request.use( +trader_service.interceptors.request.use( config => { if (typeof getToken() === 'string') { (config as any).headers['Authorization'] = 'Bearer' + getToken() @@ -82,4 +82,4 @@ service2.interceptors.request.use( // } // ) -export { service, service2 } \ No newline at end of file +export { service, trader_service } \ No newline at end of file diff --git a/src/view/trader/cta_strategy.vue b/src/view/trader/cta_strategy.vue index 3b1920e..7ecae50 100644 --- a/src/view/trader/cta_strategy.vue +++ b/src/view/trader/cta_strategy.vue @@ -11,132 +11,141 @@ 检索 -
- {{ item.bk_type_name }} - 增加 - 自定义 -
- + -->
- 新建 + 新建
- + - - - - + + + + - + + + + + + + -
- 反选 - 清除 -
--> - - - - \ No newline at end of file diff --git a/src/view/trader/cta_strategy_file.vue b/src/view/trader/cta_strategy_file.vue new file mode 100644 index 0000000..ec87e8d --- /dev/null +++ b/src/view/trader/cta_strategy_file.vue @@ -0,0 +1,126 @@ + + + + + \ No newline at end of file