Browse Source

k线优化

master
vee 3 years ago
parent
commit
a1c9c90767
  1. 117
      components/kline/kline.vue
  2. 4
      components/kline/tradingView/chartConfig.js
  3. 18
      components/kline/tradingView/datafeed.js
  4. 9
      components/kline/tradingView/websocket.js
  5. 2
      utils/language/vi_VN.js

117
components/kline/kline.vue

@ -1,8 +1,26 @@
<template>
<view>
<view>
<view class="tab">
<view class="item" :class="{ select: type === '1min' }" @click="onChangeType('1min')">1min
</view>
<view class="item" :class="{ select: type === '5min' }" @click="onChangeType('5min')">5min
</view>
<view class="item" :class="{ select: type === '15min' }" @click="onChangeType('15min')">15min
</view>
<view class="item" :class="{ select: type === '30min' }" @click="onChangeType('30min')">30min
</view>
<view class="item" :class="{ select: type === '60min' }" @click="onChangeType('60min')">60min
</view>
<view class="item" :class="{ select: type === '1day' }" @click="onChangeType('1day')">1day
</view>
<view class="item" :class="{ select: type === '1week' }" @click="onChangeType('1week')">1week
</view>
<view class="item" :class="{ select: type === '1mon' }" @click="onChangeType('1mon')">1mon
</view>
</view>
<view id="kline" :windowWidth="width" :change:windowWidth="KlineJs.setWidth" :windowHeight="height"
:change:windowHeight="KlineJs.setHeight" :symbol="symbol"
:change:symbol="KlineJs.setSymbol"></view>
:change:symbol="KlineJs.setSymbol" :index_activeCycle="index_activeCycle" :change:index_activeCycle="KlineJs.changindex_activeCycle"></view>
</view>
</template>
@ -13,11 +31,59 @@
mixins: [props],
data() {
return {
type:'1min',
index_activeCycle:1
};
},
created() {
}
,methods: {
onChangeType(type) {
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('1min')">1min
// </view>
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('5min')">5min
// </view>
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('15min')">15min
// </view>
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('30min')">30min
// </view>
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('60min')">60min
// </view>
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('1day')">1day
// </view>
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('1week')">1week
// </view>
// <view class="item" :class="{ select: type === '' }" @click="onChangeType('1mon')">1mon
// </view>
this.type = type
switch(type){
case '1min':
this.index_activeCycle=1;
break;
case '5min':
this.index_activeCycle=5;
break;
case '15min':
this.index_activeCycle=15;
break;
case '30min':
this.index_activeCycle=30;
break;
case '60min':
this.index_activeCycle=60;
break;
case '1day':
this.index_activeCycle='1D';
break;
case '1week':
this.index_activeCycle='1W';
break;
case '1mon':
this.index_activeCycle='1M';
break;
}
},
}
}
</script>
@ -34,8 +100,6 @@
var widgetObj = null
//
var index_market = 'btcusdt'
//
var index_activeCycle = '1'
export default {
data() {
@ -48,7 +112,7 @@
//renderjs
mounted() {
//
this.initChart()
this.initChart("1")
},
methods: {
setSymbol(symbol){
@ -62,17 +126,21 @@
setHeight(height) {
console.log("可用窗口高度:", height)
this.chartHeight = 300
},
initChart() {
},
changindex_activeCycle(index_activeCycle){
this.initChart(index_activeCycle)
}
,
initChart(index_activeCycle) {
// chartConfig chartConfig.js
// chartConfig
chartConfig.interval = index_activeCycle
chartConfig.intervals = ['1','5']
chartConfig.interval = index_activeCycle
// chartConfig
chartConfig.symbol = this.symbol
//
chartConfig.width = this.chartWidth
chartConfig.height = this.chartHeight
chartConfig.height = this.chartHeight
chartConfig.time_frames=[]
// TradingView
console.log(window.TradingView.version())
const language = uni.getStorageSync("language")|| 'en_US';
@ -84,7 +152,8 @@
widgetObj = new widget(chartConfig)
console.log(widgetObj)
console.log(11111,widgetObj)
widgetObj._options.interval=5
widgetObj.onChartReady(() => {
// k线 7线30线
widgetObj.chart().createStudy('Moving Average', false, false, [5], null, {
@ -100,5 +169,27 @@
}
}
</script>
</script>
<style lang="scss" scoped>
.tab {
display: flex;
background: #000000;
.item {
height: 64rpx;
line-height: 64rpx;
flex: 1;
font-size: 24rpx;
text-align: center;
&.select {
background: rgba(0, 232, 162, 0.3);
border-radius: 19px;
}
}
}
</style>

4
components/kline/tradingView/chartConfig.js

@ -13,7 +13,8 @@ var chartConfig = {
fullscreen: false, //布尔值显示图表是否占用窗口中所有可用的空间。
//如果上面参数开启会影响到宽高项
timeframe: '1',
timezone: "Asia/Bangkok",
timezone: "Asia/Bangkok",
intervals: ['1', '5', '15', '30', '60', '1D', '1W', '1M'],
container: "kline",
datafeed: new FeedBase(),
library_path: "./static/charting_library/",
@ -29,6 +30,7 @@ var chartConfig = {
//禁用功能
disabled_features: [ // 需要屏蔽掉的 参考 https://tradingview.gitee.io/featuresets/
"widget_logo", //LOGO
"header_resolutions",
"left_toolbar",
"header_screenshot",
"header_fullscreen_button",

18
components/kline/tradingView/datafeed.js

@ -58,11 +58,11 @@ FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) {
"has_intraday": true,
"intraday_multipliers": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间
"supported_resolutions": ['1', '5', '15', '30', '60', '1D', '1W','1M'], // 时间
"supports_marks": false,
"supports_timescale_marks": false,
"supports_marks": true,
"supports_timescale_marks": true,
"supported_time": true,
"has_weekly_and_monthly": false,
"has_no_volume": false,
"has_weekly_and_monthly": true,
"has_no_volume": true,
"regular_session": "24x7",
})
@ -100,9 +100,9 @@ const resolutionFormat = (resolution, name, to) => {
let from = null;
if (to) {
from = to - 50 * minutes * 60;
from = to - 50 * minutes * 500;
if (resolution.includes('M') || resolution.includes('W')) { // 周线月线控制条数,时间超出火币规定范围, ws报错
from = to - 50 * minutes * 60;
from = to - 50 * minutes * 500;
}
}
return {
@ -118,7 +118,11 @@ FeedBase.prototype.getBars = function(symbolInfo, resolution, periodParams, onHi
// 切换产品周期 或者 切换产品 会执行这个函数
let reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to > detafeed_historyTime ? periodParams
.to :
detafeed_historyTime)
detafeed_historyTime)
if (resolution.includes('M') || resolution.includes('W')) { // 周线月线控制条数,时间超出火币规定范围, ws报错
reso = resolutionFormat(resolution, symbolInfo.name, periodParams.to)
}
// 是历史数据
var history = true
/*

9
components/kline/tradingView/websocket.js

@ -83,13 +83,20 @@ var socket = {
}else {
if(resp.event === 'req'){
Event.emit('data', resp.data)
this.sendWsRequest({
event: 'un_sub',
type: 'kline',
id: this.id,
channel:[this.lastRealTimeData],
})
this.sendWsRequest({
event: 'sub',
type: 'kline',
id: this.id,
channel:[this.lastRealTimeData],
})
Event.emit('data', resp.data)
}else{
Event.emit('realTime', resp.data)

2
utils/language/vi_VN.js

@ -81,7 +81,7 @@ export default {
customerService: 'dịch vụ trực tuyến',
homeMessage: 'Vui lòng liên hệ với dịch vụ khách hàng ở góc trên bên trái để xác minh danh tính Vui lòng liên hệ với dịch vụ khách hàng ở góc trên bên trái để xác minh danh tính ...',
Recharge: 'nạp điện',
Mine: 'khai thác mỏ',
Mine: 'của tôi',
Subcription: 'Đăng ký',
Order: 'Gọi món',
TodaySteps: 'các bước hôm nay',

Loading…
Cancel
Save