games_app/backend/dist-test-faq/services/candleGenerationService.d.ts

101 lines
3.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Synthetic candle generation and stake-pool outcome resolution.
*/
export type RoundOutcome = {
type: 'short_win';
winner: 'short';
neutralColor: null;
} | {
type: 'long_win';
winner: 'long';
neutralColor: null;
} | {
type: 'neutral';
winner: null;
neutralColor: 'red' | 'green';
};
export type GeneratedCandle = {
open: number;
high: number;
low: number;
close: number;
colorHint: 'red' | 'green';
};
export type PrevCandleOhlc = {
open: number;
high: number;
low: number;
close: number;
};
export declare function defaultSeedCandle(price: number): PrevCandleOhlc;
/**
* Resolves round outcome from stake pools.
* Winner side is chosen by pool_winner_rule when pools are not neutral; otherwise neutral (push).
*/
export type PoolWinnerRule = 'minority' | 'majority';
export type PoolNeutralityRules = {
/** When |short% − long%| <= this value, round is neutral (pools too close). */
minTolerancePercent: number;
/** When max(short%, long%) >= this value, round is neutral (pools too one-sided). */
maxTolerancePercent: number;
minToleranceEnabled: boolean;
maxToleranceEnabled: boolean;
};
/**
* Shared neutrality checks used by majority/minority and daily-revenue modes.
* Returns a neutral outcome when rules apply; otherwise null.
*/
export declare function resolvePoolNeutrality(shortPool: number, longPool: number, rules: PoolNeutralityRules): RoundOutcome | null;
export declare function resolvePoolOutcome(shortPool: number, longPool: number, rules: PoolNeutralityRules, poolWinnerRule?: PoolWinnerRule): RoundOutcome;
export type DirectionalOutcomeType = 'short_win' | 'long_win';
/** Default streak cap when admin config is missing / unset. */
export declare const DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION = 5;
/**
* Clamp admin value: `0` disables the cap; otherwise `1..50`.
*/
export declare function normalizeMaxConsecutiveSameDirection(value: unknown): number;
/**
* Counts how many of the most recent directional outcomes (short/long) share the same type.
* Neutral outcomes break the streak and are skipped.
*/
export declare function countConsecutiveDirectionalOutcomes(recentOutcomesNewestFirst: Array<'short_win' | 'long_win' | 'neutral'>): {
type: DirectionalOutcomeType | null;
count: number;
};
/**
* Random short/long outcome for rounds with no player predictions.
* After `maxConsecutiveSameDirection` consecutive candles of the same direction,
* the next must be the opposite. Pass `0` to disable the cap (pure random).
*/
export declare function resolveAutoNoBetOutcome(recentOutcomesNewestFirst: Array<'short_win' | 'long_win' | 'neutral'>, maxConsecutiveSameDirection?: number): Extract<RoundOutcome, {
type: DirectionalOutcomeType;
}>;
/**
* Neutral = exact copy of previous OHLC (same body, wicks, and price level).
* Only colorHint differs for display.
*/
export declare function replicateNeutralCandle(prev: PrevCandleOhlc, colorHint: 'red' | 'green'): GeneratedCandle;
/**
* Builds OHLC for the synthetic candle following the resolved outcome.
* Long candles anchor at the top-right of the previous body; short at the bottom-right.
*/
export declare function generateSyntheticCandle(prev: PrevCandleOhlc, outcome: RoundOutcome): GeneratedCandle;
//# sourceMappingURL=candleGenerationService.d.ts.map