mirror of
https://git.hmsn.ink/coin/bot.git
synced 2026-03-19 15:55:01 +09:00
5분봉 개선 버전
This commit is contained in:
39
index.js
39
index.js
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user