st-comp 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.18",
4
+ "version": "0.0.19",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -17,6 +17,7 @@
17
17
  "echarts": "^5.4.3",
18
18
  "element-plus": "^2.3.14",
19
19
  "pinia": "^2.1.6",
20
+ "st-func": "^0.0.14",
20
21
  "talib.js": "^0.1.0",
21
22
  "vue": "^3.3.4",
22
23
  "vue-router": "^4.2.5"
@@ -9,144 +9,17 @@ interface InformatData {
9
9
  low: number[]
10
10
  kLineData: [number, number, number, number, number, number][]
11
11
  }
12
+ interface indicatorInfoItemType {
13
+ calculationFn: Function
14
+ color: string
15
+ key: string
16
+ }
12
17
 
13
18
  let isInit = false // 是否初始化
14
19
  let loading = true // 初始化loading
15
20
  let requestPromise: Function[] = [] // 用于存储loading中的计算请求
16
21
 
17
- // 指标线计算后处理
18
- function shiftList(list: any[], n: number) {
19
- let len = list.length
20
- if (n <= 1 || n > len) {
21
- return new Array(len).fill(null)
22
- }
23
- return [...new Array(n - 1).fill(null), ...list.slice(0, len - n + 1)]
24
- }
25
-
26
- // BBI 完成
27
- // BBIROLL
28
- // BOLL
29
- // BTB
30
- // DKX 完成
31
- // DKX_EMA 完成
32
- // DKX_MA 完成
33
- // DKX_STD
34
- // MA 完成
35
- // TQA
36
- // Trade
37
- // ZIG
38
-
39
- // 指标线计算方法
40
- const fnMap: any = {
41
- // 多空线
42
- DKX: (data: InformatData) => {
43
- const { open, close, high, low } = data
44
- const midValue = open.map((item, index) => (close[index] * 3 + high[index] + low[index] + item) / 6)
45
- const { output } = talib.WMA({ inReal: midValue, timePeriod: 20 })
46
- return shiftList(output, 20)
47
- },
48
- // ?
49
- MADKX: (data: InformatData) => {
50
- const { open, close, high, low } = data
51
- const midValue = open.map((item, index) => (close[index] * 3 + high[index] + low[index] + item) / 6)
52
- const DKXData = talib.WMA({ inReal: midValue, timePeriod: 20 })
53
- const { output } = talib.SMA({ inReal: DKXData.output, timePeriod: 10 })
54
- return shiftList(output, 29)
55
- },
56
- // ?
57
- EMA: (data: InformatData, cycle: number): number[] => {
58
- const { close } = data
59
- const { output } = talib.EMA({ inReal: close, timePeriod: cycle })
60
- return shiftList(output, cycle)
61
- },
62
- // ?
63
- EMA30: (data: InformatData): number[] => {
64
- return fnMap.EMA(data, 30)
65
- },
66
- // ?
67
- EMA60: (data: InformatData): number[] => {
68
- return fnMap.EMA(data, 60)
69
- },
70
- // ?
71
- EMA120: (data: InformatData): number[] => {
72
- return fnMap.EMA(data, 120)
73
- },
74
- // ?
75
- EMA240: (data: InformatData): number[] => {
76
- return fnMap.EMA(data, 240)
77
- },
78
- // ?
79
- EMA360: (data: InformatData): number[] => {
80
- return fnMap.EMA(data, 240)
81
- },
82
- // ?
83
- EMA720: (data: InformatData): number[] => {
84
- return fnMap.EMA(data, 240)
85
- },
86
- // ?
87
- HHV: (data: InformatData, cycle: number): number[] => {
88
- const { high } = data
89
- const { output } = talib.MAX({ inReal: high, timePeriod: cycle })
90
- return shiftList(output, cycle)
91
- },
92
- // ?
93
- HHV30: (data: InformatData): number[] => {
94
- return fnMap.HHV(data, 30)
95
- },
96
- // ?
97
- LLV: (data: InformatData, cycle: number): number[] => {
98
- const { high } = data
99
- const { output } = talib.MIN({ inReal: high, timePeriod: cycle })
100
- return shiftList(output, cycle)
101
- },
102
- // ?
103
- LLV30: (data: InformatData): number[] => {
104
- return fnMap.LLV(data, 30)
105
- },
106
- // ?
107
- MA: (data: InformatData, cycle: number): number[] => {
108
- const { close } = data
109
- const { output } = talib.SMA({ inReal: close, timePeriod: cycle })
110
- return shiftList(output, cycle)
111
- },
112
- // ?
113
- MA5: (data: InformatData): number[] => {
114
- return fnMap.MA(data, 5)
115
- },
116
- // ?
117
- MA10: (data: InformatData): number[] => {
118
- return fnMap.MA(data, 10)
119
- },
120
- // ?
121
- MA20: (data: InformatData): number[] => {
122
- return fnMap.MA(data, 20)
123
- },
124
- // ?
125
- MA60: (data: InformatData): number[] => {
126
- return fnMap.MA(data, 60)
127
- },
128
- // ?
129
- BBI: (data: InformatData): number[] => {
130
- const MA3 = fnMap.MA(data, 3)
131
- const MA6 = fnMap.MA(data, 6)
132
- const MA12 = fnMap.MA(data, 12)
133
- const MA24 = fnMap.MA(data, 24)
134
- return MA3.map((item: number, index: number) => {
135
- return (item + MA6[index] + MA12[index] + MA24[index]) / 4
136
- })
137
- },
138
- }
139
-
140
- // 获取指标线数据函数
141
- const getData = (key: string, data: InformatData) => {
142
- if (fnMap[key]) {
143
- return fnMap[key](data)
144
- } else {
145
- return new Array(data.time.length).fill(null)
146
- }
147
- }
148
-
149
- // 数据初始化
22
+ // 返回格式化基础数据
150
23
  const initData = (data: KlineDataItem[]): InformatData => {
151
24
  const time: string[] = []
152
25
  const open: number[] = []
@@ -166,11 +39,6 @@ const initData = (data: KlineDataItem[]): InformatData => {
166
39
  return { time, open, close, high, low, kLineData }
167
40
  }
168
41
 
169
- // 导出数据长度处理
170
- const sliceData = (data: any[], length: number) => {
171
- return data.length > length ? data.slice(data.length - length) : data
172
- }
173
-
174
42
  // 初始化talib
175
43
  const init = async () => {
176
44
  if (!isInit) {
@@ -189,6 +57,20 @@ const init = async () => {
189
57
  }
190
58
  }
191
59
 
60
+ // 导出数据长度处理
61
+ const sliceData = (data: any[], length: number) => {
62
+ return data.length > length ? data.slice(data.length - length) : data
63
+ }
64
+
65
+ // 获取指标线数据函数
66
+ const getData = (item: any, data: InformatData, otherData: InformatData) => {
67
+ if (item.calculationFn) {
68
+ return item.calculationFn(talib, data, otherData)
69
+ } else {
70
+ return new Array(data.time.length).fill(null)
71
+ }
72
+ }
73
+
192
74
  // 主函数
193
75
  const formatKlineData = async (
194
76
  data: KlineDataItem[],
@@ -197,29 +79,30 @@ const formatKlineData = async (
197
79
  ): Promise<InFormatKlineData> => {
198
80
  const formatData: InformatData = initData(data)
199
81
 
82
+ /**
83
+ * @description: 用于提供重叠指标计算的额外K线数据逻辑
84
+ * @throws: 暂时置空数组,因为K线额外数据的请求位置暂定,可能会改成前端计算生成额外K线数据
85
+ */
86
+ let otherFormatData:any = []
87
+ // if(indicatorInfo.showFreq && indicatorInfo.showFreq.includes(freqName) && indicatorInfo.mergeFreq){
88
+
89
+ // }
90
+ otherFormatData = initData(otherFormatData)
91
+
200
92
  await init()
201
93
 
202
94
  return {
203
95
  originData: sliceData(data, totalBarCount),
204
96
  kLine: sliceData(formatData.kLineData, totalBarCount),
205
97
  time: sliceData(formatData.time, totalBarCount),
206
- indicator: Object.keys(indicatorInfo).reduce((res: any[], key: string) => {
207
- let color = 'rgba(238, 238, 238, 0.5)'
208
- if (indicatorInfo[key]) {
209
- color = `#${(indicatorInfo[key] as any).split('#')[1]}`
210
- }
211
- if (key !== 'WINDOW') {
212
- return [
213
- ...res,
214
- {
215
- key,
216
- color,
217
- data: sliceData(getData(key, formatData), totalBarCount),
218
- },
219
- ]
220
- }
221
- return res
222
- }, []),
98
+ indicator: indicatorInfo.config.reduce((result: any[], next: indicatorInfoItemType) => {
99
+ result.push({
100
+ key: next.key,
101
+ color: next.color,
102
+ data: sliceData(getData(next, formatData, otherFormatData), totalBarCount)
103
+ })
104
+ return result
105
+ }, [])
223
106
  }
224
107
  }
225
108
 
@@ -22,14 +22,7 @@
22
22
  const props = defineProps({
23
23
  indicator: {
24
24
  type: Object,
25
- default: () => ({
26
- DKX: 'LINE#FFFFFF',
27
- EMA120: 'LINE#E4007F',
28
- EMA240: 'LINE#999999',
29
- EMA60: 'LINE#00FF00',
30
- MADKX: 'LINE#FFFF00',
31
- WINDOW: '#0',
32
- }),
25
+ default: () => ({}),
33
26
  },
34
27
  klineData: {
35
28
  type: Array,
@@ -166,11 +166,23 @@ export type LineDataType = LineDataItem[]
166
166
 
167
167
  /**
168
168
  * @description: 指标线配置类型
169
+ * @example
170
+ * config: Array 内含哪些指标
171
+ * label: 指标名称
172
+ * mergeFreq: 需要合并的K线周期
173
+ * showFreq: 哪些周期里展示
174
+ * value: 指标名称
169
175
  */
170
176
  export interface IndicatorConfigType {
171
- [key: string]: {
172
- [key: string]: string
173
- }
177
+ config: Array<{
178
+ key: string
179
+ color: string
180
+ calculationFn: Function
181
+ }>
182
+ label: string
183
+ mergeFreq: undefined | string
184
+ showFreq: undefined | string[]
185
+ value: string
174
186
  }
175
187
 
176
188
  /**
@@ -7,7 +7,7 @@ export const getSingleCycleSingleVariety = async (data: any) => {
7
7
  return axios({
8
8
  method: 'post',
9
9
  headers: {
10
- token: 'ee8f92ba3949d0173aaf244542cdcaf2',
10
+ token: '9593c16255001925afeed6dd2770eea7',
11
11
  },
12
12
  url: 'http://192.168.12.49:88/common/qt/getSingleCycleSingleVariety',
13
13
  data,
@@ -21,7 +21,7 @@ export const getMultiCycleSingleVariety = async (data: any) => {
21
21
  return axios({
22
22
  method: 'post',
23
23
  headers: {
24
- token: 'ee8f92ba3949d0173aaf244542cdcaf2',
24
+ token: '9593c16255001925afeed6dd2770eea7',
25
25
  },
26
26
  url: 'http://192.168.12.49:88/common/qt/getMultiCycleSingleVariety',
27
27
  data,
@@ -35,7 +35,7 @@ export const getDict = async (data: any) => {
35
35
  return axios({
36
36
  method: 'post',
37
37
  headers: {
38
- token: 'ee8f92ba3949d0173aaf244542cdcaf2',
38
+ token: '9593c16255001925afeed6dd2770eea7',
39
39
  },
40
40
  url: 'http://192.168.12.49:88/common/qt/getDict',
41
41
  data,
@@ -50,7 +50,7 @@ export const getIndicatorConfig = async () => {
50
50
  return axios({
51
51
  method: 'get',
52
52
  headers: {
53
- token: 'ee8f92ba3949d0173aaf244542cdcaf2',
53
+ token: '9593c16255001925afeed6dd2770eea7',
54
54
  },
55
55
  url: 'http://116.62.161.92:8005/get_indicator'
56
56
  })
@@ -7,7 +7,8 @@
7
7
  import { ElMessage } from 'element-plus'
8
8
  import 'element-plus/dist/index.css'
9
9
  import { formatValue } from '../../../../packages/Kline/utils'
10
- import { getSingleCycleSingleVariety, getDict, getIndicatorConfig } from '../api.ts'
10
+ import { getSingleCycleSingleVariety, getDict } from '../api.ts'
11
+ import { mainIndicatorList } from 'st-func'
11
12
 
12
13
  dayjs.extend(isSameOrAfter)
13
14
 
@@ -37,7 +38,6 @@
37
38
  { label: '开平', value: 1 },
38
39
  { label: '买卖', value: 2 },
39
40
  ])
40
- const indicatorOptions = ref<any>([])
41
41
 
42
42
  // 接口原生-点位数据
43
43
  const originPointData = ref<any>([])
@@ -63,7 +63,6 @@
63
63
  // 初始化
64
64
  const componentInit = async () => {
65
65
  try {
66
- await getIndicatorOptions()
67
66
  await getDictCycle()
68
67
  await getKlineData()
69
68
  await getKlineExtendData()
@@ -90,27 +89,11 @@
90
89
  klineData: [],
91
90
  markData: [],
92
91
  netWorkErrorMsg: '',
93
- indicator: indicatorOptions.value.find((i: any) => i.value === 'DKX_EMA').info,
92
+ indicator: mainIndicatorList.find((i: any) => i.value === 'DKX_EMA'),
94
93
  indicatorName: 'DKX_EMA',
95
94
  }
96
95
  })
97
96
  }
98
- /**
99
- * @description: 获取指标配置表
100
- */
101
- const getIndicatorOptions = async () => {
102
- const res = await getIndicatorConfig()
103
- indicatorOptions.value = Object.keys(res.data).reduce((result: any, key: any) => {
104
- if (res.data[key].WINDOW === '#0') {
105
- result.push({
106
- value: key,
107
- label: key,
108
- info: res.data[key],
109
- })
110
- }
111
- return result
112
- }, [])
113
- }
114
97
  /**
115
98
  * @description: 获取K线数据 / 点位数据
116
99
  */
@@ -313,7 +296,7 @@
313
296
  * @description: 切换指标
314
297
  */
315
298
  const indicatorChange = (item: any) => {
316
- item.indicator = indicatorOptions.value.find((i: any) => i.value === item.indicatorName).info
299
+ item.indicator = mainIndicatorList.find((i: any) => i.value === item.indicatorName)
317
300
  }
318
301
 
319
302
  // 画线预警
@@ -574,7 +557,7 @@
574
557
  @change="indicatorChange(item)"
575
558
  >
576
559
  <el-option
577
- v-for="(item, index) in indicatorOptions"
560
+ v-for="(item, index) in mainIndicatorList"
578
561
  :key="index"
579
562
  :label="item.label"
580
563
  :value="item.value"
@@ -7,7 +7,8 @@
7
7
  import { ElMessage } from 'element-plus'
8
8
  import 'element-plus/dist/index.css'
9
9
  import { formatValue } from '../../../../packages/Kline/utils'
10
- import { getSingleCycleSingleVariety, getDict, getIndicatorConfig } from '../api.ts'
10
+ import { getSingleCycleSingleVariety, getDict } from '../api.ts'
11
+ import { mainIndicatorList } from 'st-func'
11
12
 
12
13
  dayjs.extend(isSameOrAfter)
13
14
 
@@ -31,13 +32,12 @@
31
32
  const cycleOptions = ref<any>([]) // 周期下拉框数据
32
33
 
33
34
  const indicator = computed(() => {
34
- if (indicatorOptions.value.length > 0) {
35
- return indicatorOptions.value.find((item: any) => item.value === indicatorName.value).info
35
+ if (mainIndicatorList.length > 0) {
36
+ return mainIndicatorList.find((item: any) => item.value === indicatorName.value)
36
37
  }
37
38
  return null
38
39
  })
39
40
  const indicatorName = ref<any>('DKX_EMA')
40
- const indicatorOptions = ref<any>([])
41
41
 
42
42
  const sellBuyType = ref(1)
43
43
  const sellBuyTypeName = computed(() => {
@@ -78,7 +78,6 @@
78
78
  const componentInit = async () => {
79
79
  try {
80
80
  loading.value = true
81
- await getIndicatorOptions()
82
81
  await getDictCycle()
83
82
  await getKlineData()
84
83
  await getKlinePointData()
@@ -107,22 +106,6 @@
107
106
  }
108
107
  })
109
108
  }
110
- /**
111
- * @description: 获取指标配置表
112
- */
113
- const getIndicatorOptions = async () => {
114
- const res = await getIndicatorConfig()
115
- indicatorOptions.value = Object.keys(res.data).reduce((result:any,key:any)=>{
116
- if(res.data[key].WINDOW === '#0'){
117
- result.push({
118
- value: key,
119
- label: key,
120
- info: res.data[key]
121
- })
122
- }
123
- return result
124
- },[])
125
- }
126
109
  /**
127
110
  * @description: 获取K线数据
128
111
  */
@@ -498,7 +481,7 @@
498
481
  popper-class="element-dark"
499
482
  >
500
483
  <el-option
501
- v-for="(item, index) in indicatorOptions"
484
+ v-for="(item, index) in mainIndicatorList"
502
485
  :key="index"
503
486
  :label="item.label"
504
487
  :value="item.value"
package/src/vite-env.d.ts CHANGED
@@ -6,3 +6,4 @@ declare module '*.vue' {
6
6
  const component: DefineComponent<{}, {}, any>
7
7
  export default component
8
8
  }
9
+ declare module 'st-func'