Browse Source

新增股票

master
liaoxinyu 3 weeks ago
parent
commit
bb732a1be0
  1. 5
      api/market.js
  2. 9
      layout/vButton.vue
  3. 24
      pages/base/stockexchange-operation.vue
  4. 216
      pages/stockexchange/exchange-transaction.vue
  5. 1
      pages/stockexchange/index.vue
  6. 48
      pages/stockexchange/symbol-list.vue

5
api/market.js

@ -65,7 +65,10 @@ class Market {
static getstockCoinInfo(data){ static getstockCoinInfo(data){
return Serve.get(`/stock/getCoinInfo`,data) return Serve.get(`/stock/getCoinInfo`,data)
} }
// 是否显示颜色
static getstocktradingOpen(data){
return Serve.get(`/stock/tradingOpen`,data)
}
} }
export default Market; export default Market;

9
layout/vButton.vue

@ -205,4 +205,13 @@ export default {
border-radius:inherit; border-radius:inherit;
} }
} }
.colorless {
::v-deep uni-button {
background: #999999;
color: #fff;
border:none;
border-radius:inherit;
box-shadow: 0px 0px 15px 0px rgba(199, 199, 199, 0.7);
}
}
</style> </style>

24
pages/base/stockexchange-operation.vue

@ -68,7 +68,7 @@
<symbol-list <symbol-list
:collect="collect" :collect="collect"
:marketList="marketList" :marketList="marketList"
:heyue="0" :heyue="2"
@check-symbol="checkSymbol" @check-symbol="checkSymbol"
:symbols="symbols" :symbols="symbols"
/> />
@ -98,10 +98,6 @@ export default {
type: String, type: String,
required: false, required: false,
}, },
stocksymbol: {
default: '',
type: String
}
}, },
components: { components: {
exchangeTransaction, exchangeTransaction,
@ -126,15 +122,14 @@ export default {
watch: { watch: {
isShow(n) { isShow(n) {
if (n) { if (n) {
this.query = { symbol: this.stocksymbol };
setTimeout(() => { setTimeout(() => {
this.ws.send({ this.ws2.send({
cmd: "sub", cmd: "sub",
msg: this.msg, msg: this.msg,
}); });
}, 200); }, 200);
} else { } else {
this.ws.send({ this.ws2.send({
cmd: "unsub", cmd: "unsub",
msg: this.msg, msg: this.msg,
}); });
@ -143,7 +138,7 @@ export default {
}, },
computed: { computed: {
...mapState({ ...mapState({
ws: "ws", ws2: "ws2",
}), }),
isLogin() { isLogin() {
return Boolean(uni.getStorageSync("token")); return Boolean(uni.getStorageSync("token"));
@ -199,11 +194,11 @@ export default {
// socket // socket
linkSocket() { linkSocket() {
let msg = this.msg; let msg = this.msg;
this.ws.send({ this.ws2.send({
cmd: "sub", cmd: "sub",
msg, msg,
}); });
this.ws.on("message", (res) => { this.ws2.on("message", (res) => {
let { data, sub } = res; let { data, sub } = res;
if (sub == msg) { if (sub == msg) {
this.marketList = data; this.marketList = data;
@ -227,11 +222,6 @@ export default {
return curParam; return curParam;
}, },
}, },
mounted() {
if (this.stocksymbol) {
this.query = { symbol: this.stocksymbol };
}
},
created() { created() {
this.query = this.getQuery(); this.query = this.getQuery();
if (this.query.symbol) { if (this.query.symbol) {
@ -241,7 +231,7 @@ export default {
this.getCollect(); this.getCollect();
}, },
destroyed() { destroyed() {
this.ws.send({ this.ws2.send({
cmd: "unsub", cmd: "unsub",
msg: 'exchangeMarketList', msg: 'exchangeMarketList',
}) })

216
pages/stockexchange/exchange-transaction.vue

@ -4,14 +4,14 @@
<view class="w-max" style="height: var(--status-bar-height)"></view> <view class="w-max" style="height: var(--status-bar-height)"></view>
<view @click="$emit('symbol')" class="d-flex align-center"> <view @click="$emit('symbol')" class="d-flex align-center">
<i class="iconfont color-light fn-bold fn-18">&#xe655;</i> <i class="iconfont color-light fn-bold fn-18">&#xe655;</i>
<text class="fn-bold">{{ symbol }}</text> <text class="fn-bold">{{ activeCoin.coin_name }}</text>
<text class="fn-10 m-l-xs p-y-2" :class="increase.increase < 0 ? 'color-sell bg-sell-transparent' : 'color-buy bg-buy-transparent'">{{increase.increaseStr}}</text> <text class="fn-10 m-l-xs p-y-2" :class="increase.increase < 0 ? 'color-sell bg-sell-transparent' : 'color-buy bg-buy-transparent'">{{increase.increaseStr}}</text>
</view> </view>
<view class="d-flex fn-20 color-theme-1"> <view class="d-flex fn-20 color-theme-1">
<view class="m-r-xs" @click="$emit('option')"> <!-- <view class="m-r-xs" @click="$emit('option')">
<van-icon v-if="isCoolect" name="star" /> <van-icon v-if="isCoolect" name="star" />
<van-icon v-else class="color-default" name="star-o" /> <van-icon v-else class="color-default" name="star-o" />
</view> </view> -->
<v-link <v-link
tag="div" tag="div"
v-if="symbol" v-if="symbol"
@ -165,13 +165,21 @@
block block
@click="storeEntrust" @click="storeEntrust"
ref="btn" ref="btn"
>{{ v-if="tradingOpenshow==true">
form.direction == "buy" {{form.direction == "buy" ? this.$t("exchange.c3") : this.$t("exchange.c4")}}
? this.$t("exchange.c3")
: this.$t("exchange.c4")
}}
{{ activeCoin.coin_name }}</v-button {{ activeCoin.coin_name }}</v-button
> >
<v-button
size="small"
type="colorless"
class="w-max rounded-md"
block
@click="storeEntrust"
ref="btn"
v-if="tradingOpenshow==false">
{{form.direction == "buy" ? this.$t("exchange.c3") : this.$t("exchange.c4")}}
{{ activeCoin.coin_name }}</v-button
>
</template> </template>
<template v-else> <template v-else>
<v-button <v-button
@ -330,41 +338,41 @@
<view class="p-x-md p-y-xs" style="line-height: 60rpx;"> <view class="p-x-md p-y-xs" style="line-height: 60rpx;">
<view class="row d-flex m-y-xs"> <view class="row d-flex m-y-xs">
<view class="d-flex w-50 align-end"> <view class="d-flex w-50 align-end">
{{$t("exchange.g8")}}<span class="color-light"></span>{{item.pair_name}} {{$t("exchange.g9")}}<span class="color-light"></span>{{item.coin_name}}
</view> </view>
<view class="d-flex w-50 justify-between"> <view class="d-flex w-50 justify-between">
<view> <view>
{{$t("exchange.g9")}}<span class="color-light"></span>{{item.market}} {{$t("exchange.g10")}}<span class="color-light"></span>{{item.market}}
</view> </view>
</view> </view>
</view> </view>
<view class="row d-flex m-y-xs"> <view class="row d-flex m-y-xs">
<view class="d-flex w-50 align-end"> <view class="d-flex w-50 align-end">
{{$t("exchange.g10")}}<span class="color-light"></span>{{item.usable_balance}} {{$t("exchange.g11")}}<span class="color-light"></span>{{item.usable_balance}}
</view> </view>
<view class="d-flex w-50 justify-between"> <view class="d-flex w-50 justify-between">
<view> <view>
{{$t("exchange.g11")}}<span class="color-light"></span>{{item.realtimePrice}} {{$t("exchange.g12")}}<span class="color-light"></span>{{item.realtimePrice}}
</view> </view>
</view> </view>
</view> </view>
<view class="row d-flex m-y-xs"> <view class="row d-flex m-y-xs">
<view class="d-flex w-50 align-end"> <view class="d-flex w-50 align-end">
{{$t("exchange.g12")}}<span class="color-light"></span>{{item.cost_price}} {{$t("exchange.g13")}}<span class="color-light"></span>{{item.cost_price}}
</view> </view>
<view class="d-flex w-50 justify-between"> <view class="d-flex w-50 justify-between">
<view> <view>
{{$t("exchange.g13")}}<span class="color-light"></span>{{item.dayProfit}} {{$t("exchange.g14")}}<span :class="item.dayProfit>0?'color-buy':item.dayProfit<0?'color-sell':''">{{item.dayProfit}}</span>
</view> </view>
</view> </view>
</view> </view>
<view class="row d-flex m-y-xs"> <view class="row d-flex m-y-xs">
<view class="d-flex w-50 align-end"> <view class="d-flex w-50 align-end">
{{$t("exchange.g14")}}<span class="color-light"></span>{{item.unRealProfit}} {{$t("exchange.g15")}}<span class="color-light" :class="item.unRealProfit>0?'color-buy':item.unRealProfit<0?'color-sell':''">{{item.unRealProfit}}</span>
</view> </view>
<view class="d-flex w-50 justify-between"> <view class="d-flex w-50 justify-between">
<view> <view>
{{$t("exchange.g15")}}<span class="color-light"></span>{{item.profitRate}} {{$t("exchange.g16")}}<span class="color-light" :class="item.profitRate>0?'color-buy':item.profitRate<0?'color-sell':''">{{item.profitRate}}</span>
</view> </view>
</view> </view>
</view> </view>
@ -461,7 +469,10 @@ export default {
refreshing:false, refreshing:false,
active:0, active:0,
stockholdPositionlist:[], stockholdPositionlist:[],
holdPositiondtime: null holdPositiondtime: null,
tradingOpenshow:false,
timer: null,
}; };
}, },
computed: { computed: {
@ -526,14 +537,27 @@ export default {
// //
totalMoney() { totalMoney() {
// todo // todo
let totalMoney = 0; // let totalMoney = 0;
if (this.form.type == 0) { // if (this.form.type == 0) {
totalMoney = math.multiple(this.form.amount, this.form.entrust_price); // totalMoney = math.multiple(this.form.amount, this.form.entrust_price);
} else { // } else {
// totalMoney = this.form.amount; // // totalMoney = this.form.amount;
totalMoney = math.multiple(this.form.amount, this.form.entrust_price); // totalMoney = math.multiple(this.form.amount, this.form.entrust_price);
} // }
return totalMoney; // return totalMoney;
let totalMoney = 0;
// amount price -Infinity 0
let amount = Number(this.form.amount) || 0;
let price = Number(this.form.entrust_price) || 0;
if (this.form.type == 0) {
totalMoney = math.multiple(amount, price);
} else {
totalMoney = math.multiple(amount, price);
}
//
return isNaN(totalMoney) ? 0 : totalMoney;
}, },
// //
activeStep() { activeStep() {
@ -554,18 +578,22 @@ export default {
usable() { usable() {
if (this.form.direction == "buy") { if (this.form.direction == "buy") {
if (!this.targetBalance.usable_balance) return 0; if (!this.targetBalance.usable_balance) return 0;
return this.omitTo( // return this.omitTo(
// this.targetBalance.usable_balance, // // this.targetBalance.usable_balance,
// this.activeCoin.price_decimals // // this.activeCoin.price_decimals
this.currentBalance.usable_balance, // this.currentBalance.usable_balance,
this.activeCoin.qty_decimals // this.activeCoin.qty_decimals
); // );
return this.currentBalance.usable_balance
} else { } else {
// console.log(this.currentBalance);
if (!this.currentBalance.usable_balance) return 0; if (!this.currentBalance.usable_balance) return 0;
return this.omitTo( // return this.omitTo(
this.currentBalance.usable_balance, // this.currentBalance.usable_balance,
this.activeCoin.qty_decimals // // this.targetBalance.usable_balance,
); // this.activeCoin.qty_decimals
// );
return this.currentBalance.usable_balance
} }
}, },
usable1() { usable1() {
@ -618,10 +646,13 @@ export default {
},3000) },3000)
this.getUserBalance(); this.getUserBalance();
this.linkSocket(this.activeCoin.symbol); this.linkSocket(this.activeCoin.symbol);
this.startSchedule();
} else if(!n&&this.isLogin){ } else if(!n&&this.isLogin){
this.unLink(this.activeCoin.symbol); this.unLink(this.activeCoin.symbol);
clearInterval(this.dtime); clearInterval(this.dtime);
clearInterval(this.holdPositiondtime); clearInterval(this.holdPositiondtime);
clearInterval(this.timer);
} }
}, },
@ -633,9 +664,11 @@ export default {
this.holdPositiondtime = setInterval(()=>{ this.holdPositiondtime = setInterval(()=>{
this.stockholdPosition(); this.stockholdPosition();
},3000) },3000)
this.startSchedule();
}else if(e!='stockexchange-operation'&&this.isLogin){ }else if(e!='stockexchange-operation'&&this.isLogin){
clearInterval(this.dtime); clearInterval(this.dtime);
clearInterval(this.holdPositiondtime); clearInterval(this.holdPositiondtime);
clearInterval(this.timer);
} }
}, },
list(e){ list(e){
@ -708,6 +741,7 @@ export default {
// //
sliderChange(n,i) { sliderChange(n,i) {
// console.log(n, i, this.form.direction); // console.log(n, i, this.form.direction);
if(!n)return
let num = n/100; let num = n/100;
this.sliderActive=i this.sliderActive=i
if (this.form.direction == "buy") { if (this.form.direction == "buy") {
@ -720,11 +754,16 @@ export default {
); );
} else if (this.form.type == 1) { } else if (this.form.type == 1) {
// //
this.form.amount = this.form.amount = math.multiple( // this.form.amount = this.form.amount = math.multiple(
this.targetBalance.usable_balance, // this.targetBalance.usable_balance,
num, // num,
4 // 4
); // );
this.form.amount = math.multiple(
this.targetBalance.usable_balance / this.form.entrust_price,
num,
6
);
} }
} else if (this.form.direction == "sell") { } else if (this.form.direction == "sell") {
if (!this.currentBalance.usable_balance) return; if (!this.currentBalance.usable_balance) return;
@ -783,12 +822,14 @@ export default {
if(ti===3){ if(ti===3){
clearInterval(timer); clearInterval(timer);
} }
}, 1000) }, 2000)
} }
console.log('123'); // console.log('123');
this.dtime = setInterval(() => { this.dtime = setInterval(() => {
this.getCurrentEntrust(true) this.getCurrentEntrust(true)
}, 3000); }, 3000);
this.sliderChange(null,-1)
this.sliderActive = -1
// this.getCurrentEntrust() // this.getCurrentEntrust()
}) })
.catch(() => {}); .catch(() => {});
@ -808,24 +849,85 @@ export default {
this.newPrice = this.tradeList[0]||{}; this.newPrice = this.tradeList[0]||{};
}); });
}, },
tradingOpen(){
Market.getstocktradingOpen().then(res => {
this.tradingOpenshow = res.data
}).catch(err => {});
},
startSchedule() {
this.timer = setInterval(() => {
const now = new Date();
const minutes = now.getMinutes();
const seconds = now.getSeconds();
let remainingSeconds = 0;
// 1. 0000 3000
if (minutes % 30 === 0 && seconds === 0) {
remainingSeconds = 0;
console.log(`距离下次刷新还有 ${remainingSeconds} 秒,正在执行刷新...`);
//
this.tradingOpen();
}
// 2.
else {
if (minutes < 30) {
// 0~29 30
remainingSeconds = (30 - minutes) * 60 - seconds;
} else {
// 30~59 60 ()
remainingSeconds = (60 - minutes) * 60 - seconds;
}
//
// console.log(` ${remainingSeconds} `);
}
}, 1000);
},
// //
getDefaultPrice() { getDefaultPrice() {
if (this.form.direction == "buy") { // if (this.form.direction == "buy") {
this.form.entrust_price = Math.min( // this.form.entrust_price = Math.min(
...this.tradeList.map((item) => item.price) // ...this.tradeList.map((item) => item.price)
); // );
} else { // } else {
this.form.entrust_price = Math.max( // this.form.entrust_price = Math.max(
...this.buyList.map((item) => item.price) // ...this.buyList.map((item) => item.price)
); // );
} // }
if (this.form.direction == "buy") {
// tradeList
if (this.tradeList && this.tradeList.length > 0) {
this.form.entrust_price = Math.min(
...this.tradeList.map((item) => Number(item.price))
);
} else {
// 使0
this.form.entrust_price = this.newPrice.price || 0;
}
} else { //
// buyList
if (this.buyList && this.buyList.length > 0) {
this.form.entrust_price = Math.max(
...this.buyList.map((item) => Number(item.price))
);
} else {
// 使0
this.form.entrust_price = this.newPrice.price || 0;
}
}
}, },
// //
changeDirection(type){ changeDirection(type){
this.form.direction = type; this.form.direction = type;
this.getDefaultPrice(); this.getDefaultPrice();
let n = this.progress[this.sliderActive]; let n = this.progress[this.sliderActive];
// this.sliderChange(n, this.sliderActive); this.sliderChange(n, this.sliderActive);
}, },
// //
getValue(amount) { getValue(amount) {
@ -944,6 +1046,10 @@ export default {
this.getBooks(); this.getBooks();
this.getUserBalance(); this.getUserBalance();
this.socketMessage(); this.socketMessage();
this.tradingOpen()
this.startSchedule();
if (this.query.direction) { if (this.query.direction) {
this.form.direction = this.query.direction; this.form.direction = this.query.direction;
} }
@ -959,6 +1065,9 @@ export default {
// this.unLink(this.unSymbol); // this.unLink(this.unSymbol);
clearInterval(this.dtime); clearInterval(this.dtime);
clearInterval(this.holdPositiondtime); clearInterval(this.holdPositiondtime);
if (this.timer) {
clearInterval(this.timer);
}
}, },
}; };
</script> </script>
@ -1130,4 +1239,7 @@ export default {
.bor5-active{ .bor5-active{
border-bottom: 4px solid $theme-2; border-bottom: 4px solid $theme-2;
} }
/deep/uni-input{
background-color: transparent;
}
</style> </style>

1
pages/stockexchange/index.vue

@ -562,5 +562,6 @@ export default {
.chart-tradingview { .chart-tradingview {
height: 370px; height: 370px;
width: 100%; width: 100%;
border: 0px;
} }
</style> </style>

48
pages/stockexchange/symbol-list.vue

@ -1,14 +1,14 @@
<template> <template>
<view class="symbol-list"> <view class="symbol-list">
<view class="w-max" style="height: var(--status-bar-height)"></view> <view class="w-max" style="height: var(--status-bar-height)"></view>
<view class="title fn-18 p-md color-light">{{ title||$t("exchange.f5") }}</view> <view class="title fn-18 p-md color-light">{{ heyue==2?$t('exchange.g7'):title||$t("exchange.f5") }}</view>
<van-search <van-search
background="transparent" background="transparent"
:value="filterText" :value="filterText"
@change="filterText = $event.detail" @change="filterText = $event.detail"
:placeholder="$t('exchange.f6')" :placeholder="$t('exchange.f6')"
/> />
<van-tabs :active="active"> <van-tabs :active="active" v-if="heyue==0||heyue==1">
<van-tab <van-tab
:title="heyue==1&&parentItem.coin_name=='USDT'?$t('first.b8'):parentItem.coin_name" :title="heyue==1&&parentItem.coin_name=='USDT'?$t('first.b8'):parentItem.coin_name"
v-for="parentItem in showMarketList" v-for="parentItem in showMarketList"
@ -69,6 +69,50 @@
</view> </view>
</van-tab> </van-tab>
</van-tabs> </van-tabs>
<view v-if="heyue==2">
<view>
<view class="p-x-xs m-t-md">
<table class="w-max">
<thead>
<tr class="fn-sm">
<th class="p-l-md p-y-xs fn-left">{{ $t("exchange.f7") }}</th>
<th class="fn-center">{{ $t("exchange.f8") }}</th>
<th class="p-r-md p-y-xs fn-right">{{ $t("exchange.f9") }}</th>
</tr>
</thead>
<tbody v-for="parentItem in showMarketList" :key="parentItem.coin_name">
<tr
class="p-y-md"
:class="symbols==item.coin_name&&heyue==1?'bg-panel':''"
v-for="item in parentItem.marketInfoList"
:key="item.symbol"
v-show="isShow(item.pair_name)"
@click="$emit('check-symbol', item)"
>
<td class="p-l-md p-y-md w-40">
<template v-if="parentItem.isCollect">
<span class="color-light">{{ item.pair_name }}</span>
</template>
<template v-else>
<span class="color-light">{{ item.coin_name||item.symbol }}</span>
</template>
</td>
<td class="w-30 fn-center">
<template :class="item.increase < 0 ? 'color-sell' : 'color-buy'">
{{ item.price }}
</template>
</td>
<td :class="item.increase < 0 ? 'color-sell' : 'color-buy'" class="p-r-md p-y-xs fn-right w-30">
{{ item.increaseStr }}
</td>
</tr>
</tbody>
</table>
</view>
</view>
</view>
</view> </view>
</template> </template>
<script> <script>

Loading…
Cancel
Save