5분봉 개선 버전

This commit is contained in:
2025-09-02 12:22:30 +09:00
parent c539f3a0ad
commit 6ef7a99374
4 changed files with 89 additions and 38 deletions

View File

@@ -172,9 +172,48 @@ function enterMarket(sig) {
logger.info(`[FILLED] ${sig.side} 시장가 @${curPrice} qty=${qty}`, { position });
}
function forceExit() {
if(position) {
const pnl = (position.side === 'LONG' ? curPrice - position.entry : position.entry - curPrice) * position.qty;
const fee = position.qty * curPrice * (cfg.feeTaker / 100);
const netPnl = pnl - fee;
balance += netPnl;
const tradeRecord = {
...position,
closed: true,
exitPrice: curPrice,
exitReason: 'force Exit',
pnl: netPnl,
closeTime: Date.now(),
finalBalance: balance,
leverage: cfg.leverage
};
trades.push(tradeRecord);
fs.writeFileSync(cfg.logPath, JSON.stringify(trades, null, 2));
logger.info(`[FORCEEXIT] @${curPrice.toFixed(4)} | PnL=${netPnl.toFixed(2)} | Balance=${balance.toFixed(2)}`, {
trade: tradeRecord,
market: { currentPrice: curPrice }
});
// 종료된 포지션 로깅
logger.logPosition(tradeRecord, `강제 청산 포지션 종료`);
position = null;
}
}
function checkExit() {
if (!position || curPrice === null) return;
if (Date.now() - position.openTime >= (1000 * 60) *cfg.forceTime) {
forceExit()
return;
}
const { id, side, entry, qty, sl, tp, fe, ib} = position;
let exit = null;