Browse Source

完善推送

master
vee 3 years ago
parent
commit
05ca8ab4d6
  1. 26
      components/positionList/positionList.vue
  2. 8
      components/transaction/transaction.vue
  3. 10
      pages/markets/index.vue
  4. 568
      pages/markets/kLine.vue
  5. 358
      pages/markets/trade.vue
  6. 6
      utils/axios.js
  7. 2
      utils/language/en_US.js
  8. 25
      utils/websocket.js

26
components/positionList/positionList.vue

@ -6,9 +6,9 @@
</view>
<view class="sell">
<view class="item" v-for="(item, index) in bboList.sell" :key="index" @click="depthClick(item)">
<text class="price">{{ item.price }}</text>
<text class="num">{{ item.total }}</text>
<view class="sellbg" :style="`width: ${20 * index}%;`"></view>
<text class="price">{{ parseFloat(item.price).toFixed(item.baseCoinScale) }}</text>
<text class="num">{{ item.size }}</text>
<view class="sellbg" :style="`width: ${item.size/sum.sell*100 }%;`"></view>
</view>
</view>
<view class="currentPriceBody" @click="depthClick(item)">
@ -18,9 +18,9 @@
<view class="buy">
<view class="item" v-for="(item, index) in bboList.buy" :key="index" @click="depthClick(item)">
<text class="price">{{ item.price }}</text>
<text class="num">{{ item.total }}</text>
<view class="buybg" :style="`width: ${20 * index}%;`"></view>
<text class="price">{{ parseFloat(item.price).toFixed(item.baseCoinScale) }}</text>
<text class="num">{{ item.size }}</text>
<view class="buybg" :style="`width: ${item.size/sum.buy*100 }%;`"></view>
</view>
</view>
@ -33,7 +33,15 @@ export default {
item: Object,
marketDetail: {
type: Object,
default: () => {}
default: () => {
}
},
sum: {
type: Object,
default: () => {
}
},
bboList:{
type: Object,
@ -43,9 +51,7 @@ export default {
data() {
return {
popoverVisible: false,
depthValue: 1,
sellList: 9,
buyList: 10,
}
},
computed: {

8
components/transaction/transaction.vue

@ -86,6 +86,12 @@ export default {
return 'USDT'
}
},
type: { //
type: String,
default() {
return 'buy'
}
},
coinPrice: { //
type: Number,
default() {
@ -107,7 +113,7 @@ export default {
},
data() {
return {
type: 'buy',
priceSelectListShow: false,
priceTypeValue: 0,
priceTypeList: [

10
pages/markets/index.vue

@ -43,11 +43,11 @@
onShow() {
},
onHide() {
this.unsubWebSocket();
},
onUnload() {
this.unsubWebSocket();
onHide() {
this.websock.closeSocket();
},
onUnload() {
this.websock.closeSocket();
},
computed: {
i18n() {

568
pages/markets/kLine.vue

@ -1,41 +1,48 @@
<template>
<view class="main">
<!-- nav -->
<navigation>{{ 'BTC/USDT' }}</navigation>
<navigation>{{ symbol.pair }}</navigation>
<!-- 价格百分比 -->
<view class="header">
<view class="top">
<!-- 实时价格 -->
<text class="price">34985.93</text>
<text class="price">{{parseFloat(marketDetail.close).toFixed(marketDetail.baseCoinScale)}}</text>
<!-- 百分比,根据数据正负判断颜色 -->
<text class="percent" :class="{ rise: false }">-15.30%</text>
<text class="percent"
:class="{ rise: marketDetail.percent>=0 }">{{marketDetail.percent>=0?'+'+marketDetail.percent:marketDetail.percent}}%</text>
</view>
<view class="bottom">
<view class="left">
<view class="title">{{ i18n.Highest }}</view>
<view class="value">45930.24</view>
<view class="value">{{marketDetail.high}}</view>
</view>
<view class="center">
<view class="title">{{ i18n.Lowest }}</view>
<view class="value">45930.24</view>
<view class="value">{{marketDetail.low}}</view>
</view>
<view class="right">
<view class="title">{{ i18n.Amount }}</view>
<view class="value">28394893.30943094</view>
<view class="value">{{marketDetail.amount}}</view>
</view>
</view>
</view>
<view class="tab">
<view class="item" :class="{ select: type === 0 }" @click="onChangeType(0)">1M
</view>
<view class="item" :class="{ select: type === 1 }" @click="onChangeType(1)">30M
</view>
<view class="item" :class="{ select: type === 2 }" @click="onChangeType(2)">60M
</view>
<view class="item" :class="{ select: type === 3 }" @click="onChangeType(3)">1D
</view>
<view class="item" :class="{ select: type === 3 }" @click="onChangeType(3)">30D
</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>
<!-- K线图 -->
<view class="kline" id="kline" :kdata="kdata" :change:kdata="klineE.receive"
@ -52,23 +59,23 @@
<view class="price">{{ i18n.BuyingPrice }}</view>
</view>
<view class="list">
<view class="item" v-for="(item, index) in buyList" :key="index">
<text class="price">0.87897874</text>
<text class="num buy">{{ item }}</text>
<view class="buybg" :style="`width: ${20 * index}%;`"></view>
<view class="item" v-for="(item, index) in bboList.buy" :key="index">
<text class="price">{{parseFloat(item.size).toFixed(6)}}</text>
<text class="num buy">{{ item.price }}</text>
<view class="buybg" :style="`width: ${item.size/sum.buy*100 }%;`"></view>
</view>
</view>
</view>
<view class="box">
<view class="title">
<view class="quantity">{{ i18n.Quantity }}</view>
<view class="price">{{ i18n.SellPrice20 }}</view>
<view class="price">{{ i18n.SellPrice }}</view>
</view>
<view class="list">
<view class="item" v-for="(item, index) in sellList" :key="index">
<text class="price">0.87897874</text>
<text class="num sell">{{ item }}</text>
<view class="sellbg" :style="`width: ${20 * index}%;`"></view>
<view class="item" v-for="(item, index) in bboList.sell" :key="index">
<text class="price">{{parseFloat(item.size).toFixed(6)}}</text>
<text class="num sell">{{ item.price }}</text>
<view class="sellbg" :style="`width: ${item.size/sum.sell*100 }%;`"></view>
</view>
</view>
@ -78,11 +85,11 @@
<view class="btn">
<!-- open按钮 -->
<u-button class="button" color="#00E8A2" throttleTime="500" @click="openBtnClick">
<u-button class="button" color="#00E8A2" throttleTime="500" @click="btnClick('buy')">
{{ i18n.open }}
</u-button>
<!-- close按钮 -->
<u-button class="button" color="#F4506A" throttleTime="500" @click="closeBtnClick">
<u-button class="button" color="#F4506A" throttleTime="500" @click="btnClick('sell')">
{{ i18n.close }}
</u-button>
</view>
@ -99,10 +106,16 @@
},
data() {
return {
buyList: 7,
sellList: 9,
kdata: [],
type:1
kdata: {},
type: '1min',
symbol: null,
marketDetail: {
close: 0,
usdRate: 0
},
bboList: {},
webSocketChannel: {},
sum: {}
};
},
@ -112,12 +125,283 @@
},
},
onLoad() {
this.kdata = this.splitData(ktest.JSON);
//this.kdata = this.splitData(ktest.JSON);
// console.log(this.kdata, 1111)
},
onShow() {},
methods: {
onShow() {
this.into();
},
onHide() {
this.websock.closeSocket();
},
onUnload() {
this.websock.closeSocket();
},
methods: {
into() {
this.symbol = uni.getStorageSync('symbol');
if (!this.symbol) {
// #ifdef H5
history.back()
// #endif
// #ifdef APP-PLUS
uni.navigateBack()
// #endif
}
this.getMarketDetail();
this.initWebSocket();
this.getBboList()
},
statisticsSum() {
this.sum.buy = 0
this.sum.sell = 0
console.log(this.sum.buy);
for (var buy in this.bboList.buy) {
if (buy >= 8) {
break;
}
this.sum.buy += parseFloat(this.bboList.buy[buy].size)
}
for (var sell in this.bboList.sell) {
if (sell >= 8) {
break;
}
this.sum.sell += parseFloat(this.bboList.sell[sell].size)
}
},
onChangeType(type) {
this.unsubkline();
this.type = type
this.subKHistory()
this.subkline();
},
formateDate(time) {
var date = new Date(parseInt(time * 1000));
var Y = date.getFullYear();
var M = '-' + (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
var D = '-' + date.getDate();
var h = ' ' + date.getHours();
var m = ':' + date.getMinutes();
var s = ':' + date.getSeconds();
var time;
if (this.type.indexOf('min') > -1) {
time = Y + M + D + h + m;
} else if (this.type === '1day' || this.type === '1week') {
time = Y + M + D;
} else {
time = Y + M;
}
return time;
},
getBboList() {
const bboList = this.$api.bboList({
"symbol": this.symbol.symbol
});
bboList.then(res => {
console.log(9999999,res)
this.bboList = res
this.statisticsSum();
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
getMarketDetail() {
const marketDetail = this.$api.marketDetail({
"symbol": this.symbol.symbol
});
marketDetail.then(res => {
this.marketDetail = res
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
initWebSocket() {
this.websock = new this.$websocket(this.$constant.WSSURL) // xxx URL
var that = this
this.websock.getWebSocketMsg(data => {
if (data.channel === 'conn') {
that.websockId = data.data
that.subbbo()
that.submarketDetail()
that.subKHistory()
that.subkline();
} else if (data.channel === 'market.pairsgroup') {
that.symbolList = data.data.USDT;
} else if (data.channel === that.webSocketChannel.bbo) {
that.bboList = data.data;
} else if (data.channel === that.webSocketChannel.bbo) {
that.bboList = data.data;
that.statisticsSum();
} else if (data.channel === that.webSocketChannel.trade) {
that.tradeList = data.data;
} else if (data.channel === that.webSocketChannel.detail) {
that.marketDetail = data.data;
} else if (data.channel === that.webSocketChannel.kline) {
if (data.event === 'req') {
that.kdata = that.splitData(data.data)
} else {
that.upkline(data.data)
}
}
});
},
//
subKHistory() {
var toDate = parseInt(new Date().getTime() / 1000);
var num = 100000;
var fromDate = parseInt(new Date().getTime() / 1000);
switch (this.type) {
case '1min':
fromDate = fromDate - num;
break;
case '5min':
fromDate = fromDate - (5 * num);
break;
case '15min':
fromDate = fromDate - (15 * num);
break;
case '30min':
fromDate = fromDate - (30 * num);
break;
case '60min':
fromDate = fromDate - (60 * num);
break;
case '1day':
fromDate = fromDate - (60 * 24 * num);
break;
case '1week':
fromDate = fromDate - (60 * 24 * 7 * num);
break;
case '1mon':
fromDate = fromDate - (60 * 24 * 30 * num);
break;
}
this.webSocketChannel.kline = 'market.' + this.symbol.symbol + ".kline." + this.type;
const data = {
event: 'req',
type: 'kline',
id: this.websockId,
channel: [this.webSocketChannel.kline],
fromDate: parseInt(fromDate),
toDate: toDate
};
this.websock.webSocketSendMsg(data)
},
subkline() {
this.webSocketChannel.kline = 'market.' + this.symbol.symbol + ".kline." + this.type;
const data = {
event: 'sub',
type: 'kline',
id: this.websockId,
channel: [this.webSocketChannel.kline],
};
this.websock.webSocketSendMsg(data)
},
unsubkline() {
this.webSocketChannel.kline = 'market.' + this.symbol.symbol + ".kline." + this.type;
const data = {
event: 'un_sub',
type: 'kline',
id: this.websockId,
channel: [this.webSocketChannel.kline],
};
this.websock.webSocketSendMsg(data)
},
upkline(data) {
if (data.id === this.kdata.values[this.kdata.values.length - 1][5]) {
this.kdata.values.pop();
this.kdata.volumes.pop();
this.kdata.values.push([data.open, data.close, data.low, data.high, data.kTime, data.id]);
this.kdata.volumes.push([this.kdata.volumes.length, data.high, data.open > data.close ? 1 : -1])
} else {
this.kdata.values.push([data.open, data.close, data.low, data.high, data.kTime, data.id]);
this.kdata.volumes.push([this.kdata.volumes.length, this.kdata.volumes.length, data.high, data.open >
data.close ? 1 : -1
])
this.kdata.categoryData.push(this.formateDate(data.kTime));
}
},
subbbo() {
this.webSocketChannel.bbo = 'market.' + this.symbol.symbol + ".bbo";
this.subWebSocket('bbo', [this.webSocketChannel.bbo])
},
unsubbbo() {
this.unsubWebSocket('bbo', [this.webSocketChannel.bbo])
},
subtrade() {
this.webSocketChannel.trade = 'market.' + this.symbol.symbol + ".trade";
this.subWebSocket('trade', [this.webSocketChannel.trade])
},
unsubtrade() {
this.unsubWebSocket('trade', [this.webSocketChannel.trade])
},
submarketDetail() {
this.webSocketChannel.detail = 'market.' + this.symbol.symbol + ".detail";
this.subWebSocket('detail', [this.webSocketChannel.detail])
},
unsubmarketDetail() {
this.unsubWebSocket('detail', [this.webSocketChannel.detail])
},
subWebSocket(type, channel) {
const data = {
event: 'sub',
type: type,
id: this.websockId,
channel: channel
};
this.websock.webSocketSendMsg(data)
console.log("websocket发送", data);
},
unsubWebSocket(type, channel) {
const data = {
event: 'un_sub',
type: type,
id: this.websockId,
channel: channel
};
this.websock.webSocketSendMsg(data)
},
splitData(rawData) {
@ -125,15 +409,20 @@
let values = [];
let volumes = [];
for (let i = 0; i < rawData.length; i++) {
categoryData.push(rawData[i].splice(0, 1)[0]);
values.push(rawData[i]);
volumes.push([i, rawData[i][4], rawData[i][0] > rawData[i][1] ? 1 : -1]);
var ldata = rawData[i];
categoryData.push(this.formateDate(ldata.kTime));
values.push([ldata.open, ldata.close, ldata.low, ldata.high, ldata.kTime, ldata.id]);
volumes.push([i, ldata.high, ldata.open > ldata.close ? 1 : -1]);
}
return {
categoryData: categoryData,
values: values,
volumes: volumes
volumes: volumes,
webSocketChannel: this.webSocketChannel.kline
};
},
depthChange(e) {
console.log(e);
@ -150,19 +439,16 @@
uni.navigateTo({
url,
});
},
openBtnClick(){
// let categoryData = [];
// let values = [];
// let volumes = [];
// this.kdata.values.pop();
// this.kdata.volumes.pop();
this.kdata.values.push([17827.33+Math.floor(Math.random()*100),
17829.73+Math.floor(Math.random()*100),
17799.8+Math.floor(Math.random()*100),
17877.84+Math.floor(Math.random()*100) , 85130000+Math.floor(Math.random()*100)])
this.kdata.volumes.push([3140,1688777777,1])
this.kdata.categoryData.push('2016-06-22')
},
btnClick(type) {
uni.setStorageSync('orderType',type);
// #ifdef H5
history.back()
// #endif
// #ifdef APP-PLUS
uni.navigateBack()
// #endif
}
},
@ -172,7 +458,7 @@
let kline
export default {
mounted() {
console.log('1111', this.kdata.categoryData);
if (typeof window.echarts === 'function') {
//this.initEcharts()
} else {
@ -187,16 +473,20 @@
},
methods: {
receive(newValue, oldValue, ownerVm, vm) {
console.log('newValue', newValue)
receive(newValue, oldValue, ownerVm, vm) {
if (this.channel != newValue.webSocketChannel) {
this.is = false
}
this.channel = newValue.webSocketChannel
const script = document.createElement('script');
// view www www
script.src = './static/echarts.js';
script.onload = this.upData.bind(this);
document.head.appendChild(script);
},
calculateMA(dayCount, data) {
@ -217,12 +507,13 @@
upData(myChart) {
const upColor = '#00C873';
const downColor = '#FF3750';
var chartDom = document.getElementById('kline');
if(!this.is){
this.myChart = echarts.init(chartDom);
var chartDom = document.getElementById('kline');
if (!this.is) {
console.log("this.is11111111", this.is)
this.myChart = echarts.init(chartDom);
}
this.is=true;
this.is = true;
var option;
this.myChart.setOption(
(option = {
@ -245,8 +536,8 @@
axisLine: {
show: false,
onZero: false
},
},
axisTick: {
show: false
},
@ -280,12 +571,12 @@
max: 'dataMax'
}
],
yAxis: [{
scale: true,
axisLine: {
yAxis: [{
position: 'right',
scale: true,
axisLine: {
show: false
},
axisTick: {
@ -326,7 +617,7 @@
visualMap: {
show: false,
seriesIndex: 1,
seriesIndex: 5,
dimension: 2,
pieces: [{
value: 1,
@ -338,17 +629,17 @@
}
]
},
grid: [{
top: '8%',
left: '50rpx',
right: '10rpx',
height: '60%',
grid: [{
top: '8%',
left: '10rpx',
right: '50rpx',
height: '60%',
backgroundColor: 'transparent',
},
{
left: '0%',
right: '0%',
left: '10rpx',
right: '50rpx',
top: '80%',
height: '16%'
}
@ -369,7 +660,7 @@
}
],
series: [{
name: 'Dow-Jones index',
type: 'candlestick',
data: this.kdata.values,
itemStyle: {
@ -377,19 +668,20 @@
color0: downColor,
borderColor: undefined,
borderColor0: undefined
},
markLine: {
symbol: ['none', 'none'],
data: [
{
name: 'max line on close',
type: 'max',
valueDim: 'close'
}
]
},
},
markLine: {
symbol: ['none', 'none'],
data: [
{
name: 'max line on close',
type: 'max',
valueDim: 'highest'
}
]
},
tooltip: {
formatter: function(param) {
param = param[0];
@ -404,6 +696,47 @@
}
}
},
{
name: 'MA5',
type: 'line',
showSymbol: false,
data: this.calculateMA(5, this.kdata),
smooth: true,
lineStyle: {
opacity: 0.5
}
},
{
name: 'MA10',
type: 'line',
showSymbol: false,
data: this.calculateMA(10, this.kdata),
smooth: true,
lineStyle: {
opacity: 0.5
}
},
{
name: 'MA20',
type: 'line',
showSymbol: false,
data: this.calculateMA(20, this.kdata),
smooth: true,
lineStyle: {
opacity: 0.5
}
},
{
name: 'MA30',
type: 'line',
showSymbol: false,
data: this.calculateMA(30, this.kdata),
smooth: true,
lineStyle: {
opacity: 0.5
}
},
{
name: 'Volume',
type: 'bar',
@ -419,8 +752,8 @@
]
}),
true
);
);
}
},
watch: {
@ -498,26 +831,29 @@
}
}
.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;
}
}
.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;
}
}
}
.kline {
background: #000000;
}
@ -533,7 +869,7 @@
display: flex;
font-size: 24rpx;
.box {
.box {
padding-left: 32rpx;
flex: 1;
overflow: hidden;

358
pages/markets/trade.vue

@ -7,10 +7,11 @@
</navigation>
<view class="content">
<view class="transactionSide">
<transaction></transaction>
<transaction :coin="symbol.coinSymbol" :type="type" :currency="symbol.baseSymbol"></transaction>
</view>
<view class="positionSide">
<positionList v-on:depthChange="depthChange" :marketDetail="marketDetail" :bboList="bboList"></positionList>
<positionList v-on:depthChange="depthChange" :sum="sum" :marketDetail="marketDetail" :bboList="bboList">
</positionList>
</view>
</view>
<view class="orderList">
@ -54,84 +55,115 @@
return {
popupShow: false,
symbolList: [],
symbol: null,
marketDetail:null,
bboList:{},
tradeList:{},
webSocketChannel:{}
symbol: {},
marketDetail: {
close: 0,
usdRate: 0
},
bboList: {},
type:'buy',
webSocketChannel: {},
sum:{}
};
},
computed: {
i18n() {
return this.$t("markets");
},
},
onHide() {
this.websock.closeSocket();
},
onUnload() {
this.websock.closeSocket();
},
onLoad() {
onLoad() {
},
onShow() {
this.getSymbolGroup();
this.initWebSocket();
this.symbol=uni.getStorageSync('symbol');
if(this.symbol!=null){
this.symbol = uni.getStorageSync('symbol');
if (this.symbol) {
this.getMarketDetail()
this.getBboList();
this.getTradeList();
}
},
onShow() {
console.log(11111, uni.getStorageSync('symbol'));
}
this.type=uni.getStorageSync('orderType');
console.log(this.type)
this.type=this.type?this.type:'buy';
uni.removeStorageSync('orderType');
},
methods: {
getTradeList(){
const tradeList = this.$api.tradeList({
"symbol": this.symbol.symbol
});
tradeList.then(res => {
this.tradeList = res
statisticsSum(){
this.sum.buy=0
this.sum.sell=0
console.log(this.sum.buy);
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
getBboList(){
const bboList = this.$api.bboList({
"symbol": this.symbol.symbol
});
bboList.then(res => {
this.bboList = res
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
getMarketDetail(){
const marketDetail = this.$api.marketDetail({
"symbol": this.symbol.symbol
});
marketDetail.then(res => {
this.marketDetail = res
for(var buy in this.bboList.buy){
if(buy>=5){
break;
}
this.sum.buy+=parseFloat(this.bboList.buy[buy].size)
}
for(var sell in this.bboList.sell){
if(sell>=5){
break;
}
this.sum.sell+=parseFloat(this.bboList.sell[sell].size)
}
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
getTradeList() {
const tradeList = this.$api.tradeList({
"symbol": this.symbol.symbol
});
tradeList.then(res => {
this.tradeList = res
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
getBboList() {
const bboList = this.$api.bboList({
"symbol": this.symbol.symbol
});
bboList.then(res => {
this.bboList = res
this.statisticsSum()
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
getMarketDetail() {
const marketDetail = this.$api.marketDetail({
"symbol": this.symbol.symbol
});
marketDetail.then(res => {
this.marketDetail = res
})
.catch(e => {
console.log(e)
uni.showToast({
title: e,
icon: 'none',
duration: 2500
})
})
},
getSymbolGroup() {
const symbolGroup = this.$api.symbolGroup({
@ -139,8 +171,13 @@
});
symbolGroup.then(res => {
this.symbolList = res.USDT
if(this.symbol==null){
this.symbol=this.symbolList[0]
this.symbol = uni.getStorageSync('symbol');
if (!this.symbol) {
this.symbol = this.symbolList[0]
this.getMarketDetail()
this.getBboList();
this.switchTo(this.symbol);
}
})
@ -155,90 +192,90 @@
},
initWebSocket() {
this.websock = new this.$websocket(this.$constant.WSSURL) // xxx URL
var that = this
this.websock.getWebSocketMsg(data => {
if (data.channel === 'conn') {
that.websockId = data.data
that.subpairsgroup()
that.subbbo()
that.subtrade()
that.submarketDetail()
} else if (data.channel === 'market.pairsgroup') {
that.symbolList = data.data.USDT;
}else if (data.channel === that.webSocketChannel.bbo) {
that.bboList = data.data;
}else if (data.channel === that.webSocketChannel.bbo) {
},
initWebSocket() {
this.websock = new this.$websocket(this.$constant.WSSURL) // xxx URL
var that = this
this.websock.getWebSocketMsg(data => {
if (data.channel === 'conn') {
that.websockId = data.data
that.subpairsgroup()
that.subbbo()
that.submarketDetail()
} else if (data.channel === 'market.pairsgroup') {
that.symbolList = data.data.USDT;
} else if (data.channel === that.webSocketChannel.bbo) {
that.bboList = data.data;
} else if (data.channel === that.webSocketChannel.bbo) {
that.bboList = data.data;
}else if(data.channel === that.webSocketChannel.trade){
that.tradeList=data.data;
}else if(data.channel === that.webSocketChannel.detail){
that.marketDetail=data.data;
}
});
},
//
subpairsgroup(){
this.subWebSocket('pairsgroup',['market.pairsgroup'])
},
//
unsubpairsgroup(){
this.unsubWebSocket('pairsgroup',['market.pairsgroup'])
},
subbbo(){
this.webSocketChannel.bbo='market.'+this.symbol.symbol+".bbo";
this.subWebSocket('bbo',[this.webSocketChannel.bbo])
},
unsubbbo(){
this.unsubWebSocket('bbo',[this.webSocketChannel.bbo])
},
subtrade(){
this.webSocketChannel.trade='market.'+this.symbol.symbol+".trade";
this.subWebSocket('trade',[this.webSocketChannel.trade])
},
unsubtrade(){
this.unsubWebSocket('trade',[this.webSocketChannel.trade])
},
submarketDetail(){
this.webSocketChannel.detail='market.'+this.symbol.symbol+".detail";
this.subWebSocket('detail',[this.webSocketChannel.detail])
},
unsubmarketDetail(){
this.unsubWebSocket('detail',[this.webSocketChannel.detail])
},
subWebSocket(type,channel) {
const data = {
event: 'sub',
type: type,
id: this.websockId,
channel: channel
};
this.websock.webSocketSendMsg(data)
console.log("websocket发送", data);
},
unsubWebSocket(type,channel) {
const data = {
event: 'un_sub',
type: type,
id: this.websockId,
channel: channel
};
this.websock.webSocketSendMsg(data)
that.statisticsSum();
} else if (data.channel === that.webSocketChannel.trade) {
that.tradeList = data.data;
} else if (data.channel === that.webSocketChannel.detail) {
that.marketDetail = data.data;
}
});
},
//
subpairsgroup() {
this.subWebSocket('pairsgroup', ['market.pairsgroup'])
},
//
unsubpairsgroup() {
this.unsubWebSocket('pairsgroup', ['market.pairsgroup'])
},
subbbo() {
this.webSocketChannel.bbo = 'market.' + this.symbol.symbol + ".bbo";
this.subWebSocket('bbo', [this.webSocketChannel.bbo])
},
unsubbbo() {
this.unsubWebSocket('bbo', [this.webSocketChannel.bbo])
},
subtrade() {
this.webSocketChannel.trade = 'market.' + this.symbol.symbol + ".trade";
this.subWebSocket('trade', [this.webSocketChannel.trade])
},
unsubtrade() {
this.unsubWebSocket('trade', [this.webSocketChannel.trade])
},
submarketDetail() {
this.webSocketChannel.detail = 'market.' + this.symbol.symbol + ".detail";
this.subWebSocket('detail', [this.webSocketChannel.detail])
},
unsubmarketDetail() {
this.unsubWebSocket('detail', [this.webSocketChannel.detail])
},
subWebSocket(type, channel) {
const data = {
event: 'sub',
type: type,
id: this.websockId,
channel: channel
};
this.websock.webSocketSendMsg(data)
console.log("websocket发送", data);
},
unsubWebSocket(type, channel) {
const data = {
event: 'un_sub',
type: type,
id: this.websockId,
channel: channel
};
this.websock.webSocketSendMsg(data)
},
depthChange(e) {
console.log(e);
@ -260,18 +297,15 @@
* 切换当前交易货币对
*/
switchTo(item) {
this.popupShow = false;
this.unsubbbo()
this.unsubtrade()
this.unsubmarketDetail()
this.symbol=item;
uni.setStorageSync('symbol',this.symbol);
this.getMarketDetail()
this.getBboList();
this.getTradeList();
this.subbbo()
this.subtrade()
this.popupShow = false;
this.unsubbbo()
this.unsubmarketDetail()
this.symbol = item;
uni.setStorageSync('symbol', this.symbol);
this.getMarketDetail()
this.getBboList();
this.subbbo()
this.submarketDetail()
}

6
utils/axios.js

@ -132,10 +132,10 @@ service.interceptors.request.use(
//配置成功后的拦截器
service.interceptors.response.use(res => {
console.log('过期了吗', res)
uni.hideLoading()
uni.hideLoading()
res=res.data;
console.log('11111', res)
// console.log(res)
// console.log(res.data)
// console.log(res.data.data[0].nameAlias)

2
utils/language/en_US.js

@ -141,7 +141,7 @@ export default {
MarketTrades:'Market Trades',
Quantity:'Quantity',
BuyingPrice:'Buying Price',
SellPrice20:'Sell Price20',
SellPrice:'Sell Price',
open:'Open',
},

25
utils/websocket.js

@ -165,15 +165,22 @@ class WebSocketClass {
// 关闭ws方法
closeSocket() {
if (this.ws) {
this.userClose = true;
this.ws.close({
success(res) {
console.log("关闭成功", res)
},
fail(err) {
console.log("关闭失败", err)
}
});
this.userClose = true;
// #ifdef H5
this.ws && this.ws.close();
// #endif
// #ifdef APP-PLUS
this.ws.close({
success(res) {
console.log("关闭成功", res)
},
fail(err) {
console.log("关闭失败", err)
}
});
// #endif
}
}

Loading…
Cancel
Save