j1ack 3 years ago
parent
commit
fdf2e766b0
  1. 13
      components/kline/kline.vue
  2. 11
      components/kline/tradingView/chartConfig.js
  3. 48
      components/kline/tradingView/datafeed.js
  4. 7
      components/kline/tradingView/websocket.js
  5. 3
      static/charting_library/charting_library.js
  6. 2
      static/charting_library/zh-tv-chart.132c7060.html

13
components/kline/kline.vue

@ -160,7 +160,18 @@
'Plot.linewidth': 2, 'Plot.linewidth': 2,
'Plot.color': '#2ba7d6' 'Plot.color': '#2ba7d6'
}) })
widgetObj.chart().createStudy('Moving Average', false, false, [10], null, {
'Plot.linewidth': 2,
'Plot.color': '#98588a'
})
widgetObj.chart().createStudy('Moving Average', false, false, [20], null, {
'Plot.linewidth': 2,
'Plot.color': '#3a714a'
})
widgetObj.chart().createStudy('Moving Average', false, false, [30], null, {
'Plot.linewidth': 2,
'Plot.color': '#965fc4'
})
this.$nextTick(() => { this.$nextTick(() => {
widgetObj.chart().resetData() widgetObj.chart().resetData()
}) })

11
components/kline/tradingView/chartConfig.js

@ -4,7 +4,12 @@ import {
// new UDFCompatibleDatafeed('https://demo-feed-data.tradingview.com') // new UDFCompatibleDatafeed('https://demo-feed-data.tradingview.com')
var chartConfig = { var chartConfig = {
supports_search: false,
supports_group_request: false,
supported_resolutions: ['1', '5', '15', '30', '60', '1D', '1W', '1M'],
supports_marks: true,
supports_timescale_marks: true,
// debug: true, // debug: true,
width: 0, //宽度 width: 0, //宽度
height: 0, //高度 height: 0, //高度
@ -30,9 +35,9 @@ var chartConfig = {
//禁用功能 //禁用功能
disabled_features: [ // 需要屏蔽掉的 参考 https://tradingview.gitee.io/featuresets/ disabled_features: [ // 需要屏蔽掉的 参考 https://tradingview.gitee.io/featuresets/
"widget_logo", //LOGO "widget_logo", //LOGO
"header_resolutions", //"header_resolutions",
"left_toolbar", "left_toolbar",
"header_screenshot", //"header_screenshot",
"header_fullscreen_button", "header_fullscreen_button",
"header_undo_redo", "header_undo_redo",
"header_indicators", "header_indicators",

48
components/kline/tradingView/datafeed.js

@ -15,7 +15,7 @@ import {
// 历史数据 第一条数据的 时间撮 因为k线图一次性历史数据只拿一部分,用户吧图往前滑动,就会用这个时间撮去请求更早的 历史数据 // 历史数据 第一条数据的 时间撮 因为k线图一次性历史数据只拿一部分,用户吧图往前滑动,就会用这个时间撮去请求更早的 历史数据
var detafeed_historyTime = 0 var detafeed_historyTime = null
// 上一次的 K线周期 切换产品的时候 需要从websock 取消订阅这个 // 上一次的 K线周期 切换产品的时候 需要从websock 取消订阅这个
var detafeed_lastResolution = null var detafeed_lastResolution = null
// 上一次的产品 切换产品的时候 需要从websock 取消订阅这个 // 上一次的产品 切换产品的时候 需要从websock 取消订阅这个
@ -32,17 +32,7 @@ FeedBase.prototype.getSendSymbolName = function(symbolName) {
var name = symbolName.split('/') var name = symbolName.split('/')
return (name[0] + name[1]).toLocaleLowerCase() return (name[0] + name[1]).toLocaleLowerCase()
} }
FeedBase.prototype.defaultConfiguration = function defaultConfiguration() {
//设置默认配置
return {
supports_search: false,
supports_group_request: false,
supported_resolutions: ['1', '5', '15', '30', '60', '1D', '1W', '1M'],
supports_marks: false,
supports_timescale_marks: false,
supports_time: true
};
};
FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) { FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) {
onResolve({ onResolve({
"name": symbolName, "name": symbolName,
@ -55,13 +45,18 @@ FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) {
"session": "24x7", "session": "24x7",
"type": "bitcoin", "type": "bitcoin",
"volume_precision": 10, "volume_precision": 10,
"has_intraday": true, "has_intraday": true,
"intraday_multipliers": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间 "seconds_multipliers":['1', '5', '15', '30', '60', '1D', '1W','1M'],
"intraday_multipliers": ['1', '5', '15', '30', '60', '1D', '1W','1M'],
"supports_search": false,
"supports_group_request": false,
"supported_resolutions": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间 "supported_resolutions": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间
"has_seconds":false,
"supports_marks": true, "supports_marks": true,
"supports_timescale_marks": true, "supports_timescale_marks": true,
"supported_time": true, "supported_time": true,
"has_weekly_and_monthly": true, "has_weekly_and_monthly": false,
"has_no_volume": true, "has_no_volume": true,
"regular_session": "24x7", "regular_session": "24x7",
@ -114,14 +109,12 @@ const resolutionFormat = (resolution, name, to) => {
}; };
FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHistoryCallback, onErrorCallback) { FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHistoryCallback, onErrorCallback) {
console.log("获取历史数据") console.log("获取历史数据",periodParams)
// 切换产品周期 或者 切换产品 会执行这个函数 // 切换产品周期 或者 切换产品 会执行这个函数
let reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to > detafeed_historyTime ? periodParams let reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to)
.to : // if (resolution.includes('M') || resolution.includes('W')|| resolution.includes('D')) { // 周线月线控制条数,时间超出火币规定范围, ws报错
detafeed_historyTime) // reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to)
if (resolution.includes('M') || resolution.includes('W')|| resolution.includes('D')) { // 周线月线控制条数,时间超出火币规定范围, ws报错 // }
reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to)
}
// 是历史数据 // 是历史数据
var history = true var history = true
@ -152,10 +145,12 @@ FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHi
fromDate:reso.from, fromDate:reso.from,
toDate:reso.to toDate:reso.to
}, reso.req, history) }, reso.req, history)
Event.off('data') Event.off('data')
Event.on('data', data => { Event.on('data', data => {
if (data && Array.isArray(data)) { if (data && Array.isArray(data)) {
// 记录这次请求的时间周期 // 记录这次请求的时间周期
detafeed_lastResolution = resolution detafeed_lastResolution = resolution
@ -170,13 +165,14 @@ FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHi
i.volume = i.vol i.volume = i.vol
datas.push(i) datas.push(i)
} }
} else { } else {
console.log('进来')
meta = { meta = {
noData: true, noData: 'no_data',
nextTime: detafeed_historyTime nextTime: detafeed_historyTime
} }
} }
onHistoryCallback(datas, meta) onHistoryCallback(datas, {noData:data.length==0})
} }
}) })
} }

