import { aiSignal } from './strategy.js'; import ccxt from "ccxt"; import fs from "fs"; import logger from "./logger.js"; const cfg = JSON.parse(fs.readFileSync('./config.json', 'utf8')) const ex = new ccxt.bybit({ apiKey: '', secret: '', options: { defaultType: 'swap' } }); const ohlcv = await ex.fetchOHLCV(cfg.cctxSymbol, cfg.ohlcvInterval, undefined, 300); const bars = ohlcv.map(c => ({ t: c[0], o: c[1], h: c[2], l: c[3], c: c[4], v: c[5] })); const sig = await aiSignal(bars); // const sig = JSON.parse(msg) console.log(sig) console.log(sig.side) console.log(sig.sl) console.log(sig.tp) console.log(sig.reason) let position= {} let balance = 10000 const curPrice = sig.price if(sig.side !== 'HOLD') enterMarket(sig); function enterMarket(sig) { const qty = ((balance * cfg.leverage) / curPrice).toFixed(4); const notional = curPrice * +qty; const fee = notional * cfg.feeTaker / 100; balance -= fee; position = { id: `m${Date.now()}`, side: sig.side, entry: curPrice, qty: +qty, sl: sig.sl, tp: sig.tp, openTime: Date.now(), fee, initialBalance: balance + fee }; logger.info(`[FILLED] ${sig.side} 시장가 @${curPrice} qty=${qty}`, { position }); }