diff --git a/components/kline/kline.vue b/components/kline/kline.vue index 5398a17..2c6fcd1 100644 --- a/components/kline/kline.vue +++ b/components/kline/kline.vue @@ -160,7 +160,18 @@ 'Plot.linewidth': 2, '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(() => { widgetObj.chart().resetData() }) diff --git a/components/kline/tradingView/chartConfig.js b/components/kline/tradingView/chartConfig.js index 7a0f4c1..e29ad8b 100644 --- a/components/kline/tradingView/chartConfig.js +++ b/components/kline/tradingView/chartConfig.js @@ -4,7 +4,12 @@ import { // 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, width: 0, //宽度 height: 0, //高度 @@ -30,9 +35,9 @@ var chartConfig = { //禁用功能 disabled_features: [ // 需要屏蔽掉的 参考 https://tradingview.gitee.io/featuresets/ "widget_logo", //LOGO - "header_resolutions", + //"header_resolutions", "left_toolbar", - "header_screenshot", + //"header_screenshot", "header_fullscreen_button", "header_undo_redo", "header_indicators", diff --git a/components/kline/tradingView/datafeed.js b/components/kline/tradingView/datafeed.js index 2bd0b45..4f4059e 100644 --- a/components/kline/tradingView/datafeed.js +++ b/components/kline/tradingView/datafeed.js @@ -15,7 +15,7 @@ import { // 历史数据 第一条数据的 时间撮 因为k线图一次性历史数据只拿一部分,用户吧图往前滑动,就会用这个时间撮去请求更早的 历史数据 -var detafeed_historyTime = 0 +var detafeed_historyTime = null // 上一次的 K线周期 切换产品的时候 需要从websock 取消订阅这个 var detafeed_lastResolution = null // 上一次的产品 切换产品的时候 需要从websock 取消订阅这个 @@ -32,17 +32,7 @@ FeedBase.prototype.getSendSymbolName = function(symbolName) { var name = symbolName.split('/') 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) { onResolve({ "name": symbolName, @@ -55,13 +45,18 @@ FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) { "session": "24x7", "type": "bitcoin", "volume_precision": 10, - "has_intraday": true, - "intraday_multipliers": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间 + "has_intraday": true, + "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'], // 时间 + + "has_seconds":false, "supports_marks": true, "supports_timescale_marks": true, "supported_time": true, - "has_weekly_and_monthly": true, + "has_weekly_and_monthly": false, "has_no_volume": true, "regular_session": "24x7", @@ -114,14 +109,12 @@ const resolutionFormat = (resolution, name, to) => { }; 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 - .to : - detafeed_historyTime) - if (resolution.includes('M') || resolution.includes('W')|| resolution.includes('D')) { // 周线月线控制条数,时间超出火币规定范围, ws报错 - reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to) - } + let 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 @@ -152,10 +145,12 @@ FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHi fromDate:reso.from, toDate:reso.to }, reso.req, history) + Event.off('data') - Event.on('data', data => { + Event.on('data', data => { + if (data && Array.isArray(data)) { // 记录这次请求的时间周期 detafeed_lastResolution = resolution @@ -170,13 +165,14 @@ FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHi i.volume = i.vol datas.push(i) } - } else { + } else { + console.log('进来') meta = { - noData: true, + noData: 'no_data', nextTime: detafeed_historyTime } } - onHistoryCallback(datas, meta) + onHistoryCallback(datas, {noData:data.length==0}) } }) } diff --git a/components/kline/tradingView/websocket.js b/components/kline/tradingView/websocket.js index b50c591..42bdd77 100644 --- a/components/kline/tradingView/websocket.js +++ b/components/kline/tradingView/websocket.js @@ -84,7 +84,10 @@ var socket = { }else { 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({ event: 'un_sub', type: 'kline', @@ -98,6 +101,8 @@ var socket = { channel:[this.lastRealTimeData], }) }else{ + + Event.emit('realTime', resp.data) } diff --git a/static/charting_library/charting_library.js b/static/charting_library/charting_library.js index 85a0a05..f8e69df 100644 --- a/static/charting_library/charting_library.js +++ b/static/charting_library/charting_library.js @@ -27,7 +27,8 @@ interval: "1D", timezone: "Etc/UTC", container: "", - library_path: "", + library_path: "", + locale: "en", widgetbar: { details: !1, diff --git a/static/charting_library/zh-tv-chart.132c7060.html b/static/charting_library/zh-tv-chart.132c7060.html index 01546e7..37a6078 100644 --- a/static/charting_library/zh-tv-chart.132c7060.html +++ b/static/charting_library/zh-tv-chart.132c7060.html @@ -755,7 +755,7 @@ "Save all charts for all symbols and intervals on your layout": "保存布局里的所有图表,包含图表里的全部品种和周期", Dot_hotkey: "点", "Load Chart Layout": "加载图表布局", - minutes_interval: "m", + minutes_interval: "分鐘", hours_interval: "小时", days_interval: "日", weeks_interval: "周",