7
components/kline/tradingView/websocket.js

@ -84,7 +84,10 @@ var socket = {
}else { }else {
if(resp.event === 'req'){ if(resp.event === 'req'){
Event.emit('data', resp.data) //Event.emit('data', resp.data)
if (resp.data && Array.isArray(resp.data)) {
Event.emit('data', resp.data)
}
this.sendWsRequest({ this.sendWsRequest({
event: 'un_sub', event: 'un_sub',
type: 'kline', type: 'kline',
@ -98,6 +101,8 @@ var socket = {
channel:[this.lastRealTimeData], channel:[this.lastRealTimeData],
}) })
}else{ }else{
Event.emit('realTime', resp.data) Event.emit('realTime', resp.data)
} }

3
static/charting_library/charting_library.js

@ -27,7 +27,8 @@
interval: "1D", interval: "1D",
timezone: "Etc/UTC", timezone: "Etc/UTC",
container: "", container: "",
library_path: "", library_path: "",
locale: "en", locale: "en",
widgetbar: { widgetbar: {
details: !1, details: !1,

2
static/charting_library/zh-tv-chart.132c7060.html

@ -755,7 +755,7 @@
"Save all charts for all symbols and intervals on your layout": "保存布局里的所有图表,包含图表里的全部品种和周期", "Save all charts for all symbols and intervals on your layout": "保存布局里的所有图表,包含图表里的全部品种和周期",
Dot_hotkey: "点", Dot_hotkey: "点",
"Load Chart Layout": "加载图表布局", "Load Chart Layout": "加载图表布局",
minutes_interval: "m", minutes_interval: "分鐘",
hours_interval: "小时", hours_interval: "小时",
days_interval: "日", days_interval: "日",
weeks_interval: "周", weeks_interval: "周",

Loading…
Cancel
Save