feat: 前端全量更新 - 含所有本次需求
- 移除秒合约页面及UI - 合约页Tab改为Position Held/Transaction Record - 存款/提款/转账页增加BTC/ETH - 资产页重构(用户信息+盈亏+多语言) - 注册页改版(匹配新设计稿) - 日文全面翻译+首页菜单多语言 - 代理专属注册链接支持(?code=) - 10个locale文件同步更新
This commit is contained in:
@@ -0,0 +1,218 @@
|
||||
/*********************************************/
|
||||
|
||||
// 次文件只需要关注 getBars 和 subscribeBars 函数即可
|
||||
|
||||
/******************************************/
|
||||
|
||||
// 历史数据 第一条数据的 时间撮 因为k线图一次性历史数据只拿一部分,用户吧图往前滑动,就会用这个时间撮去请求更早的 历史数据
|
||||
var detafeed_historyTime = 0
|
||||
// 上一次的 K线周期 切换产品的时候 需要从websock 取消订阅这个
|
||||
var detafeed_lastResolution = null
|
||||
// 上一次的产品 切换产品的时候 需要从websock 取消订阅这个
|
||||
var detafeed_lastSymbol = null
|
||||
// 价格精度设置 来自kline_H5
|
||||
// var pricescale = pricescale
|
||||
// bbtype2类型1日-昨日数据
|
||||
var lastBarObj = null
|
||||
|
||||
function FeedBase() {}
|
||||
|
||||
FeedBase.prototype.onReady = function(callback) {
|
||||
setTimeout(()=>{
|
||||
callback(this._configuration)
|
||||
},0)
|
||||
}
|
||||
|
||||
FeedBase.prototype.getSendSymbolName = function(symbolName) {
|
||||
var name = symbolName.split('/')
|
||||
return (name[0] + name[1]).toLocaleLowerCase()
|
||||
}
|
||||
|
||||
FeedBase.prototype.resolveSymbol = function(symbolName, onResolve, onError) {
|
||||
setTimeout(()=>{
|
||||
onResolve({
|
||||
"name": symbolName,
|
||||
"timezone": "America/New_York",
|
||||
"pricescale": Math.pow(10,pricescale), //10000
|
||||
"minmov": 1,
|
||||
"minmov2": 0,
|
||||
"ticker": symbolName,
|
||||
"description": "",
|
||||
"session": "24x7",
|
||||
"type": "bitcoin",
|
||||
"volume_precision": 10,
|
||||
"has_intraday": true,
|
||||
"intraday_multipliers": ['1', '5', '15', '30', '60', '1440'], // 时间
|
||||
"has_weekly_and_monthly": false,
|
||||
"has_no_volume": false,
|
||||
"regular_session": "24x7",
|
||||
"has_daily":true
|
||||
})
|
||||
},0)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更多时间类型在这里添加 时间类型请看火币文档
|
||||
* @param resolution 订阅周期 按照自己喜欢的来 如 30 30分钟、 1D 一天
|
||||
* @param name 交易对symbol
|
||||
* @param to 结束时间
|
||||
* @returns {object}
|
||||
*/
|
||||
const resolutionFormat = (resolution, name, to) => {
|
||||
let req = `market.${name}.kline.${resolution}min`;
|
||||
let minutes = resolution;
|
||||
|
||||
if (resolution.includes('D')) {
|
||||
if (resolution.length < 2) resolution = '1' + resolution;
|
||||
req = `market.${name}.kline.${parseInt(resolution)}day`;
|
||||
minutes = parseInt(resolution) * 24 * 60;
|
||||
} else if (resolution.includes('W')) {
|
||||
if (resolution.length < 2) resolution = '1' + resolution;
|
||||
req = `market.${name}.kline.${parseInt(resolution)}week`;
|
||||
minutes = parseInt(resolution) * 24 * 60 * 7;
|
||||
} else if (resolution.includes('M')) {
|
||||
if (resolution.length < 2) resolution = '1' + resolution;
|
||||
req = `market.${name}.kline.${parseInt(resolution)}mon`;
|
||||
minutes = parseInt(resolution) * 24 * 60 * 30;
|
||||
} else {
|
||||
if (resolution / 60 > 1) {
|
||||
req = `market.${name}.kline.${resolution / 60}hour`;
|
||||
}
|
||||
}
|
||||
|
||||
let from = null;
|
||||
if (to) {
|
||||
from = to - 200 * minutes * 60;
|
||||
if (resolution.includes('M') || resolution.includes('W')) { // 周线月线控制条数,时间超出火币规定范围, ws报错
|
||||
from = to - 50 * minutes * 60;
|
||||
}
|
||||
}
|
||||
return {
|
||||
minutes,
|
||||
req,
|
||||
from,
|
||||
to,
|
||||
};
|
||||
};
|
||||
|
||||
FeedBase.prototype.getBars = function(symbolInfo, resolution,rangeStartDate, rangeEndDate, onResult, onError,periodParams) {
|
||||
// 监听到数据加载后传入nodata
|
||||
if(periodParams==false){
|
||||
onResult([], { noData: true })
|
||||
return
|
||||
}
|
||||
|
||||
// 切换产品周期 或者 切换产品 会执行这个函数
|
||||
let reso = resolutionFormat(resolution, symbolInfo.name, rangeEndDate > detafeed_historyTime ? rangeEndDate :
|
||||
detafeed_historyTime)
|
||||
// 是历史数据
|
||||
var history = true
|
||||
/*
|
||||
!detafeed_historyTime 如果没请请求过这个产品或者这个周期的历史数据
|
||||
resolution !== detafeed_lastResolution 是否更换了产品周期
|
||||
detafeed_lastSymbol !== symbolInfo.name 是否切换了产品
|
||||
*/
|
||||
if (!detafeed_historyTime || (resolution !== detafeed_lastResolution) || detafeed_lastSymbol !== symbolInfo.name) {
|
||||
// 那就不是历史数据
|
||||
history = false
|
||||
// 储存请求过的产品
|
||||
detafeed_lastSymbol = symbolInfo.name
|
||||
// 记录目前时间戳,就用目前时间戳往前请求历史数据
|
||||
detafeed_historyTime = window.parseInt((Date.now() / 1000))
|
||||
}
|
||||
|
||||
socket.sendData({
|
||||
req: reso.req,
|
||||
id: "id10",
|
||||
from: reso.from,
|
||||
to: reso.to,
|
||||
}, reso.req, history)
|
||||
|
||||
Event.off('data')
|
||||
|
||||
Event.on('data', data => {
|
||||
Event.emit('zhezhaoceng', 2)
|
||||
Event.emit('changeflag', true)
|
||||
if (data && data.length) {
|
||||
// 记录这次请求的时间周期
|
||||
detafeed_lastResolution = resolution
|
||||
|
||||
var meta = { noData: false }
|
||||
const datas = []
|
||||
|
||||
detafeed_historyTime = data[0].id
|
||||
for (let i of data) {
|
||||
if(resolution=='1D'){
|
||||
i.time = (i.id+86400) * 1000
|
||||
}else{
|
||||
i.time = i.id * 1000
|
||||
}
|
||||
|
||||
datas.push({
|
||||
time: i.time,
|
||||
volume: Number(i.vol || 0),
|
||||
open: Number(i.open || 0),
|
||||
high: Number(i.high || 0),
|
||||
low: Number(i.low || 0),
|
||||
close: Number(i.close || 0)
|
||||
})
|
||||
}
|
||||
|
||||
if(bb_type==2 && resolution!='1D' && datas.length > 1){
|
||||
lastBarObj = datas[datas.length - 2]
|
||||
}
|
||||
|
||||
onResult(datas, meta)
|
||||
} else {
|
||||
onResult([], { noData: true })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
FeedBase.prototype.subscribeBars = function(symbolInfo, resolution, onTick, listenerGuid, onResetCacheNeededCallback) {
|
||||
Event.off('realTime')
|
||||
|
||||
Event.on('realTime', data => {
|
||||
if(!data) return
|
||||
|
||||
if(bb_type==2 && lastBarObj!=null){
|
||||
if(resolution=='1D' && (data.id-86400==lastBarObj.id)){
|
||||
data.open = lastBarObj.close
|
||||
}
|
||||
if(resolution=='1' && (data.id-60==lastBarObj.id)){
|
||||
data.open = lastBarObj.close
|
||||
}
|
||||
if(resolution=='5' && (data.id-300==lastBarObj.id)){
|
||||
data.open = lastBarObj.close
|
||||
}
|
||||
if(resolution=='15' && (data.id-900==lastBarObj.id)){
|
||||
data.open = lastBarObj.close
|
||||
}
|
||||
if(resolution=='30' && (data.id-1800==lastBarObj.id)){
|
||||
data.open = lastBarObj.close
|
||||
}
|
||||
if(resolution=='60' && (data.id-3600==lastBarObj.id)){
|
||||
data.open = lastBarObj.close
|
||||
}
|
||||
}
|
||||
|
||||
let time = data.id * 1000
|
||||
if(resolution=='1D'){
|
||||
time = (data.id+86400) * 1000
|
||||
}
|
||||
|
||||
onTick({
|
||||
time: time,
|
||||
volume: Number(data.vol || 0),
|
||||
close: Number(data.close || 0),
|
||||
open: Number(data.open || 0),
|
||||
high: Number(data.high || 0),
|
||||
low: Number(data.low || 0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
FeedBase.prototype.unsubscribeBars = function(listenerGuid) {
|
||||
// 取消订阅产品的callback
|
||||
}
|
||||
Reference in New Issue
Block a user