st-comp 0.0.44 → 0.0.45

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.
@@ -1,150 +1,111 @@
1
+ import { stMath } from 'st-func'
2
+ const { round } = stMath
3
+
4
+ // 获取主图配置
1
5
  export const getMainOption = (config: any) => {
2
- const { data, showStartTime, showEndTime } = config
3
- const xAxisData: any[] = []
4
- const klineData: any[] = []
6
+ const { showStartTime, showEndTime, drawData, maxShowDays } = config
7
+ const { xAxisData, candlestickData } = drawData
5
8
  let startValue = -1
6
9
  let endValue = -1
7
- data.forEach((item: any, index: number) => {
8
- xAxisData.push(item[0])
9
- klineData.push([ item[1], item[4], item[3], item[2] ])
10
- if (new Date(item[0]) >= new Date(showStartTime) && startValue === -1) {
10
+ let dayPerTime: any = {}
11
+ xAxisData.forEach((time: any, index: number) => {
12
+ dayPerTime[time.split(' ')[0]] = dayPerTime[time.split(' ')[0]] || 0
13
+ dayPerTime[time.split(' ')[0]] += 1
14
+ if (new Date(time) >= new Date(showStartTime) && startValue === -1) {
11
15
  startValue = index
12
16
  }
13
- if (new Date(item[0]) <= new Date(showEndTime)) {
17
+ if (new Date(time) <= new Date(showEndTime)) {
14
18
  endValue = index
15
19
  }
16
20
  })
17
- return {
18
- animation: false,
19
- grid: {
20
- left: '50px',
21
- top: '20px',
22
- right: '20px',
23
- bottom: '20px',
24
- },
25
- dataZoom: [
26
- {
27
- type: 'inside',
28
- realtime: true,
29
- startValue,
30
- endValue,
31
- }
32
- ],
33
- tooltip: {
34
- trigger: "axis",
35
- axisPointer: {
36
- type: "cross",
21
+ const maxShowCount = Math.max(...Object.values(dayPerTime)) * maxShowDays
22
+ const indicatorSeries = drawData.mainIndicatorData.map((item: any) => {
23
+ return {
24
+ name: item.key,
25
+ type: 'line',
26
+ silent: true,
27
+ symbol: 'none',
28
+ data: item.data,
29
+ lineStyle: {
30
+ width: item.width || 1,
37
31
  },
38
- },
39
- xAxis: {
40
- type: 'category',
41
- data: xAxisData
42
- },
43
- yAxis: {
44
- type: 'value',
45
- min: (value: any) => value.min,
46
- max: (value: any) => value.max,
47
- },
48
- series: [
49
- {
50
- type: 'candlestick',
51
- data: klineData,
32
+ itemStyle: {
33
+ color: item.color,
52
34
  }
53
- ]
54
- }
55
- }
56
-
57
- export const getSubOption = (config: any) => {
58
- const { data, showStartTime, showEndTime } = config
59
- const xAxisData: any[] = []
60
- const barData: any[] = []
61
- let startValue = -1
62
- let endValue = -1
63
- data.forEach((item: any, index: number) => {
64
- xAxisData.push(item[0])
65
- barData.push(item[5])
66
- if (new Date(item[0]) >= new Date(showStartTime) && startValue === -1) {
67
- startValue = index
68
- }
69
- if (new Date(item[0]) <= new Date(showEndTime)) {
70
- endValue = index
71
35
  }
72
36
  })
73
37
  return {
74
38
  animation: false,
75
39
  grid: {
76
- left: '50px',
40
+ left: '60px',
77
41
  top: '20px',
78
42
  right: '20px',
79
- bottom: '20px',
43
+ bottom: '6px',
80
44
  },
81
45
  dataZoom: [
82
46
  {
83
47
  type: 'inside',
84
- realtime: true,
85
48
  startValue,
86
49
  endValue,
50
+ maxValueSpan: maxShowCount,
87
51
  }
88
52
  ],
89
53
  tooltip: {
90
- trigger: "axis",
54
+ trigger: 'axis',
55
+ appendToBody: true,
56
+ confine: true,
91
57
  axisPointer: {
92
- type: "cross",
58
+ type: 'cross',
59
+ label: {
60
+ rich: {},
61
+ formatter: data => {
62
+ const { axisDimension, value } = data
63
+ if(axisDimension === 'x') {
64
+ return ''
65
+ } else {
66
+ return String(round(value))
67
+ }
68
+ }
69
+ },
93
70
  },
94
- },
71
+ formatter: () => '',
72
+ },
95
73
  xAxis: {
74
+ show: false,
96
75
  type: 'category',
97
- data: xAxisData
76
+ data: xAxisData,
77
+ splitLine: {
78
+ show: false,
79
+ },
98
80
  },
99
81
  yAxis: {
100
82
  type: 'value',
101
- },
102
- series: [
103
- {
104
- data: barData,
105
- type: 'bar'
106
- }
107
- ]
108
- }
109
- }
110
-
111
- export const getSlideOption = (config: any) => {
112
- const { data, defaultShowDays } = config
113
- const xAxisData = data.map((item: any) => item[0].split(' ')[0])
114
- const lineData = data.map((item: any) => item[4])
115
- return {
116
- grid: {
117
- height: 0,
118
- left: '80px',
119
- right: '80px',
120
- },
121
- dataZoom: [
122
- {
83
+ axisLine: {
123
84
  show: true,
124
- realtime: true,
125
- startValue: data.length - 1 - defaultShowDays,
126
- endValue: data.length - 1,
127
85
  },
128
- {
129
- type: 'inside',
130
- realtime: true,
131
- startValue: data.length - 1 - defaultShowDays,
132
- endValue: data.length - 1,
133
- }
134
- ],
135
- xAxis: {
136
- type: 'category',
137
- data: xAxisData,
138
- show: false,
139
- },
140
- yAxis: {
141
- type: 'value'
86
+ splitLine: {
87
+ show: true,
88
+ lineStyle: {
89
+ type: "dotted",
90
+ color: "#333",
91
+ },
92
+ },
93
+ min: (value: any) => round(value.min),
94
+ max: (value: any) => round(value.max),
142
95
  },
143
96
  series: [
144
97
  {
145
- data: lineData,
146
- type: 'line'
147
- }
98
+ type: 'candlestick',
99
+ data: candlestickData,
100
+ itemStyle: {
101
+ color: "transparent",
102
+ color0: "#00FFFF",
103
+ borderColor: "#FF0000",
104
+ borderColor0: "#00FFFF",
105
+ borderWidth: 1,
106
+ },
107
+ },
108
+ ...indicatorSeries,
148
109
  ]
149
110
  }
150
111
  }
@@ -1,13 +1,156 @@
1
1
  import axios from 'axios'
2
+ import * as talib from 'talib.js'
2
3
 
4
+ // ---------------------------------- 公共方法 ----------------------------------
5
+ // 导出数据长度处理
6
+ const sliceData = (data: any[], length: number) => {
7
+ return data.length > length ? data.slice(data.length - length) : data
8
+ }
9
+
10
+
11
+ // ---------------------------------- 工具方法 ----------------------------------
12
+ // 注册计算指标线方法
13
+ let isInit = false // 是否初始化
14
+ let loading = true // 初始化loading
15
+ let requestPromise: any[] = [] // 用于存储loading中的计算请求
16
+ export const initTalib = async () => {
17
+ if (!isInit) {
18
+ // 未初始化
19
+ isInit = true
20
+ await talib.init('./talib.wasm')
21
+ loading = false
22
+ requestPromise.forEach(resolve => {
23
+ resolve()
24
+ })
25
+ } else if(loading) {
26
+ // 正在初始化
27
+ return new Promise((resolve) => {
28
+ requestPromise.push(resolve)
29
+ })
30
+ }
31
+ }
32
+
33
+ // 默认获取k线参数
3
34
  export const getKlineDataApi = async(params: any) => {
4
35
  const res = await axios({
5
36
  method: 'post',
6
37
  headers: {
7
- token: '78e4d78065e760bb3d0dcc3d442e6a0e',
38
+ token: '041fd377d5d5efc7e08e2ed5b61b0c8d',
8
39
  },
9
- url: 'http://192.168.12.49/common/qt/getSingleCycleSingleVariety',
40
+ url: 'http://invest.hzyotoy.com/common/qt/getSingleCycleSingleVariety',
10
41
  data: params,
11
42
  })
12
43
  return res.data.body
13
- }
44
+ }
45
+
46
+ // 初始化数据
47
+ export const formatData = (formatDataParams: any) => {
48
+ const { originDrawData, addData, params, mainIndicator, mainIndicatorList, subIndicator, subIndicatorList, config, slideData } = formatDataParams
49
+ let drawData: any = {}
50
+ const { startTime, endTime, queryType } = params
51
+ const { loadAddCount, preLoadCount } = config
52
+
53
+ const time: any[] = [] // 新增数据全部时间数据,用于计算指标线
54
+ const open: any[] = [] // 新增数据全部开盘价,用于指标线计算
55
+ const close: any[] = [] // 新增数据全部收盘价,用于指标线计算
56
+ const high: any[] = [] // 新增数据全部最高价,用于指标线计算
57
+ const low: any[] = [] // 新增数据全部最低价,用于指标线计算
58
+ let xAxisData: any[] = [] // 用于绘图的x轴时间数据
59
+ let candlestickData: any[] = [] // 用于绘图的k线图数据
60
+
61
+ const originData = addData.filter((item: any, index: number) => {
62
+ // 赋值
63
+ time.push(item[0])
64
+ open.push(item[1])
65
+ close.push(item[4])
66
+ high.push(item[2])
67
+ low.push(item[3])
68
+ xAxisData.push(item[0])
69
+ candlestickData.push([ item[1], item[4], item[3], item[2], index === 0 ? 0 : addData[index - 1][4] ])
70
+ // 取范围中的数据
71
+ if (queryType === '0') {
72
+ return new Date(startTime) <= new Date(item[0]) && new Date(item[0]) <= new Date(endTime)
73
+ } else if (queryType === '1') {
74
+ return index >= addData.length - loadAddCount && new Date(slideData[0][0]) <= new Date(item[0]) && new Date(item[0]) <= new Date(slideData[slideData.length - 1][0])
75
+ } else if (queryType === '2') {
76
+ return index >= preLoadCount && new Date(slideData[0][0]) <= new Date(item[0]) && new Date(item[0]) <= new Date(slideData[slideData.length - 1][0])
77
+ }
78
+ return false
79
+ })
80
+ xAxisData = sliceData(xAxisData, originData.length)
81
+ candlestickData = sliceData(candlestickData, originData.length)
82
+ // 指标线相关计算
83
+ const indicatorFormatData = { time, open, close, high, low, originData: addData }
84
+ const mainIndicatorConfig = mainIndicatorList.find((item: any) => item.value === mainIndicator).config
85
+ const mainIndicatorData = mainIndicatorConfig.map((item: any) => ({
86
+ ...item,
87
+ data: sliceData(item.calculationFn ? item.calculationFn(talib, indicatorFormatData, []) : [], xAxisData.length),
88
+ }))
89
+ const subIndicatorConfig = subIndicatorList.find((item: any) => item.value === subIndicator).config
90
+ const subIndicatorData = subIndicatorConfig.reduce((res: any[], item: any) => {
91
+ if (item.source === 'calculation') {
92
+ return [
93
+ ...res,
94
+ {
95
+ ...item,
96
+ data: sliceData(item.calculationFn ? item.calculationFn(talib, indicatorFormatData) : [], xAxisData.length)
97
+ }
98
+ ]
99
+ }
100
+ return res
101
+ }, [])
102
+ // 根据不同情况处理数据
103
+ if (queryType === '0') {
104
+ // 重新搜索
105
+ drawData = {
106
+ originData, // 原数据
107
+ xAxisData, // 时间数据
108
+ candlestickData, // k线数据
109
+ mainIndicatorData, // 主图指标线数据
110
+ subIndicatorData, // 副图数据
111
+ }
112
+ } else if (queryType === '1') {
113
+ // 加载历史数据
114
+ drawData = {
115
+ originData: [...originData, ...originDrawData.originData.slice(1)], // 原数据
116
+ xAxisData: [...xAxisData, ...originDrawData.xAxisData.slice(1)], // 时间数据
117
+ candlestickData: [...candlestickData, ...originDrawData.candlestickData.slice(1)], // k线数据
118
+ mainIndicatorData: originDrawData.mainIndicatorData.map((item: any, index: number) => {
119
+ return {
120
+ ...item,
121
+ data: [...mainIndicatorData[index].data, ...item.data.slice(1)],
122
+ }
123
+ }), // 主图指标线数据
124
+ subIndicatorData: originDrawData.subIndicatorData.map((item: any, index: number) => {
125
+ return {
126
+ ...item,
127
+ data: [...subIndicatorData[index].data, ...item.data.slice(1)],
128
+ }
129
+ }), // 副图数据
130
+ }
131
+ } else if (queryType === '2') {
132
+ // 加载新数据
133
+ drawData = {
134
+ originData: [...originDrawData.originData, ...originData.slice(1)], // 原数据
135
+ xAxisData: [...originDrawData.xAxisData, ...xAxisData.slice(1)], // 时间数据
136
+ candlestickData: [...originDrawData.candlestickData, ...candlestickData.slice(1)], // k线数据
137
+ mainIndicatorData: originDrawData.mainIndicatorData.map((item: any, index: number) => {
138
+ return {
139
+ ...item,
140
+ data: [...item.data, ...mainIndicatorData[index].data.slice(1)],
141
+ }
142
+ }), // 主图指标线数据
143
+ subIndicatorData: originDrawData.subIndicatorData.map((item: any, index: number) => {
144
+ return {
145
+ ...item,
146
+ data: [...item.data, ...subIndicatorData[index].data.slice(1)],
147
+ }
148
+ }), // 副图数据
149
+ }
150
+ }
151
+ // 添加一些字段,用于方便使用
152
+ drawData.length = drawData.xAxisData.length
153
+ drawData.startTime = drawData.xAxisData[0]
154
+ drawData.endTime = drawData.xAxisData[drawData.length - 1]
155
+ return drawData
156
+ }
@@ -1,85 +1,127 @@
1
- import axios from 'axios'
1
+ import axios from "axios";
2
+
3
+ /**
4
+ * @description: 通用接口-价差K线数据
5
+ */
6
+ export const getDiffKLine = async (data: any) => {
7
+ return axios({
8
+ method: "post",
9
+ headers: {
10
+ token: "966881cb7da8394afac317fa2c4a040b",
11
+ },
12
+ url: "http://192.168.12.39/common/qt/getDiffKLine",
13
+ data,
14
+ });
15
+ };
16
+
17
+ /**
18
+ * @description: 通用接口-二腿相关度
19
+ */
20
+ export const queryDiffLineRevelance = (data: any) => {
21
+ return axios({
22
+ method: "post",
23
+ headers: {
24
+ token: "966881cb7da8394afac317fa2c4a040b",
25
+ },
26
+ url: "http://192.168.12.39/common/qt/queryDiffLineRevelance",
27
+ data,
28
+ });
29
+ };
30
+
31
+ /**
32
+ * @description: 通用接口-二腿价格走势图
33
+ */
34
+ export const getDiffSubKLine = (data: any) => {
35
+ return axios({
36
+ method: "post",
37
+ headers: {
38
+ token: "966881cb7da8394afac317fa2c4a040b",
39
+ },
40
+ url: "http://192.168.12.39/common/qt/getDiffSubKLine",
41
+ data,
42
+ });
43
+ };
2
44
 
3
45
  /**
4
46
  * @description: 通用接口-单品种单周期K线数据
5
- */
47
+ */
6
48
  export const getSingleCycleSingleVariety = async (data: any) => {
7
49
  return axios({
8
- method: 'post',
50
+ method: "post",
9
51
  headers: {
10
- token: '4b26c72f990a5b02be1a79eb33c1bedf',
52
+ token: "4b26c72f990a5b02be1a79eb33c1bedf",
11
53
  },
12
- url: 'http://120.27.237.138/common/qt/getSingleCycleSingleVariety',
54
+ url: "http://120.27.237.138/common/qt/getSingleCycleSingleVariety",
13
55
  data,
14
- })
15
- }
56
+ });
57
+ };
16
58
 
17
59
  /**
18
60
  * @description: 通用接口-单品种多周期K线数据
19
- */
61
+ */
20
62
  export const getMultiCycleSingleVariety = async (data: any) => {
21
63
  return axios({
22
- method: 'post',
64
+ method: "post",
23
65
  headers: {
24
- token: '9593c16255001925afeed6dd2770eea7',
66
+ token: "9593c16255001925afeed6dd2770eea7",
25
67
  },
26
- url: 'http://192.168.12.49:88/common/qt/getMultiCycleSingleVariety',
68
+ url: "http://192.168.12.49:88/common/qt/getMultiCycleSingleVariety",
27
69
  data,
28
- })
29
- }
70
+ });
71
+ };
30
72
 
31
73
  /**
32
74
  * @description: 通用接口-字典
33
- */
75
+ */
34
76
  export const getDict = async (data: any) => {
35
77
  return axios({
36
- method: 'post',
78
+ method: "post",
37
79
  headers: {
38
- token: '9593c16255001925afeed6dd2770eea7',
80
+ token: "9593c16255001925afeed6dd2770eea7",
39
81
  },
40
- url: 'http://192.168.12.49:88/common/qt/getDict',
82
+ url: "http://192.168.12.49:88/common/qt/getDict",
41
83
  data,
42
- })
43
- }
84
+ });
85
+ };
44
86
 
