mirror of
https://git.hmsn.ink/coin/bot.git
synced 2026-03-20 00:02:16 +09:00
tp 범위 조절
This commit is contained in:
30
index.js
30
index.js
@@ -13,6 +13,7 @@ const ex = new ccxt.bybit({
|
|||||||
|
|
||||||
let bars = [];
|
let bars = [];
|
||||||
let balance = cfg.startBalance;
|
let balance = cfg.startBalance;
|
||||||
|
let pending = null;
|
||||||
let position = null;
|
let position = null;
|
||||||
let trades = [];
|
let trades = [];
|
||||||
let curPrice = null;
|
let curPrice = null;
|
||||||
@@ -63,6 +64,7 @@ function initWs() {
|
|||||||
if (t) {
|
if (t) {
|
||||||
if(t.lastPrice) {
|
if(t.lastPrice) {
|
||||||
curPrice = +t.lastPrice;
|
curPrice = +t.lastPrice;
|
||||||
|
confirmTrade();
|
||||||
// logger.debug('현재 가격 업데이트', { curPrice });
|
// logger.debug('현재 가격 업데이트', { curPrice });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,10 +159,10 @@ function enterMarket(sig) {
|
|||||||
const fee = notional * cfg.feeTaker / 100;
|
const fee = notional * cfg.feeTaker / 100;
|
||||||
balance -= fee;
|
balance -= fee;
|
||||||
|
|
||||||
position = {
|
pending = {
|
||||||
id: `m${Date.now()}`,
|
id: `m${Date.now()}`,
|
||||||
side: sig.side,
|
side: sig.side,
|
||||||
entry: curPrice,
|
entry: sig.price,
|
||||||
qty: +qty,
|
qty: +qty,
|
||||||
sl: sig.sl,
|
sl: sig.sl,
|
||||||
tp: sig.side === 'LONG' ? sig.tp - (sig.tp * 0.0005) : sig.tp + (sig.tp * 0.0005),
|
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
|
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() {
|
function forceExit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user