UNPKG

@debate300/bithumb-pro

Version:

A real-time cryptocurrency price tracker for Bithumb (Pro).

105 lines (104 loc) 5.31 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setDisplayOptions = setDisplayOptions; exports.redrawTable = redrawTable; const cli_table3_1 = __importDefault(require("cli-table3")); const chalk_1 = __importDefault(require("chalk")); let displayLimit = 0; let limitWasSetByUser = false; let sortBy = "rate"; // 'rate' or 'name' function setDisplayOptions(limit, sort) { if (limit > 0) { displayLimit = limit; limitWasSetByUser = true; } if (["name", "rate"].includes(sort)) { sortBy = sort; } } function redrawTable(exchangeName, data) { const menu = ` ${chalk_1.default.bold('Menu:')} ${chalk_1.default.cyan('1')} Bithumb | ${chalk_1.default.cyan('2')} Upbit | ${chalk_1.default.cyan('3')} Binance`; if (exchangeName === 'Binance') { process.stdout.write("\x1B[H\x1B[J" + chalk_1.default.yellow(`\n${exchangeName} 연동은 아직 구현되지 않았습니다.`)); process.stdout.write('\n\n' + menu); return; } if (data.size === 0) { process.stdout.write("\x1B[H\x1B[J" + chalk_1.default.yellow("\n데이터를 기다리는 중입니다...")); process.stdout.write('\n\n' + menu); return; } let currentDisplayLimit = displayLimit; if (!limitWasSetByUser) { const terminalHeight = process.stdout.rows || 30; currentDisplayLimit = Math.max(1, terminalHeight - 10); // Adjust for header/footer } const terminalWidth = process.stdout.columns || 150; const availableWidth = terminalWidth - (9 + 1) - 10; const colWidths = [ Math.floor(availableWidth * 0.18), // 코인 Math.floor(availableWidth * 0.12), // 현재가 Math.floor(availableWidth * 0.08), // 체결강도 Math.floor(availableWidth * 0.08), // 수익률 Math.floor(availableWidth * 0.09), // 전일대비 Math.floor(availableWidth * 0.11), // 전일대비금액 Math.floor(availableWidth * 0.11), // 전일종가 Math.floor(availableWidth * 0.12), // 고가 Math.floor(availableWidth * 0.11), // 저가 ]; const table = new cli_table3_1.default({ head: [ chalk_1.default.magentaBright("코인"), chalk_1.default.magentaBright("현재가"), chalk_1.default.magentaBright("체결강도"), chalk_1.default.magentaBright("수익률"), chalk_1.default.magentaBright("전일대비"), chalk_1.default.magentaBright("전일대비금액"), chalk_1.default.magentaBright("전일종가"), chalk_1.default.magentaBright("고가"), chalk_1.default.magentaBright("저가"), ], colWidths: colWidths, wordWrap: true, }); const sortedData = Array.from(data.values()).sort((a, b) => { if (sortBy === "name") return a.symbol.localeCompare(b.symbol); return b.priceChangeRate - a.priceChangeRate; }); const displayData = sortedData.slice(0, currentDisplayLimit); for (const d of displayData) { let profitLossStr = "-"; let profitLossColor = chalk_1.default.white; if (d.profitLossRate !== undefined) { profitLossStr = `${d.profitLossRate.toFixed(2)}%`; if (d.profitLossRate > 0) profitLossColor = chalk_1.default.green; else if (d.profitLossRate < 0) profitLossColor = chalk_1.default.red; } let rateColor = chalk_1.default.white; if (d.priceChangeRate > 0) rateColor = chalk_1.default.green; else if (d.priceChangeRate < 0) rateColor = chalk_1.default.red; const highPricePercent = d.prevClosePrice > 0 ? ((d.highPrice - d.prevClosePrice) / d.prevClosePrice) * 100 : 0; const lowPricePercent = d.prevClosePrice > 0 ? ((d.lowPrice - d.prevClosePrice) / d.prevClosePrice) * 100 : 0; table.push([ chalk_1.default.yellow(`${d.icon} ${d.koreanName}`), d.priceColor(`${d.currentPrice.toLocaleString("ko-KR")} KRW`), d.volumePower?.toFixed(2) || "-", profitLossColor(profitLossStr), rateColor(`${d.priceChangeRate.toFixed(2)}%`), rateColor(`${d.priceChangeAmount.toLocaleString("ko-KR")} KRW`), d.prevClosePrice.toLocaleString("ko-KR"), `${highPricePercent >= 0 ? chalk_1.default.green(`+${highPricePercent.toFixed(2)}%`) : chalk_1.default.red(`${highPricePercent.toFixed(2)}%`)} (${d.highPrice.toLocaleString("ko-KR")})`, `${lowPricePercent >= 0 ? chalk_1.default.green(`+${lowPricePercent.toFixed(2)}%`) : chalk_1.default.red(`${lowPricePercent.toFixed(2)}%`)} (${d.lowPrice.toLocaleString("ko-KR")})`, ]); } const output = []; output.push(chalk_1.default.bold(`${exchangeName} 실시간 시세 (Ctrl+C to exit)`)); // Market sentiment logic can be re-added here if needed output.push(table.toString()); if (sortedData.length > currentDisplayLimit) { output.push(chalk_1.default.yellow(`표시가 ${currentDisplayLimit}개로 제한되었습니다. (총 ${sortedData.length}개)`)); } process.stdout.write(output.join("\n")); }