import socket from "@/utils/websocket.js" let socket_api = 'https://doc.okenx.com:2000' const state = { bids: [], asks: [], daymarket:{} } const mutations = { // SET_CONTRACT: (state, contract) => { // // 合约账户 // state.contractAccount = contract; // }, // SET_BIBI: (state, bibi) => { // // 币币账户 // state.bibiAccount = bibi; // }, // SET_LEGAL: (state, legal) => { // // 法币账户 // state.legalAccount = legal; // }, // SET_GIFTMONEY: (state, GiftMoney) => { // // 赠金账户 // state.GiftMoneyAccount = GiftMoney; // }, // SET_STOCKS_COLOR: (state, code) => { // state.stocksColor = code // }, // SET_TOKEN: (state, token) => { // setToken(token) // state.token = token // } } const nums = (arr) => { const att = arr.map(el => { return el[0] }) const num = Math.max.apply(null, att) arr.forEach(el => { let n = Math.round(el[0] / num * 10000) / 100 el[2] = n > 100 ? 100 : n; }) return arr } const actions = { openSocket({ commit, state }, data) { var sk = socket(socket_api); sk.on(data.type, function(msg) { if (data.legal_id == msg.legal_id && data.currency_id == msg.currency_id) { //btc 匹配 // var buyIn = JSON.parse(msg.bids); // var out = JSON.parse(msg.asks).reverse(); if (msg.type == 'market_depth') { var buyIn = msg.bids.slice(0, 7); state.bids = nums(buyIn); var out = msg.asks.slice(0, 7); // state.bids = msg.bids state.asks = nums(out); } if (msg.type == 'daymarket') { state.daymarket = msg console.log('daymarket = ', msg) // var buyIn = msg.bids.slice(0, 7); // state.bids = nums(buyIn); // var out = msg.asks.slice(0, 7); // // state.bids = msg.bids // state.asks = nums(out); } } }) }, } export default { namespaced: true, state, mutations, actions }