Interface PartialProfitContract

Contract for partial profit level events.

Emitted by partialProfitSubject when a signal reaches a profit level milestone (10%, 20%, 30%, etc). Used for tracking partial take-profit execution and monitoring strategy performance.

Events are emitted only once per level per signal (Set-based deduplication in ClientPartial). Multiple levels can be emitted in a single tick if price jumps significantly.

Consumers:

  • PartialMarkdownService: Accumulates events for report generation
  • User callbacks via listenPartialProfit() / listenPartialProfitOnce()
import { listenPartialProfit } from "backtest-kit";

// Listen to all partial profit events
listenPartialProfit((event) => {
console.log(`[${event.backtest ? "Backtest" : "Live"}] Signal ${event.data.id} reached ${event.level}% profit`);
console.log(`Symbol: ${event.symbol}, Price: ${event.currentPrice}`);
console.log(`Position: ${event.data.position}, Entry: ${event.data.priceOpen}`);
});

// Wait for first 50% profit level
listenPartialProfitOnce(
(event) => event.level === 50,
(event) => console.log("50% profit reached:", event.data.id)
);
interface PartialProfitContract {
    backtest: boolean;
    currentPrice: number;
    data: IPublicSignalRow;
    exchangeName: string;
    frameName: string;
    level: PartialLevel;
    strategyName: string;
    symbol: string;
    timestamp: number;
}

Properties

backtest: boolean

Execution mode flag.

  • true: Event from backtest execution (historical candle data)
  • false: Event from live trading (real-time tick)
currentPrice: number

Current market price at which this profit level was reached. Used to calculate actual profit percentage.

Complete signal row data with original prices. Contains all signal information including originalPriceStopLoss, originalPriceTakeProfit, and totalExecuted.

exchangeName: string

Exchange name where this signal is being executed. Identifies which exchange this profit event belongs to.

frameName: string

Frame name where this signal is being executed. Identifies which frame this profit event belongs to (empty string for live mode).

level: PartialLevel

Profit level milestone reached (10, 20, 30, 40, 50, 60, 70, 80, 90, or 100). Represents percentage profit relative to entry price.

// If entry was $50000 and level is 20:
// currentPrice >= $60000 (20% profit)
strategyName: string

Strategy name that generated this signal. Identifies which strategy execution this profit event belongs to.

symbol: string

Trading pair symbol (e.g., "BTCUSDT"). Identifies which market this profit event belongs to.

timestamp: number

Event timestamp in milliseconds since Unix epoch.

Timing semantics:

  • Live mode: when.getTime() at the moment profit level was detected
  • Backtest mode: candle.timestamp of the candle that triggered the level
const eventDate = new Date(event.timestamp);
console.log(`Profit reached at: ${eventDate.toISOString()}`);