UNPKG

@thoshpathi/utils-smartapi

Version:

Extended utilities for Angel One's smartapi-javascript SDK, including custom methods and helpers for market data like candles, P&L, and more.

44 lines (42 loc) 1.6 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/pl_utils.ts var pl_utils_exports = {}; __export(pl_utils_exports, { calculatePL: () => calculatePL, isProfitReached: () => isProfitReached, isStoplossReached: () => isStoplossReached }); module.exports = __toCommonJS(pl_utils_exports); function isProfitReached({ entry, points, trend, ltp }) { return trend === "BUY" ? ltp >= entry + points : ltp <= entry - points; } function isStoplossReached({ entry, points, trend, ltp }) { return trend === "BUY" ? ltp <= entry - points : ltp >= entry + points; } function calculatePL({ entry, qty, trend, ltp }) { const points = trend === "BUY" ? ltp - entry : entry - ltp; return points * qty; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { calculatePL, isProfitReached, isStoplossReached });