/** * Event handlers: position.opened/closed/flipped/increased/decreased. * Strategy close is not handled; position.closed events cover positions closed by strategy close. * Flush state before emitting (atomicity). */ import type { SenpiEventBus } from "./bus-types.js"; import type { StrategyState } from "../../types/strategy.js"; import type { DslPluginConfig, DslCreatedTriggerReason, PositionOpenedEvent } from "../../types/dsl/index.js"; import type { StateManager } from "../../state/index.js"; import type { NotifiedStopCarry } from "./initial-state.js"; export interface HandlePositionOpenedOpts { /** When false, skip the initial editPosition SL placement; slOrderId stays null. Default true. */ placeSl?: boolean; /** * Announced-stop state to carry into the rebuilt state * (increase/decrease/resize/adopt). Threaded through to {@link buildInitialState} * so a mid-trading rebuild — which mints a fresh correlationId and resets the * in-memory ratchet — cannot re-announce a lower stop, re-announce breakeven, or * re-open the trail cooldown. Omitted for a fresh open and deliberately NOT set * on a flip (favorable polarity inverts). */ carryNotifiedStop?: NotifiedStopCarry; /** * The tick that observed the change, for a caller that normalizes its payload before re-entering * the open path — the rebuild shapes (increase/decrease/flip) have no room for the id, so it is * read from the original payload and passed here instead. The monitor-driven reconcile passes its * tick here too; the boot reconcile runs before any tick exists and passes none. */ tickId?: string; } export declare function createEventHandlers(config: DslPluginConfig, stateManager: StateManager, strategyStates: Map, bus: SenpiEventBus, _baseDir: string): { handlePositionOpened: (payload: unknown, triggerReason?: DslCreatedTriggerReason, opts?: HandlePositionOpenedOpts) => Promise; handlePositionClosed: (payload: unknown) => Promise; handlePositionFlipped: (payload: unknown) => Promise; handlePositionIncreased: (payload: unknown) => Promise; handlePositionDecreased: (payload: unknown) => Promise; /** Returns count of active DSL positions archived (`dsl.deleted` emitted per position). */ deleteDslsForStrategy: (address: string) => Promise; isSlPlacementInProgress: (key: string) => boolean; /** * Adopt an orphaned exchange position into DSL without emitting bus position.opened. * With placeSl=false (default for adoption), SL placement is skipped — the monitor will * place it on the next tick via shouldSyncExchangeSl (slOrderId === null). */ adoptPosition: (payload: PositionOpenedEvent, opts?: HandlePositionOpenedOpts) => Promise; /** * Resize: archive any existing ACTIVE DSL state for the (coin,dex), then adopt fresh. * Uses RECONCILE_RESIZE as the archive close reason. * Releases the archive lock before calling adoptPosition to avoid deadlock. */ resizePosition: (payload: PositionOpenedEvent, opts?: HandlePositionOpenedOpts) => Promise; }; //# sourceMappingURL=handlers.d.ts.map