st-comp 0.0.16 → 0.0.17

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.
@@ -2,12 +2,12 @@ import * as talib from 'talib.js'
2
2
  import type { KlineDataItem, IndicatorConfigType, InFormatKlineData } from './type.d.ts'
3
3
 
4
4
  interface InformatData {
5
- time: string[];
6
- open: number[];
7
- close: number[];
8
- high: number[];
9
- low: number[];
10
- kLineData: [number, number, number, number][];
5
+ time: string[]
6
+ open: number[]
7
+ close: number[]
8
+ high: number[]
9
+ low: number[]
10
+ kLineData: [number, number, number, number, number, number][]
11
11
  }
12
12
 
13
13
  let isInit = false // 是否初始化
@@ -16,14 +16,11 @@ let requestPromise: Function[] = [] // 用于存储loading中的计算请求
16
16
 
17
17
  // 指标线计算后处理
18
18
  function shiftList(list: any[], n: number) {
19
- let len = list.length;
20
- if (n <= 1 || n > len){
19
+ let len = list.length
20
+ if (n <= 1 || n > len) {
21
21
  return new Array(len).fill(null)
22
22
  }
23
- return [
24
- ...new Array(n - 1).fill(null),
25
- ...list.slice(0, len - n + 1)
26
- ]
23
+ return [...new Array(n - 1).fill(null), ...list.slice(0, len - n + 1)]
27
24
  }
28
25
 
29
26
  // BBI 完成
@@ -44,14 +41,14 @@ const fnMap: any = {
44
41
  // 多空线
45
42
  DKX: (data: InformatData) => {
46
43
  const { open, close, high, low } = data
47
- const midValue = open.map((item, index) => (close[index] * 3 + high[index] + low[index] + item) / 6);
44
+ const midValue = open.map((item, index) => (close[index] * 3 + high[index] + low[index] + item) / 6)
48
45
  const { output } = talib.WMA({ inReal: midValue, timePeriod: 20 })
49
46
  return shiftList(output, 20)
50
47
  },
51
48
  // ?
52
49
  MADKX: (data: InformatData) => {
53
50
  const { open, close, high, low } = data
54
- const midValue = open.map((item, index) => (close[index] * 3 + high[index] + low[index] + item) / 6);
51
+ const midValue = open.map((item, index) => (close[index] * 3 + high[index] + low[index] + item) / 6)
55
52
  const DKXData = talib.WMA({ inReal: midValue, timePeriod: 20 })
56
53
  const { output } = talib.SMA({ inReal: DKXData.output, timePeriod: 10 })
57
54
  return shiftList(output, 29)
@@ -156,14 +153,15 @@ const initData = (data: KlineDataItem[]): InformatData => {
156
153
  const close: number[] = []
157
154
  const high: number[] = []
158
155
  const low: number[] = []
159
- const kLineData: [number, number, number, number][] = []
160
- data.forEach(item => {
156
+ // 成交额 昨收
157
+ const kLineData: [number, number, number, number, number, number][] = []
158
+ data.forEach((item,index) => {
161
159
  time.push(item[0])
162
160
  open.push(item[1])
163
161
  close.push(item[4])
164
162
  high.push(item[2])
165
163
  low.push(item[3])
166
- kLineData.push([item[1], item[4], item[3], item[2]])
164
+ kLineData.push([item[1], item[4], item[3], item[2], item[6], index === 0 ? item[4] : data[index - 1][4]])
167
165
  })
168
166
  return { time, open, close, high, low, kLineData }
169
167
  }
@@ -174,7 +172,7 @@ const sliceData = (data: any[], length: number) => {
174
172
  }
175
173
 
176
174
  // 初始化talib
177
- const init = async() => {
175
+ const init = async () => {
178
176
  if (!isInit) {
179
177
  // 未初始化
180
178
  isInit = true
@@ -183,7 +181,7 @@ const init = async() => {
183
181
  requestPromise.forEach(resolve => {
184
182
  resolve()
185
183
  })
186
- } else if(loading) {
184
+ } else if (loading) {
187
185
  // 正在初始化
188
186
  return new Promise((resolve: Function) => {
189
187
  requestPromise.push(resolve)
@@ -192,7 +190,11 @@ const init = async() => {
192
190
  }
193
191
 
194
192
  // 主函数
195
- const formatKlineData = async (data: KlineDataItem[], indicatorInfo: IndicatorConfigType, totalBarCount: number): Promise<InFormatKlineData> => {
193
+ const formatKlineData = async (
194
+ data: KlineDataItem[],
195
+ indicatorInfo: IndicatorConfigType,
196
+ totalBarCount: number
197
+ ): Promise<InFormatKlineData> => {
196
198
  const formatData: InformatData = initData(data)
197
199
 
198
200
  await init()
@@ -212,8 +214,8 @@ const formatKlineData = async (data: KlineDataItem[], indicatorInfo: IndicatorCo
212
214
  {
213
215
  key,
214
216
  color,
215
- data: sliceData(getData(key, formatData), totalBarCount)
216
- }
217
+ data: sliceData(getData(key, formatData), totalBarCount),
218
+ },
217
219
  ]
218
220
  }
219
221
  return res
@@ -221,4 +223,4 @@ const formatKlineData = async (data: KlineDataItem[], indicatorInfo: IndicatorCo
221
223
  }
222
224
  }
223
225
 
224
- export default formatKlineData
226
+ export default formatKlineData
@@ -114,31 +114,44 @@
114
114
  const option = ref<any>(null) // 处理后的echarts配置
115
115
  const activeIndex = ref(-1) // 当前鼠标激活的数据索引
116
116
 
117
- // Tips: 开, 高, 低,
117
+ // Tips: [开, 收, 低, 高, 成交额, 昨收]
118
118
  const kLineTips = computed(() => {
119
119
  if (option.value && option.value.dataset[0]?.source?.klineData[activeIndex.value]) {
120
120
  const klineItem = option.value.dataset[0].source.klineData[activeIndex.value]
121
+ // 计算涨跌比
122
+ let ratio = (((klineItem[1] - klineItem[5]) / klineItem[1]) * 100).toFixed(2)
123
+ let ratioColor = +ratio === 0.0 ? 'white' : +ratio > 0 ? 'red' : '#00ff00'
121
124
  return [
122
125
  {
123
126
  label: '开',
124
- value: klineItem[1],
127
+ value: klineItem[0],
125
128
  color: 'rgb(153, 153, 153)',
126
129
  },
127
130
  {
128
131
  label: '高',
129
- value: klineItem[2],
132
+ value: klineItem[3],
130
133
  color: 'rgb(153, 153, 153)',
131
134
  },
132
135
  {
133
136
  label: '低',
134
- value: klineItem[3],
137
+ value: klineItem[2],
135
138
  color: 'rgb(153, 153, 153)',
136
139
  },
137
140
  {
138
141
  label: '收',
139
- value: klineItem[4],
142
+ value: klineItem[1],
140
143
  color: 'rgb(153, 153, 153)',
141
144
  },
145
+ {
146
+ label: '额',
147
+ value: formatPrice(klineItem[4]),
148
+ color: 'rgb(153, 153, 153)',
149
+ },
150
+ {
151
+ label: '涨跌',
152
+ value: `${ratio}%`,
153
+ color: ratioColor,
154
+ },
142
155
  ]
143
156
  }
144
157
  return []
@@ -150,7 +163,7 @@
150
163
  next.data[activeIndex.value] &&
151
164
  result.push({
152
165
  label: next.key,
153
- value: formatPrice(next.data[activeIndex.value]),
166
+ value: (next.data[activeIndex.value]).toFixed(2),
154
167
  color: next.color,
155
168
  })
156
169
  return result
@@ -73,7 +73,7 @@ export const getOption = async (
73
73
  dataset: {
74
74
  id: 'data',
75
75
  source: {
76
- klineData: originData,
76
+ klineData: kLine,
77
77
  indicatorData: indicator,
78
78
  },
79
79
  },
@@ -7,7 +7,7 @@ export const getSingleCycleSingleVariety = async (data: any) => {
7
7
  return axios({
8
8
  method: 'post',
9
9
  headers: {
10
- token: '49d4a41f8776c86d36dd560969117785',
10
+ token: 'ee8f92ba3949d0173aaf244542cdcaf2',
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: '49d4a41f8776c86d36dd560969117785',
24
+ token: 'ee8f92ba3949d0173aaf244542cdcaf2',
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: '49d4a41f8776c86d36dd560969117785',
38
+ token: 'ee8f92ba3949d0173aaf244542cdcaf2',
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: '49d4a41f8776c86d36dd560969117785',
53
+ token: 'ee8f92ba3949d0173aaf244542cdcaf2',
54
54
  },
55
55
  url: 'http://116.62.161.92:8005/get_indicator'
56
56
  })
@@ -80,7 +80,7 @@
80
80
  dictIds: [1002],
81
81
  }
82
82
  const res = await getDict(params)
83
- multiCycleKline.value = res.data[1002].map((item: any) => {
83
+ multiCycleKline.value = res.data.body[1002].map((item: any) => {
84
84
  return {
85
85
  loading: true,
86
86
  cycle: Number(item.dictCode),
@@ -99,7 +99,7 @@
99
99
  dictIds: [1002],
100
100
  }
101
101
  const res = await getDict(params)
102
- cycleOptions.value = res.data[1002].map((item: any) => {
102
+ cycleOptions.value = res.data.body[1002].map((item: any) => {
103
103
  return {
104
104
  label: item.dictName,
105
105
  value: item.dictCode,