UNPKG

trading-core-lib

Version:
58 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function percentage({ value, total }) { if (total === 0) return 0; return (value / total) * 100; } /** * 전체 기준에서 여러 단계의 퍼센트 할당을 곱해서 실제 비율을 계산합니다. * @param percentages 퍼센트 배열 (예: [25, 5]이면 25%에서 다시 5%) * @returns 전체에서 차지하는 실제 퍼센트 (예: 1.25) */ function calculateNestedPercentage(percentages) { // 퍼센트를 비율로 변환 후 곱셈 const ratio = percentages.reduce((acc, curr) => acc * (curr / 100), 1); // 다시 퍼센트로 환산 return ratio * 100; } function calculateTPSLPrices(side, entryOrOrderPrice, tradingConfig) { // Use config values directly (assuming they are percentages 1-100) const { takeProfit, stopLoss, leverage } = tradingConfig; // 레버리지 고려한 실제 퍼센트 계산 (API값 / 100 필요) const actualTpPercent = takeProfit * leverage; // No *100 needed if API is 1-100 const actualSlPercent = stopLoss * leverage; // No *100 needed if API is 1-100 let tpPrice, slPrice; if (side === "Buy") { tpPrice = entryOrOrderPrice * (1 + actualTpPercent / 100); slPrice = entryOrOrderPrice * (1 - actualSlPercent / 100); } else { // side === "Sell" tpPrice = entryOrOrderPrice * (1 - actualTpPercent / 100); slPrice = entryOrOrderPrice * (1 + actualSlPercent / 100); } return { tpPrice, slPrice }; } /** * 레버리지와 방향을 고려한 가격을 계산합니다. * @param side 거래 방향 ('Buy' | 'Sell') * @param avgPrice 평균 진입가 * @param priceChange 가격 변동 퍼센트 * @param leverage 레버리지 * @returns 레버리지가 적용된 가격 */ function calculateLeveragedPrice(side, avgPrice, priceChange, leverage) { // 레버리지로 나누어 실제 가격 변동 퍼센트 계산 const actualPriceChange = priceChange / leverage; return side === "Buy" ? avgPrice * (1 + actualPriceChange / 100) // 롱: 진입가 + (본절% / 레버리지) : avgPrice * (1 - actualPriceChange / 100); // 숏: 진입가 - (본절% / 레버리지) } exports.default = { percentage, calculateNestedPercentage, calculateTPSLPrices, calculateLeveragedPrice, }; //# sourceMappingURL=calculators.js.map