j1ack 3 years ago
parent
commit
7339e1f32d
  1. 10
      components/kline/kline.vue
  2. 22
      components/kline/tradingView/datafeed.js
  3. 14
      components/kline/tradingView/websocket.js
  4. 10
      pages/markets/kLine.vue
  5. 18
      utils/websocket.js

10
components/kline/kline.vue

@ -117,15 +117,15 @@
}, },
methods: { methods: {
setSymbol(symbol){ setSymbol(symbol){
console.log(symbol) //console.log(symbol)
this.chartSymbol=symbol this.chartSymbol=symbol
}, },
setWidth(width) { setWidth(width) {
console.log("可用窗口宽度:", width) //console.log(":", width)
this.chartWidth = width this.chartWidth = width
}, },
setHeight(height) { setHeight(height) {
console.log("可用窗口高度:", height) //console.log(":", height)
this.chartHeight = 300 this.chartHeight = 300
}, },
changindex_activeCycle(index_activeCycle){ changindex_activeCycle(index_activeCycle){
@ -147,12 +147,12 @@
chartConfig.height = this.chartHeight chartConfig.height = this.chartHeight
chartConfig.time_frames=[] chartConfig.time_frames=[]
// TradingView // TradingView
console.log(window.TradingView.version()) //console.log(window.TradingView.version())
widgetObj = new widget(chartConfig) widgetObj = new widget(chartConfig)
console.log(11111,widgetObj) //console.log(11111,widgetObj)
widgetObj._options.interval=5 widgetObj._options.interval=5
widgetObj.onChartReady(() => { widgetObj.onChartReady(() => {
// k线 7线30线 // k线 7线30线

22
components/kline/tradingView/datafeed.js

@ -48,15 +48,11 @@ FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) {
"has_intraday": true, "has_intraday": true,
"seconds_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'], "intraday_multipliers": ['1', '5', '15', '30', '60', '1D', '1W','1M'],
"supports_search": false, "has_seconds":true,
"supports_group_request": false,
"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": false, "has_weekly_and_monthly": true,
"has_no_volume": true, "has_no_volume": true,
"regular_session": "24x7", "regular_session": "24x7",
@ -74,7 +70,7 @@ FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) {
const resolutionFormat = (resolution, name, to) => { const resolutionFormat = (resolution, name, to) => {
let req = `market.${name}.kline.${resolution}min`; let req = `market.${name}.kline.${resolution}min`;
let minutes = resolution; let minutes = resolution;
console.log(resolution) //console.log(resolution)
if (resolution.includes('D')) { if (resolution.includes('D')) {
if (resolution.length < 2) resolution = '1' + resolution; if (resolution.length < 2) resolution = '1' + resolution;
req = `market.${name}.kline.${parseInt(resolution)}day`; req = `market.${name}.kline.${parseInt(resolution)}day`;
@ -100,6 +96,7 @@ const resolutionFormat = (resolution, name, to) => {
from = to - 50 * minutes * 500; from = to - 50 * minutes * 500;
} }
} }
return { return {
minutes, minutes,
req, req,
@ -109,12 +106,11 @@ 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("获取历史数据",periodParams) //console.log("获取历史数据",periodParams)
// 切换产品周期 或者 切换产品 会执行这个函数 // 切换产品周期 或者 切换产品 会执行这个函数
let reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to) let reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to > detafeed_historyTime ? periodParams
// if (resolution.includes('M') || resolution.includes('W')|| resolution.includes('D')) { // 周线月线控制条数,时间超出火币规定范围, ws报错 .to :
// reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to) detafeed_historyTime)
// }
// 是历史数据 // 是历史数据
var history = true var history = true
@ -166,7 +162,7 @@ FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHi
datas.push(i) datas.push(i)
} }
} else { } else {
console.log('进来') //console.log('进来')
meta = { meta = {
noData: 'no_data', noData: 'no_data',
nextTime: detafeed_historyTime nextTime: detafeed_historyTime

14
components/kline/tradingView/websocket.js

@ -30,8 +30,8 @@ var socket = {
// 如果不是订阅历史产品 那么肯定就是切换周期咯 或者切换产品咯 // 如果不是订阅历史产品 那么肯定就是切换周期咯 或者切换产品咯
// 那么就订阅一下 这次产品的或者周期的 实时数据 // 那么就订阅一下 这次产品的或者周期的 实时数据
if (!history) { if (!history) {
console.log('订阅新的' + realTimeDatas) //console.log('订阅新的' + realTimeDatas)
console.log(111111,realTimeDatas) //console.log(111111,realTimeDatas)
this.sendWsRequest({ this.sendWsRequest({
event: 'un_sub', event: 'un_sub',
type: 'kline', type: 'kline',
@ -65,12 +65,12 @@ var socket = {
} }
}, },
error(err) { error(err) {
console.log(err, 'depth-socket::error') //console.log(err, 'depth-socket::error')
}, },
close() { close() {
// 如果websocket关闭的话,就从新打开一下。 // 如果websocket关闭的话,就从新打开一下。
this.initWs() this.initWs()
console.log('depth-socket::close') //console.log('depth-socket::close')
}, },
message(resp) { message(resp) {
resp=JSON.parse(resp.data) resp=JSON.parse(resp.data)
@ -126,7 +126,7 @@ var socket = {
} }
if (i >= checkTimes) { if (i >= checkTimes) {
clearInterval(this.intervalObj) clearInterval(this.intervalObj)
console.log('send post_data_str timeout.') //console.log('send post_data_str timeout.')
} }
}, 500) }, 500)
}, },
@ -139,13 +139,13 @@ var socket = {
this.socket.send(JSON.stringify(options)) this.socket.send(JSON.stringify(options))
break break
case 2: case 2:
console.log('ws关闭状态') //console.log('ws关闭状态')
break break
case 3: case 3:
this.initWs() this.initWs()
break break
default: default:
console.log('ws未知错误') //console.log('ws未知错误')
} }
} }
} }

10
pages/markets/kLine.vue

@ -129,7 +129,7 @@
}, },
onLoad() { onLoad() {
//this.kdata = this.splitData(ktest.JSON); //this.kdata = this.splitData(ktest.JSON);
// console.log(this.kdata, 1111) // //console.log(this.kdata, 1111)
// //
@ -182,7 +182,7 @@
uni.navigateTo({ uni.navigateTo({
url, url,
fail(err) { fail(err) {
console.log(err) //console.log(err)
} }
}) })
}, },
@ -242,12 +242,12 @@
"symbol": this.symbol.symbol "symbol": this.symbol.symbol
}); });
bboList.then(res => { bboList.then(res => {
// console.log(9999999, res) // //console.log(9999999, res)
this.bboList = res this.bboList = res
this.statisticsSum(); this.statisticsSum();
}) })
.catch(e => { .catch(e => {
// console.log(e) // //console.log(e)
uni.showToast({ uni.showToast({
title: e, title: e,
icon: 'none', icon: 'none',
@ -264,7 +264,7 @@
}) })
.catch(e => { .catch(e => {
// console.log(e) // //console.log(e)
uni.showToast({ uni.showToast({
title: e, title: e,
icon: 'none', icon: 'none',

18
utils/websocket.js

@ -39,7 +39,7 @@ class WebSocketClass {
this.ws = uni.connectSocket({ this.ws = uni.connectSocket({
url: this.wsUrl, url: this.wsUrl,
success(data) { success(data) {
console.log('websocket连接成功'); //console.log('websocket连接成功');
that.initEventHandle(); that.initEventHandle();
}, },
@ -58,13 +58,13 @@ class WebSocketClass {
// #ifdef H5 // #ifdef H5
this.ws.onopen = (event) => { this.ws.onopen = (event) => {
console.log('WebSocket连接打开'); //console.log('WebSocket连接打开');
}; };
// #endif // #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
this.ws.onOpen(res => { this.ws.onOpen(res => {
console.log('WebSocket连接打开'); //console.log('WebSocket连接打开');
}); });
// #endif // #endif
@ -151,10 +151,10 @@ class WebSocketClass {
this.ws && this.ws.send({ this.ws && this.ws.send({
data: JSON.stringify(msg), data: JSON.stringify(msg),
success() { success() {
console.log('消息发送成功',msg); //console.log('消息发送成功',msg);
}, },
fail(err) { fail(err) {
console.log('关闭失败', err) //console.log('关闭失败', err)
} }
}); });
// #endif // #endif
@ -177,10 +177,10 @@ class WebSocketClass {
// #ifdef APP-PLUS // #ifdef APP-PLUS
this.ws.close({ this.ws.close({
success(res) { success(res) {
console.log('关闭成功', res) //console.log('关闭成功', res)
}, },
fail(err) { fail(err) {
console.log('关闭失败', err) //console.log('关闭失败', err)
} }
}); });
// #endif // #endif
@ -189,7 +189,7 @@ class WebSocketClass {
} }
writeToScreen(massage) { writeToScreen(massage) {
console.log(massage); //console.log(massage);
} }
subLatest() { subLatest() {
@ -278,7 +278,7 @@ class WebSocketClass {
} }
publicSend(event, type, channel, date) { publicSend(event, type, channel, date) {
console.log(this.id) //console.log(this.id)
var data = { var data = {
event: event, event: event,
type: type, type: type,

Loading…
Cancel
Save