mirror of
https://git.hmsn.ink/coin/chart.git
synced 2026-03-20 00:02:17 +09:00
인터벌 오류 수정
This commit is contained in:
47
src/App.vue
47
src/App.vue
@@ -30,9 +30,9 @@ const scrollContainer2 = ref()
|
||||
const signal1 = ref([])
|
||||
const signal2 = ref([])
|
||||
|
||||
const contract = ref('BTC_USDT')
|
||||
const contract = ref('ETH_USDT')
|
||||
/* Interval : "10s", "1m", "5m", "15m", "30m", "1h", "4h", "8h", "1d", "7d"*/
|
||||
const time = ref('1h')
|
||||
const time = ref('5m')
|
||||
const chartOptions = ref({
|
||||
layout: {
|
||||
textColor: 'black',
|
||||
@@ -165,11 +165,10 @@ const init = (cont, ti) => {
|
||||
// console.table(entrySignals(data))
|
||||
candleTick.value = data
|
||||
})
|
||||
|
||||
candleSocket(cont, ti)
|
||||
}
|
||||
|
||||
const distroy = (cont) => {
|
||||
const distroy = () => {
|
||||
candleTick.value = []
|
||||
socket.close()
|
||||
}
|
||||
@@ -187,15 +186,17 @@ const lazyLoad = async (ti) => {
|
||||
})
|
||||
}
|
||||
|
||||
let loopIdx = 0
|
||||
const candleSocket = (cont, ti) => {
|
||||
socket.addEventListener('open', (event) => {
|
||||
// socket.send(JSON.stringify({"type":"subscribe", "channel": cont, "time": ti}))
|
||||
console.log(cont, ti)
|
||||
socket.send(JSON.stringify({"time" : curToUnix(), "channel" : "futures.candlesticks","event": "subscribe", "payload" : [ti, cont]}))
|
||||
socket.send(JSON.stringify({"time" : curToUnix(), "channel" : "futures.trades","event": "subscribe", "payload" : [cont]}))
|
||||
})
|
||||
|
||||
socket.addEventListener('message', (message) => {
|
||||
const msg = JSON.parse(message.data)
|
||||
if(msg.channel === 'futures.candlesticks') {
|
||||
if(msg.event === 'update') {
|
||||
const item = msg.result[0]
|
||||
|
||||
@@ -208,6 +209,29 @@ const candleSocket = (cont, ti) => {
|
||||
candleTick.value = [...ticks]
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if(msg.event === 'update') {
|
||||
const item = msg.result[0]
|
||||
// console.log(item)
|
||||
const ticks = candleTick.value
|
||||
try {
|
||||
let diff = 0
|
||||
if(time.value === '10s') diff = 10
|
||||
else if(time.value === '1m') diff = 60
|
||||
else if(time.value === '5m') diff = (60 * 5)
|
||||
else if(time.value === '15m') diff = (60 * 15)
|
||||
else if(time.value === '30m') diff = (60 * 30)
|
||||
else if(time.value === '1h') diff = (60 * 60)
|
||||
else if(time.value === '4h') diff = (60 * 60 * 4)
|
||||
else if(time.value === '8h') diff = (60 * 60 * 8)
|
||||
else if(time.value === '1d') diff = (60 * 60 * 24)
|
||||
else if(time.value === '7d') diff = (60 * 60 * 24 * 7)
|
||||
if(item.create_time >= ticks[ticks.length - 1].t && item.create_time <= (ticks[ticks.length - 1].t + diff)) {
|
||||
ticks[ticks.length - 1].c = item.price
|
||||
if(ticks[ticks.length - 1].h < item.price) ticks[ticks.length - 1].h = item.price
|
||||
if(ticks[ticks.length - 1].l > item.price) ticks[ticks.length - 1].l = item.price
|
||||
candleTick.value = [...ticks]
|
||||
ema.value = calculateEMA(ticks, 20)
|
||||
macd.value = calculateMACD(ticks)
|
||||
bb.value = calculateBollingerBands(ticks)
|
||||
@@ -215,14 +239,21 @@ const candleSocket = (cont, ti) => {
|
||||
// console.table(entrySignals(ticks))
|
||||
const dd = entrySignals(ticks)
|
||||
if(dd.length) signal2.value = [...signal2.value, entrySignals(ticks)]
|
||||
|
||||
const tt = swingSignal(ticks)
|
||||
console.log(tt)
|
||||
if(tt[0] !== 'HOLD') signal1.value = [...signal1.value, swingSignal(ticks)]
|
||||
lazyLock.value = false
|
||||
}
|
||||
} catch(error) {}
|
||||
|
||||
|
||||
loopIdx++;
|
||||
if(loopIdx > 1000) {
|
||||
console.clear();
|
||||
loopIdx = 0;
|
||||
}
|
||||
// console.log('trade', socketLock)
|
||||
}
|
||||
}
|
||||
lazyLock.value = false
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -128,18 +128,38 @@ const swingSignal = (data: any) => {
|
||||
const bbl = bbands.lower[latest - offsetBb];
|
||||
const bbu = bbands.upper[latest - offsetBb];
|
||||
|
||||
// 4) 최종 조건
|
||||
if (volatilityBreak &&
|
||||
prev < 0 && hist >= 0 &&
|
||||
// 시나리오1
|
||||
// if (volatilityBreak &&
|
||||
// prev < 0 && hist >= 0 &&
|
||||
// rsiVal <= 35 && close <= bbl)
|
||||
// return ['LONG',volatilityBreak, prev, hist, rsiVal, close, bbl]
|
||||
//
|
||||
// if (volatilityBreak &&
|
||||
// prev > 0 && hist <= 0 &&
|
||||
// rsiVal >= 65 && close >= bbu)
|
||||
// return ['SHORT',volatilityBreak, prev, hist, rsiVal, close, bbl]
|
||||
|
||||
// 시나리오2
|
||||
// if (volatilityBreak &&
|
||||
// prev < hist &&
|
||||
// rsiVal <= 35 && close <= bbl)
|
||||
// return ['LONG',volatilityBreak, prev, hist, rsiVal, close, bbl]
|
||||
//
|
||||
// if (volatilityBreak &&
|
||||
// prev > hist &&
|
||||
// rsiVal >= 65 && close >= bbu)
|
||||
// return ['SHORT',volatilityBreak, prev, hist, rsiVal, close, bbl]
|
||||
|
||||
// 시나리오3
|
||||
if (prev < hist &&
|
||||
rsiVal <= 35 && close <= bbl)
|
||||
return ['LONG',volatilityBreak, prev, hist, rsiVal, close, bbl]
|
||||
return ['LONG', prev, hist, rsiVal, close, bbl]
|
||||
|
||||
if (volatilityBreak &&
|
||||
prev > 0 && hist <= 0 &&
|
||||
if (prev > hist &&
|
||||
rsiVal >= 65 && close >= bbu)
|
||||
return ['SHORT',volatilityBreak, prev, hist, rsiVal, close, bbl]
|
||||
return ['SHORT', prev, hist, rsiVal, close, bbl]
|
||||
|
||||
return ['HOLD',volatilityBreak, prev, hist, rsiVal, close, bbl];
|
||||
return ['HOLD', prev, hist, rsiVal, close, bbl];
|
||||
};
|
||||
|
||||
export {swingSignal}
|
||||
Reference in New Issue
Block a user