From 5ea7c0b3f575ef1d47b160aa0d3ec7ba7bab84bf Mon Sep 17 00:00:00 2001 From: bangae1 Date: Wed, 3 Sep 2025 00:14:56 +0900 Subject: [PATCH] =?UTF-8?q?tp=20=EB=B2=94=EC=9C=84=20=EC=A1=B0=EC=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 829f4cc..f3115b3 100644 --- a/index.js +++ b/index.js @@ -13,6 +13,7 @@ const ex = new ccxt.bybit({ let bars = []; let balance = cfg.startBalance; +let pending = null; let position = null; let trades = []; let curPrice = null; @@ -63,6 +64,7 @@ function initWs() { if (t) { if(t.lastPrice) { curPrice = +t.lastPrice; + confirmTrade(); // logger.debug('현재 가격 업데이트', { curPrice }); } } @@ -157,10 +159,10 @@ function enterMarket(sig) { const fee = notional * cfg.feeTaker / 100; balance -= fee; - position = { + pending = { id: `m${Date.now()}`, side: sig.side, - entry: curPrice, + entry: sig.price, qty: +qty, sl: sig.sl, tp: sig.side === 'LONG' ? sig.tp - (sig.tp * 0.0005) : sig.tp + (sig.tp * 0.0005), @@ -169,7 +171,29 @@ function enterMarket(sig) { initialBalance: balance + fee }; - logger.info(`[FILLED] ${sig.side} 시장가 @${curPrice} qty=${qty}`, { position }); + logger.info(`[PENDING] ${sig.side} 지정가 @${sig.price} qty=${qty}`, { pending }); +} + +function confirmTrade() { + if(pending === null) return; + let flag = false; + if(pending.side === 'LONG' ) { + if(pending.entry <= curPrice) { + flag = true; + } + } else if(pending.side === 'SHORT') { + if(pending.entry >= curPrice) { + flag = true; + } + } + + if(flag) { + position = {...pending} + pending = null; + } + + + logger.info(`[FILLED] ${position.side} 지정가 @${position.entry} qty=${position.qty}`, { position }); } function forceExit() {