45
87
  /**
46
88
  * @description: 获取指标配置表
47
89
  * 后续会通过前端函数库进行自维护获取,而不是依赖接口拉表
48
- */
90
+ */
49
91
  export const getIndicatorConfig = async () => {
50
92
  return axios({
51
- method: 'get',
93
+ method: "get",
52
94
  headers: {
53
- token: '9593c16255001925afeed6dd2770eea7',
95
+ token: "9593c16255001925afeed6dd2770eea7",
54
96
  },
55
- url: 'http://116.62.161.92:8005/get_indicator'
56
- })
57
- }
97
+ url: "http://116.62.161.92:8005/get_indicator",
98
+ });
99
+ };
58
100
 
59
101
  /**
60
102
  * @description: 获取净值曲线
61
- */
103
+ */
62
104
  export const getNetPositionData = async (data: any) => {
63
105
  return axios({
64
- method: 'post',
106
+ method: "post",
65
107
  headers: {
66
- token: '4b26c72f990a5b02be1a79eb33c1bedf',
108
+ token: "4b26c72f990a5b02be1a79eb33c1bedf",
67
109
  },
68
- url: 'http://120.27.237.138/invest/analysis/queryVarietyNetPositionValue',
69
- data
70
- })
71
- }
110
+ url: "http://120.27.237.138/invest/analysis/queryVarietyNetPositionValue",
111
+ data,
112
+ });
113
+ };
72
114
 
73
115
  /**
74
116
  * @description: 绩效-获取需要连线多笔的买卖点数据
75
- */
117
+ */
76
118
  export const queryPairedRecordByVariety = async (data: any) => {
77
119
  return axios({
78
- method: 'post',
120
+ method: "post",
79
121
  headers: {
80
- token: '4b26c72f990a5b02be1a79eb33c1bedf',
122
+ token: "4b26c72f990a5b02be1a79eb33c1bedf",
81
123
  },
82
- url: 'http://120.27.237.138/invest/analysis/queryPairedRecordByVariety',
83
- data
84
- })
85
- }
124
+ url: "http://120.27.237.138/invest/analysis/queryPairedRecordByVariety",
125
+ data,
126
+ });
127
+ };