Interface IRiskSignalRow

Risk signal row for internal risk management. Extends ISignalDto to include priceOpen, originalPriceStopLoss and originalPriceTakeProfit. Used in risk validation to access entry price and original SL/TP.

interface IRiskSignalRow {
    _entry?: { cost: number; price: number; timestamp: number }[];
    _isScheduled: boolean;
    _partial?: {
        costBasisAtClose: number;
        currentPrice: number;
        entryCountAtClose: number;
        percent: number;
        timestamp: number;
        type: "profit" | "loss";
    }[];
    _peak: {
        pnlCost: number;
        pnlPercentage: number;
        price: number;
        timestamp: number;
    };
    _trailingPriceStopLoss?: number;
    _trailingPriceTakeProfit?: number;
    cost: number;
    exchangeName: string;
    frameName: string;
    id: string;
    minuteEstimatedTime: number;
    note?: string;
    originalPriceOpen: number;
    originalPriceStopLoss: number;
    originalPriceTakeProfit: number;
    partialExecuted: number;
    pendingAt: number;
    pnl: IStrategyPnL;
    position: "long"
    | "short";
    priceOpen: number;
    priceStopLoss: number;
    priceTakeProfit: number;
    scheduledAt: number;
    strategyName: string;
    symbol: string;
    timestamp: number;
    totalEntries: number;
    totalPartials: number;
}

Hierarchy (View Summary)

Properties

_entry?: { cost: number; price: number; timestamp: number }[]

DCA (Dollar Cost Averaging) entry history. First element is always the original priceOpen at signal creation. Each subsequent element is a new averaging entry added by averageBuy(). Effective entry price = simple arithmetic mean of all price values. Original priceOpen is preserved unchanged for identity/audit purposes.

Type declaration

  • cost: number

    Cost of this entry in USD (e.g. 100 for $100 position)

  • price: number

    Price at which this entry was executed

  • timestamp: number

    Unix timestamp in milliseconds when this entry was executed

_isScheduled: boolean

Internal runtime marker for scheduled signals

_partial?: {
    costBasisAtClose: number;
    currentPrice: number;
    entryCountAtClose: number;
    percent: number;
    timestamp: number;
    type: "profit" | "loss";
}[]

History of partial closes for PNL calculation. Each entry contains type (profit/loss), percent closed, and price. Used to calculate weighted PNL: Σ(percent_i × pnl_i) for each partial + (remaining% × final_pnl)

Computed values (derived from this array):

  • _tpClosed: Sum of all "profit" type partial close percentages
  • _slClosed: Sum of all "loss" type partial close percentages
  • _totalClosed: Sum of all partial close percentages (profit + loss)

Type declaration

  • costBasisAtClose: number

    Running cost basis (sum of entry costs) at the moment this partial was executed, BEFORE applying the percent reduction. Stored as a snapshot so helpers don't need to replay the full entry history. Effective entry price at this partial = costBasisAtClose / Σ(entry.cost/entry.price for entries[0..entryCountAtClose])

  • currentPrice: number

    Price at which this partial was executed

  • entryCountAtClose: number

    Number of _entry elements at the moment this partial close was executed. Used to slice _entry to only entries that existed at this partial.

  • percent: number

    Percentage of position closed (0-100)

  • timestamp: number

    Unix timestamp in milliseconds when this partial close was executed

  • type: "profit" | "loss"

    Type of partial close: profit (moving toward TP) or loss (moving toward SL)

_peak: {
    pnlCost: number;
    pnlPercentage: number;
    price: number;
    timestamp: number;
}

Best price seen in profit direction during the life of this position. Initialized at position open with priceOpen/pendingAt. Updated on every tick/candle when price moves toward TP (currentDistance > 0).

  • For LONG: maximum VWAP price seen above effective entry
  • For SHORT: minimum VWAP price seen below effective entry
_trailingPriceStopLoss?: number

Trailing stop-loss price that overrides priceStopLoss when set. Updated by trailing() method based on position type and percentage distance.

  • For LONG: moves upward as price moves toward TP (never moves down)
  • For SHORT: moves downward as price moves toward TP (never moves up) When _trailingPriceStopLoss is set, it replaces priceStopLoss for TP/SL checks. Original priceStopLoss is preserved in persistence but ignored during execution.
_trailingPriceTakeProfit?: number

Trailing take-profit price that overrides priceTakeProfit when set. Created and managed by trailingTake() method for dynamic TP adjustment. Allows moving TP further from or closer to current price based on strategy. Updated by trailingTake() method based on position type and percentage distance.

  • For LONG: can move upward (further) or downward (closer) from entry
  • For SHORT: can move downward (further) or upward (closer) from entry When _trailingPriceTakeProfit is set, it replaces priceTakeProfit for TP/SL checks. Original priceTakeProfit is preserved in persistence but ignored during execution.
cost: number

Cost of the initial position entry in USD (first entry, not DCA). Inherited from ISignalRow. Explicitly surfaced here for consumer visibility.

exchangeName: string

Unique exchange identifier for execution

frameName: string

Unique frame identifier for execution (empty string for live mode)

id: string

Unique signal identifier (UUID v4 auto-generated)

minuteEstimatedTime: number

Expected duration in minutes before time_expired

note?: string

Human-readable description of signal reason

originalPriceOpen: number

Original entry price set at signal creation (unchanged by averaging). Mirrors signal.priceOpen which is preserved for identity/audit purposes.

originalPriceStopLoss: number

Original stop-loss price set at signal creation.

originalPriceTakeProfit: number

Original take-profit price set at signal creation.

partialExecuted: number

Total executed percentage from partial closes. Sum of all percent values from _partial array (both profit and loss types). Represents the total portion of the position that has been closed through partial executions. Range: 0-100. Value of 0 means no partial closes, 100 means position fully closed through partials.

pendingAt: number

Pending timestamp in milliseconds (when position became pending/active at priceOpen)

Unrealized PNL at the time this public signal was created. Calculated using toProfitLossDto with the currentPrice at the moment of emission.

position: "long" | "short"

Trade direction: "long" (buy) or "short" (sell)

priceOpen: number

Entry price for the position.

priceStopLoss: number

Stop loss exit price (must be < priceOpen for long, > priceOpen for short)

priceTakeProfit: number

Take profit target price (must be > priceOpen for long, < priceOpen for short)

scheduledAt: number

Signal creation timestamp in milliseconds (when signal was first created/scheduled)

strategyName: string

Unique strategy identifier for execution

symbol: string

Trading pair symbol (e.g., "BTCUSDT")

timestamp: number

Unix timestamp in milliseconds when this signal was created/scheduled in backtest context or when getSignal was called in live context (before validation)

totalEntries: number

Total number of entries in the DCA _entry history (_entry.length). 1 = no averaging done (only initial entry). 2+ = averaged positions.

totalPartials: number

Total number of partial closes executed (_partial.length). 0 = no partial closes done. 1+ = partial closes executed.