After adding controls for générations candles when none is playing
This commit is contained in:
parent
362bd1b0de
commit
af8477a987
@ -32,9 +32,10 @@ declare function mapConfig(row: repo.CandlePredictConfigRow): {
|
||||
quoteCurrency: string;
|
||||
priceDigits: number;
|
||||
};
|
||||
maxConsecutiveSameDirection: number;
|
||||
updatedAt: string;
|
||||
};
|
||||
type PlayerConfigDto = Omit<ReturnType<typeof mapConfig>, 'poolWinnerRule' | 'poolMultiplier' | 'tieTolerancePercent' | 'tieToleranceMaxPercent' | 'tieToleranceMinEnabled' | 'tieToleranceMaxEnabled' | 'dailyRevenueTarget' | 'dailyRevenueOverflowStrategy'>;
|
||||
type PlayerConfigDto = Omit<ReturnType<typeof mapConfig>, 'poolWinnerRule' | 'poolMultiplier' | 'tieTolerancePercent' | 'tieToleranceMaxPercent' | 'tieToleranceMinEnabled' | 'tieToleranceMaxEnabled' | 'dailyRevenueTarget' | 'dailyRevenueOverflowStrategy' | 'maxConsecutiveSameDirection'>;
|
||||
export type ResolvedInterval = {
|
||||
id: number;
|
||||
intervalMinutes: number;
|
||||
@ -102,6 +103,7 @@ export declare function getPublicConfig(): Promise<{
|
||||
quoteCurrency: string;
|
||||
priceDigits: number;
|
||||
};
|
||||
maxConsecutiveSameDirection: number;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
export declare function updateAdminConfig(body: Record<string, unknown>): Promise<{
|
||||
@ -135,6 +137,7 @@ export declare function updateAdminConfig(body: Record<string, unknown>): Promis
|
||||
quoteCurrency: string;
|
||||
priceDigits: number;
|
||||
};
|
||||
maxConsecutiveSameDirection: number;
|
||||
updatedAt: string;
|
||||
}>;
|
||||
export declare function listAdminIntervals(): Promise<{
|
||||
@ -228,6 +231,7 @@ export declare function getGameState(userId?: string, intervalMinutes?: number,
|
||||
quoteCurrency: string;
|
||||
priceDigits: number;
|
||||
};
|
||||
maxConsecutiveSameDirection: number;
|
||||
updatedAt: string;
|
||||
};
|
||||
intervals: PlayerIntervalDto[];
|
||||
|
||||
@ -1 +1 @@
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B,oBAAoB,CACxC,MAAM,EAAE,MAAM,EACd,IAAI,SAAI,EACR,QAAQ,SAAK,EACb,eAAe,CAAC,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;;;;;;;;;;;wBApsDD,IAAI,CAAC,cAAc;;;;;;;GAstD3E;AAED,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;;;oBAxtDO,IAAI,CAAC,cAAc;;KA2tD3E;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;kBAmE1D,MAAM,GAAG,IAAI;GAwBtC;AAED,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM;;;;;;;;;GAwBnD;AAED,wBAAsB,oBAAoB;;;;;;;KAGzC;AAED,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;KA+BzE;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE;IACL,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,OAAO,GAAG,MAAM,CAAC,EAAE,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,WAAW,CAAC;CAChC;;;;;;;;;;;;;;;;GA6HF;AAED,wBAAgB,wBAAwB,IAAI,IAAI,CAqB/C"}
|
||||
32
backend/dist/domain/candle-predict/index.js
vendored
32
backend/dist/domain/candle-predict/index.js
vendored
@ -237,11 +237,12 @@ function mapConfig(row) {
|
||||
quoteCurrency: row.instrument_quote_currency ?? 'USDT',
|
||||
priceDigits: Number(row.instrument_price_digits ?? 2),
|
||||
},
|
||||
maxConsecutiveSameDirection: (0, candleGenerationService_1.normalizeMaxConsecutiveSameDirection)(row.max_consecutive_same_direction ?? candleGenerationService_1.DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION),
|
||||
updatedAt: row.updated_at.toISOString(),
|
||||
};
|
||||
}
|
||||
function mapConfigForPlayer(row) {
|
||||
const { poolWinnerRule: _poolWinnerRule, poolMultiplier: _poolMultiplier, tieTolerancePercent: _min, tieToleranceMaxPercent: _max, tieToleranceMinEnabled: _minEn, tieToleranceMaxEnabled: _maxEn, dailyRevenueTarget: _drt, dailyRevenueOverflowStrategy: _dros, ...player } = mapConfig(row);
|
||||
const { poolWinnerRule: _poolWinnerRule, poolMultiplier: _poolMultiplier, tieTolerancePercent: _min, tieToleranceMaxPercent: _max, tieToleranceMinEnabled: _minEn, tieToleranceMaxEnabled: _maxEn, dailyRevenueTarget: _drt, dailyRevenueOverflowStrategy: _dros, maxConsecutiveSameDirection: _maxConsec, ...player } = mapConfig(row);
|
||||
return player;
|
||||
}
|
||||
function resolveInterval(global, row) {
|
||||
@ -525,6 +526,15 @@ async function updateAdminConfig(body) {
|
||||
instrumentPriceDigits > 8)) {
|
||||
throw new Error('instrument.priceDigits must be an integer between 0 and 8');
|
||||
}
|
||||
let maxConsecutiveSameDirection;
|
||||
if (typeof body.maxConsecutiveSameDirection === 'number') {
|
||||
if (!Number.isInteger(body.maxConsecutiveSameDirection) ||
|
||||
body.maxConsecutiveSameDirection < 0 ||
|
||||
body.maxConsecutiveSameDirection > 50) {
|
||||
throw new Error('maxConsecutiveSameDirection must be an integer between 0 and 50');
|
||||
}
|
||||
maxConsecutiveSameDirection = body.maxConsecutiveSameDirection;
|
||||
}
|
||||
const updated = await repo.updateConfig({
|
||||
stakeAmounts,
|
||||
minStakeAmount,
|
||||
@ -570,6 +580,7 @@ async function updateAdminConfig(body) {
|
||||
instrumentDisplayName,
|
||||
instrumentQuoteCurrency,
|
||||
instrumentPriceDigits,
|
||||
maxConsecutiveSameDirection,
|
||||
});
|
||||
// Global enable toggles should win over stale per-interval "on/off" overrides.
|
||||
if (typeof body.tieToleranceMinEnabled === 'boolean' ||
|
||||
@ -1072,7 +1083,7 @@ async function settleMaturityAtOpenMs(candleOpenMs, cfg) {
|
||||
let shared;
|
||||
if (rule === 'daily_revenue') {
|
||||
const neutralityRules = buildPoolNeutralityRules(cfg, primary);
|
||||
shared = await resolveDailyRevenueSharedOutcome(cfg, shortPool, longPool, candleOpenMs, neutralityRules);
|
||||
shared = await resolveDailyRevenueSharedOutcome(cfg, shortPool, longPool, candleOpenMs, neutralityRules, primary.intervalMinutes);
|
||||
}
|
||||
else {
|
||||
const neutralityRules = buildPoolNeutralityRules(cfg, primary);
|
||||
@ -1121,10 +1132,12 @@ async function settleMaturityAtOpenMs(candleOpenMs, cfg) {
|
||||
}
|
||||
else {
|
||||
// No real-money stake: each interval uses its own history so the
|
||||
// max-5 consecutive same-direction rule applies on every chart.
|
||||
// consecutive same-direction rule applies on every chart.
|
||||
const maxConsecutive = (0, candleGenerationService_1.normalizeMaxConsecutiveSameDirection)(cfg.max_consecutive_same_direction ?? candleGenerationService_1.DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION);
|
||||
const lookback = Math.max(10, maxConsecutive || 10);
|
||||
for (const interval of aligning) {
|
||||
const recentOutcomes = await repo.listRecentCandleOutcomes(interval.intervalMinutes, 10);
|
||||
outcomesByIntervalMinutes.set(interval.intervalMinutes, (0, candleGenerationService_1.resolveAutoNoBetOutcome)(recentOutcomes));
|
||||
const recentOutcomes = await repo.listRecentCandleOutcomes(interval.intervalMinutes, lookback);
|
||||
outcomesByIntervalMinutes.set(interval.intervalMinutes, (0, candleGenerationService_1.resolveAutoNoBetOutcome)(recentOutcomes, maxConsecutive));
|
||||
}
|
||||
const outcomeForInterval = (intervalMinutes) => outcomesByIntervalMinutes.get(intervalMinutes) ??
|
||||
outcomesByIntervalMinutes.get(primary.intervalMinutes);
|
||||
@ -1162,10 +1175,15 @@ async function settleMaturityAtOpenMs(candleOpenMs, cfg) {
|
||||
_settlingInProgress.delete(candleOpenMs);
|
||||
}
|
||||
}
|
||||
async function resolveDailyRevenueSharedOutcome(cfg, shortPool, longPool, candleOpenMs, neutralityRules) {
|
||||
async function resolveDailyRevenueSharedOutcome(cfg, shortPool, longPool, candleOpenMs, neutralityRules, primaryIntervalMinutes) {
|
||||
const revenueDate = (0, dailyRevenueOutcomeService_1.utcRevenueDate)();
|
||||
const dailyNetRaw = await repo.getOrCreateDailyRevenueNetRaw(revenueDate);
|
||||
const random = (0, dailyRevenueOutcomeService_1.pickRandomDirectionalOutcome)();
|
||||
// Same consecutive-direction cap as auto/no-bet random generation.
|
||||
// Financial gate below is unchanged: streak only shapes the initial randomWinner.
|
||||
const maxConsecutive = (0, candleGenerationService_1.normalizeMaxConsecutiveSameDirection)(cfg.max_consecutive_same_direction ?? candleGenerationService_1.DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION);
|
||||
const lookback = Math.max(10, maxConsecutive || 10);
|
||||
const recentOutcomes = await repo.listRecentCandleOutcomes(primaryIntervalMinutes, lookback);
|
||||
const random = (0, candleGenerationService_1.resolveAutoNoBetOutcome)(recentOutcomes, maxConsecutive);
|
||||
const randomWinner = random.winner ?? 'long';
|
||||
const majority = shortPool === longPool ? null : shortPool > longPool ? 'short' : 'long';
|
||||
let projectedMajorityRoundPnlRaw = 0n;
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -32,6 +32,11 @@ export type CandlePredictConfigRow = {
|
||||
instrument_quote_currency: string;
|
||||
/** Decimal places for chart price labels */
|
||||
instrument_price_digits: number;
|
||||
/**
|
||||
* Max consecutive same-direction candles in auto/random (no real-money) mode.
|
||||
* `0` = no cap.
|
||||
*/
|
||||
max_consecutive_same_direction: number;
|
||||
updated_at: Date;
|
||||
};
|
||||
export type CandlePredictMultiLevelRow = {
|
||||
@ -151,6 +156,7 @@ export type ConfigUpdate = Partial<{
|
||||
instrumentDisplayName: string;
|
||||
instrumentQuoteCurrency: string;
|
||||
instrumentPriceDigits: number;
|
||||
maxConsecutiveSameDirection: number;
|
||||
}>;
|
||||
export declare function updateConfig(update: ConfigUpdate): Promise<CandlePredictConfigRow>;
|
||||
/**
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -99,6 +99,7 @@ async function updateConfig(update) {
|
||||
instrument_display_name = $24,
|
||||
instrument_quote_currency = $25,
|
||||
instrument_price_digits = $26,
|
||||
max_consecutive_same_direction = $27,
|
||||
updated_at = NOW()
|
||||
WHERE id = 1
|
||||
RETURNING *`, [
|
||||
@ -130,6 +131,9 @@ async function updateConfig(update) {
|
||||
update.instrumentDisplayName ?? current.instrument_display_name ?? 'Full Option',
|
||||
update.instrumentQuoteCurrency ?? current.instrument_quote_currency ?? 'USDT',
|
||||
update.instrumentPriceDigits ?? current.instrument_price_digits ?? 2,
|
||||
update.maxConsecutiveSameDirection ??
|
||||
current.max_consecutive_same_direction ??
|
||||
5,
|
||||
]);
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -53,6 +53,12 @@ export type PoolNeutralityRules = {
|
||||
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.
|
||||
@ -68,10 +74,12 @@ export declare function countConsecutiveDirectionalOutcomes(recentOutcomesNewest
|
||||
|
||||
* Random short/long outcome for rounds with no player predictions.
|
||||
|
||||
* After five consecutive candles of the same direction, the next must be the opposite.
|
||||
* 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'>): Extract<RoundOutcome, {
|
||||
export declare function resolveAutoNoBetOutcome(recentOutcomesNewestFirst: Array<'short_win' | 'long_win' | 'neutral'>, maxConsecutiveSameDirection?: number): Extract<RoundOutcome, {
|
||||
type: DirectionalOutcomeType;
|
||||
}>;
|
||||
/**
|
||||
|
||||
@ -1 +1 @@
|
||||
{"version":3,"file":"candleGenerationService.d.ts","sourceRoot":"","sources":["../../src/services/candleGenerationService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,MAAM,YAAY,GAEpB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,IAAI,CAAA;CAAE,GAE1D;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,IAAI,CAAA;CAAE,GAExD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC;IAAC,YAAY,EAAE,KAAK,GAAG,OAAO,CAAA;CAAE,CAAC;AAIrE,MAAM,MAAM,eAAe,GAAG;IAE5B,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,EAAE,MAAM,CAAC;IAEZ,KAAK,EAAE,MAAM,CAAC;IAEd,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC;CAE5B,CAAC;AAIF,MAAM,MAAM,cAAc,GAAG;IAE3B,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,EAAE,MAAM,CAAC;IAEZ,KAAK,EAAE,MAAM,CAAC;CAEf,CAAC;AAIF,wBAAg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ored
@ -5,9 +5,11 @@
|
||||
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION = void 0;
|
||||
exports.defaultSeedCandle = defaultSeedCandle;
|
||||
exports.resolvePoolNeutrality = resolvePoolNeutrality;
|
||||
exports.resolvePoolOutcome = resolvePoolOutcome;
|
||||
exports.normalizeMaxConsecutiveSameDirection = normalizeMaxConsecutiveSameDirection;
|
||||
exports.countConsecutiveDirectionalOutcomes = countConsecutiveDirectionalOutcomes;
|
||||
exports.resolveAutoNoBetOutcome = resolveAutoNoBetOutcome;
|
||||
exports.replicateNeutralCandle = replicateNeutralCandle;
|
||||
@ -70,7 +72,17 @@ function resolvePoolOutcome(shortPool, longPool, rules, poolWinnerRule = 'minori
|
||||
}
|
||||
return { type: 'long_win', winner: 'long', neutralColor: null };
|
||||
}
|
||||
const MAX_CONSECUTIVE_SAME_DIRECTION = 5;
|
||||
/** Default streak cap when admin config is missing / unset. */
|
||||
exports.DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION = 5;
|
||||
/**
|
||||
* Clamp admin value: `0` disables the cap; otherwise `1..50`.
|
||||
*/
|
||||
function normalizeMaxConsecutiveSameDirection(value) {
|
||||
const n = typeof value === 'number' ? value : Number(value);
|
||||
if (!Number.isFinite(n) || n <= 0)
|
||||
return 0;
|
||||
return Math.min(50, Math.max(1, Math.floor(n)));
|
||||
}
|
||||
/**
|
||||
|
||||
* Counts how many of the most recent directional outcomes (short/long) share the same type.
|
||||
@ -102,12 +114,15 @@ function countConsecutiveDirectionalOutcomes(recentOutcomesNewestFirst) {
|
||||
|
||||
* Random short/long outcome for rounds with no player predictions.
|
||||
|
||||
* After five consecutive candles of the same direction, the next must be the opposite.
|
||||
* After `maxConsecutiveSameDirection` consecutive candles of the same direction,
|
||||
|
||||
* the next must be the opposite. Pass `0` to disable the cap (pure random).
|
||||
|
||||
*/
|
||||
function resolveAutoNoBetOutcome(recentOutcomesNewestFirst) {
|
||||
function resolveAutoNoBetOutcome(recentOutcomesNewestFirst, maxConsecutiveSameDirection = exports.DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION) {
|
||||
const maxConsecutive = normalizeMaxConsecutiveSameDirection(maxConsecutiveSameDirection);
|
||||
const { type, count } = countConsecutiveDirectionalOutcomes(recentOutcomesNewestFirst);
|
||||
if (type && count >= MAX_CONSECUTIVE_SAME_DIRECTION) {
|
||||
if (maxConsecutive > 0 && type && count >= maxConsecutive) {
|
||||
return type === 'short_win'
|
||||
? { type: 'long_win', winner: 'long', neutralColor: null }
|
||||
: { type: 'short_win', winner: 'short', neutralColor: null };
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -96,16 +96,43 @@ const defaultRules = {
|
||||
'short_win',
|
||||
'short_win',
|
||||
];
|
||||
const outcome = (0, candleGenerationService_1.resolveAutoNoBetOutcome)([...recent]);
|
||||
const outcome = (0, candleGenerationService_1.resolveAutoNoBetOutcome)([...recent], 5);
|
||||
strict_1.default.equal(outcome.type, 'long_win');
|
||||
strict_1.default.equal(outcome.winner, 'long');
|
||||
});
|
||||
(0, node_test_1.test)('respects a custom consecutive cap', () => {
|
||||
const recent = ['long_win', 'long_win', 'long_win'];
|
||||
const outcome = (0, candleGenerationService_1.resolveAutoNoBetOutcome)([...recent], 3);
|
||||
strict_1.default.equal(outcome.type, 'short_win');
|
||||
});
|
||||
(0, node_test_1.test)('disables the cap when max is 0', () => {
|
||||
const recent = [
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
];
|
||||
let sawLong = false;
|
||||
let sawShort = false;
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const outcome = (0, candleGenerationService_1.resolveAutoNoBetOutcome)([...recent], 0);
|
||||
if (outcome.type === 'long_win')
|
||||
sawLong = true;
|
||||
if (outcome.type === 'short_win')
|
||||
sawShort = true;
|
||||
if (sawLong && sawShort)
|
||||
break;
|
||||
}
|
||||
strict_1.default.equal(sawLong && sawShort, true);
|
||||
});
|
||||
(0, node_test_1.test)('does not force flip before 5 consecutive', () => {
|
||||
const recent = ['long_win', 'long_win', 'long_win', 'long_win'];
|
||||
let sawLong = false;
|
||||
let sawShort = false;
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const outcome = (0, candleGenerationService_1.resolveAutoNoBetOutcome)([...recent]);
|
||||
const outcome = (0, candleGenerationService_1.resolveAutoNoBetOutcome)([...recent], 5);
|
||||
if (outcome.type === 'long_win')
|
||||
sawLong = true;
|
||||
if (outcome.type === 'short_win')
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -2989,3 +2989,18 @@ CREATE INDEX IF NOT EXISTS idx_mobile_app_release_events_release
|
||||
ON mobile_app_release_events (release_id, event_type, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_mobile_app_release_events_created
|
||||
ON mobile_app_release_events (created_at DESC);
|
||||
|
||||
-- Max consecutive same-direction candles in auto/random (no real-money) generation.
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_schema = 'public' AND table_name = 'candle_predict_config'
|
||||
AND column_name = 'max_consecutive_same_direction'
|
||||
) THEN
|
||||
ALTER TABLE candle_predict_config
|
||||
ADD COLUMN max_consecutive_same_direction INTEGER NOT NULL DEFAULT 5
|
||||
CHECK (max_consecutive_same_direction >= 0 AND max_consecutive_same_direction <= 50);
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
|
||||
@ -16,6 +16,8 @@ import {
|
||||
defaultSeedCandle,
|
||||
resolvePoolOutcome,
|
||||
resolveAutoNoBetOutcome,
|
||||
normalizeMaxConsecutiveSameDirection,
|
||||
DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION,
|
||||
type RoundOutcome,
|
||||
type PoolNeutralityRules,
|
||||
} from '../../services/candleGenerationService';
|
||||
@ -30,7 +32,6 @@ import * as multiService from '../../services/candlePredictMultiService';
|
||||
import * as testWalletService from '../../services/testWalletService';
|
||||
import * as soloEncouragementService from '../../services/soloEncouragementService';
|
||||
import {
|
||||
pickRandomDirectionalOutcome,
|
||||
projectMajorityWinSettlement,
|
||||
resolveDailyRevenueOutcome,
|
||||
usdtDisplayToRaw,
|
||||
@ -253,6 +254,9 @@ function mapConfig(row: repo.CandlePredictConfigRow) {
|
||||
quoteCurrency: row.instrument_quote_currency ?? 'USDT',
|
||||
priceDigits: Number(row.instrument_price_digits ?? 2),
|
||||
},
|
||||
maxConsecutiveSameDirection: normalizeMaxConsecutiveSameDirection(
|
||||
row.max_consecutive_same_direction ?? DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION
|
||||
),
|
||||
updatedAt: row.updated_at.toISOString(),
|
||||
};
|
||||
}
|
||||
@ -267,6 +271,7 @@ type PlayerConfigDto = Omit<
|
||||
| 'tieToleranceMaxEnabled'
|
||||
| 'dailyRevenueTarget'
|
||||
| 'dailyRevenueOverflowStrategy'
|
||||
| 'maxConsecutiveSameDirection'
|
||||
>;
|
||||
|
||||
function mapConfigForPlayer(row: repo.CandlePredictConfigRow): PlayerConfigDto {
|
||||
@ -279,6 +284,7 @@ function mapConfigForPlayer(row: repo.CandlePredictConfigRow): PlayerConfigDto {
|
||||
tieToleranceMaxEnabled: _maxEn,
|
||||
dailyRevenueTarget: _drt,
|
||||
dailyRevenueOverflowStrategy: _dros,
|
||||
maxConsecutiveSameDirection: _maxConsec,
|
||||
...player
|
||||
} = mapConfig(row);
|
||||
return player;
|
||||
@ -688,6 +694,18 @@ export async function updateAdminConfig(body: Record<string, unknown>) {
|
||||
throw new Error('instrument.priceDigits must be an integer between 0 and 8');
|
||||
}
|
||||
|
||||
let maxConsecutiveSameDirection: number | undefined;
|
||||
if (typeof body.maxConsecutiveSameDirection === 'number') {
|
||||
if (
|
||||
!Number.isInteger(body.maxConsecutiveSameDirection) ||
|
||||
body.maxConsecutiveSameDirection < 0 ||
|
||||
body.maxConsecutiveSameDirection > 50
|
||||
) {
|
||||
throw new Error('maxConsecutiveSameDirection must be an integer between 0 and 50');
|
||||
}
|
||||
maxConsecutiveSameDirection = body.maxConsecutiveSameDirection;
|
||||
}
|
||||
|
||||
const updated = await repo.updateConfig({
|
||||
stakeAmounts,
|
||||
minStakeAmount,
|
||||
@ -741,6 +759,7 @@ export async function updateAdminConfig(body: Record<string, unknown>) {
|
||||
instrumentDisplayName,
|
||||
instrumentQuoteCurrency,
|
||||
instrumentPriceDigits,
|
||||
maxConsecutiveSameDirection,
|
||||
});
|
||||
|
||||
// Global enable toggles should win over stale per-interval "on/off" overrides.
|
||||
@ -1389,7 +1408,8 @@ async function settleMaturityAtOpenMs(
|
||||
shortPool,
|
||||
longPool,
|
||||
candleOpenMs,
|
||||
neutralityRules
|
||||
neutralityRules,
|
||||
primary.intervalMinutes
|
||||
);
|
||||
} else {
|
||||
const neutralityRules = buildPoolNeutralityRules(cfg, primary);
|
||||
@ -1459,12 +1479,19 @@ async function settleMaturityAtOpenMs(
|
||||
await repo.withDailyRevenueLock(runPoolSettlement);
|
||||
} else {
|
||||
// No real-money stake: each interval uses its own history so the
|
||||
// max-5 consecutive same-direction rule applies on every chart.
|
||||
// consecutive same-direction rule applies on every chart.
|
||||
const maxConsecutive = normalizeMaxConsecutiveSameDirection(
|
||||
cfg.max_consecutive_same_direction ?? DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION
|
||||
);
|
||||
const lookback = Math.max(10, maxConsecutive || 10);
|
||||
for (const interval of aligning) {
|
||||
const recentOutcomes = await repo.listRecentCandleOutcomes(interval.intervalMinutes, 10);
|
||||
const recentOutcomes = await repo.listRecentCandleOutcomes(
|
||||
interval.intervalMinutes,
|
||||
lookback
|
||||
);
|
||||
outcomesByIntervalMinutes.set(
|
||||
interval.intervalMinutes,
|
||||
resolveAutoNoBetOutcome(recentOutcomes)
|
||||
resolveAutoNoBetOutcome(recentOutcomes, maxConsecutive)
|
||||
);
|
||||
}
|
||||
|
||||
@ -1527,11 +1554,22 @@ async function resolveDailyRevenueSharedOutcome(
|
||||
shortPool: number,
|
||||
longPool: number,
|
||||
candleOpenMs: number,
|
||||
neutralityRules: PoolNeutralityRules
|
||||
neutralityRules: PoolNeutralityRules,
|
||||
primaryIntervalMinutes: number
|
||||
): Promise<RoundOutcome> {
|
||||
const revenueDate = utcRevenueDate();
|
||||
const dailyNetRaw = await repo.getOrCreateDailyRevenueNetRaw(revenueDate);
|
||||
const random = pickRandomDirectionalOutcome();
|
||||
// Same consecutive-direction cap as auto/no-bet random generation.
|
||||
// Financial gate below is unchanged: streak only shapes the initial randomWinner.
|
||||
const maxConsecutive = normalizeMaxConsecutiveSameDirection(
|
||||
cfg.max_consecutive_same_direction ?? DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION
|
||||
);
|
||||
const lookback = Math.max(10, maxConsecutive || 10);
|
||||
const recentOutcomes = await repo.listRecentCandleOutcomes(
|
||||
primaryIntervalMinutes,
|
||||
lookback
|
||||
);
|
||||
const random = resolveAutoNoBetOutcome(recentOutcomes, maxConsecutive);
|
||||
const randomWinner = random.winner ?? 'long';
|
||||
|
||||
const majority: 'short' | 'long' | null =
|
||||
|
||||
@ -35,6 +35,11 @@ export type CandlePredictConfigRow = {
|
||||
instrument_quote_currency: string;
|
||||
/** Decimal places for chart price labels */
|
||||
instrument_price_digits: number;
|
||||
/**
|
||||
* Max consecutive same-direction candles in auto/random (no real-money) mode.
|
||||
* `0` = no cap.
|
||||
*/
|
||||
max_consecutive_same_direction: number;
|
||||
updated_at: Date;
|
||||
};
|
||||
|
||||
@ -170,6 +175,7 @@ export type ConfigUpdate = Partial<{
|
||||
instrumentDisplayName: string;
|
||||
instrumentQuoteCurrency: string;
|
||||
instrumentPriceDigits: number;
|
||||
maxConsecutiveSameDirection: number;
|
||||
}>;
|
||||
|
||||
export async function updateConfig(update: ConfigUpdate): Promise<CandlePredictConfigRow> {
|
||||
@ -202,6 +208,7 @@ export async function updateConfig(update: ConfigUpdate): Promise<CandlePredictC
|
||||
instrument_display_name = $24,
|
||||
instrument_quote_currency = $25,
|
||||
instrument_price_digits = $26,
|
||||
max_consecutive_same_direction = $27,
|
||||
updated_at = NOW()
|
||||
WHERE id = 1
|
||||
RETURNING *`,
|
||||
@ -234,6 +241,9 @@ export async function updateConfig(update: ConfigUpdate): Promise<CandlePredictC
|
||||
update.instrumentDisplayName ?? current.instrument_display_name ?? 'Full Option',
|
||||
update.instrumentQuoteCurrency ?? current.instrument_quote_currency ?? 'USDT',
|
||||
update.instrumentPriceDigits ?? current.instrument_price_digits ?? 2,
|
||||
update.maxConsecutiveSameDirection ??
|
||||
current.max_consecutive_same_direction ??
|
||||
5,
|
||||
]
|
||||
);
|
||||
return rows[0];
|
||||
|
||||
@ -173,9 +173,17 @@ export type DirectionalOutcomeType = 'short_win' | 'long_win';
|
||||
|
||||
|
||||
|
||||
const MAX_CONSECUTIVE_SAME_DIRECTION = 5;
|
||||
|
||||
/** Default streak cap when admin config is missing / unset. */
|
||||
export const DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION = 5;
|
||||
|
||||
/**
|
||||
* Clamp admin value: `0` disables the cap; otherwise `1..50`.
|
||||
*/
|
||||
export function normalizeMaxConsecutiveSameDirection(value: unknown): number {
|
||||
const n = typeof value === 'number' ? value : Number(value);
|
||||
if (!Number.isFinite(n) || n <= 0) return 0;
|
||||
return Math.min(50, Math.max(1, Math.floor(n)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -239,21 +247,27 @@ export function countConsecutiveDirectionalOutcomes(
|
||||
|
||||
* Random short/long outcome for rounds with no player predictions.
|
||||
|
||||
* After five consecutive candles of the same direction, the next must be the opposite.
|
||||
* After `maxConsecutiveSameDirection` consecutive candles of the same direction,
|
||||
|
||||
* the next must be the opposite. Pass `0` to disable the cap (pure random).
|
||||
|
||||
*/
|
||||
|
||||
export function resolveAutoNoBetOutcome(
|
||||
|
||||
recentOutcomesNewestFirst: Array<'short_win' | 'long_win' | 'neutral'>
|
||||
recentOutcomesNewestFirst: Array<'short_win' | 'long_win' | 'neutral'>,
|
||||
|
||||
maxConsecutiveSameDirection: number = DEFAULT_MAX_CONSECUTIVE_SAME_DIRECTION
|
||||
|
||||
): Extract<RoundOutcome, { type: DirectionalOutcomeType }> {
|
||||
|
||||
const maxConsecutive = normalizeMaxConsecutiveSameDirection(maxConsecutiveSameDirection);
|
||||
|
||||
const { type, count } = countConsecutiveDirectionalOutcomes(recentOutcomesNewestFirst);
|
||||
|
||||
|
||||
|
||||
if (type && count >= MAX_CONSECUTIVE_SAME_DIRECTION) {
|
||||
if (maxConsecutive > 0 && type && count >= maxConsecutive) {
|
||||
|
||||
return type === 'short_win'
|
||||
|
||||
|
||||
@ -3,7 +3,8 @@
|
||||
*
|
||||
* Pipeline:
|
||||
* 1. Optional shared pool neutrality (min/max tolerance, equal pools) — same as other modes.
|
||||
* 2. Random directional candle.
|
||||
* 2. Random directional candle (caller may apply the consecutive same-direction cap
|
||||
* via resolveAutoNoBetOutcome before passing randomWinner).
|
||||
* 3. Financial gate if the random pick is the majority side.
|
||||
* 4. Overflow strategy when the daily revenue floor would be breached.
|
||||
*/
|
||||
|
||||
@ -113,17 +113,43 @@ describe('resolveAutoNoBetOutcome consecutive direction cap', () => {
|
||||
'short_win',
|
||||
'short_win',
|
||||
] as const;
|
||||
const outcome = resolveAutoNoBetOutcome([...recent]);
|
||||
const outcome = resolveAutoNoBetOutcome([...recent], 5);
|
||||
assert.equal(outcome.type, 'long_win');
|
||||
assert.equal(outcome.winner, 'long');
|
||||
});
|
||||
|
||||
test('respects a custom consecutive cap', () => {
|
||||
const recent = ['long_win', 'long_win', 'long_win'] as const;
|
||||
const outcome = resolveAutoNoBetOutcome([...recent], 3);
|
||||
assert.equal(outcome.type, 'short_win');
|
||||
});
|
||||
|
||||
test('disables the cap when max is 0', () => {
|
||||
const recent = [
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
'short_win',
|
||||
] as const;
|
||||
let sawLong = false;
|
||||
let sawShort = false;
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const outcome = resolveAutoNoBetOutcome([...recent], 0);
|
||||
if (outcome.type === 'long_win') sawLong = true;
|
||||
if (outcome.type === 'short_win') sawShort = true;
|
||||
if (sawLong && sawShort) break;
|
||||
}
|
||||
assert.equal(sawLong && sawShort, true);
|
||||
});
|
||||
|
||||
test('does not force flip before 5 consecutive', () => {
|
||||
const recent = ['long_win', 'long_win', 'long_win', 'long_win'] as const;
|
||||
let sawLong = false;
|
||||
let sawShort = false;
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const outcome = resolveAutoNoBetOutcome([...recent]);
|
||||
const outcome = resolveAutoNoBetOutcome([...recent], 5);
|
||||
if (outcome.type === 'long_win') sawLong = true;
|
||||
if (outcome.type === 'short_win') sawShort = true;
|
||||
if (sawLong && sawShort) break;
|
||||
|
||||
@ -6,6 +6,7 @@ import {
|
||||
projectedMajorityRoundPnl,
|
||||
resolveDailyRevenueOutcome,
|
||||
} from '../services/dailyRevenueOutcomeService';
|
||||
import { resolveAutoNoBetOutcome } from '../services/candleGenerationService';
|
||||
|
||||
describe('dailyRevenueOutcomeService', () => {
|
||||
test('pickRandomDirectionalOutcome respects RNG', () => {
|
||||
@ -42,6 +43,64 @@ describe('dailyRevenueOutcomeService', () => {
|
||||
assert.equal(outcome.winner, 'long');
|
||||
});
|
||||
|
||||
test('streak-capped randomWinner still respects financial gate (target reached)', () => {
|
||||
// 5 short in a row → streak forces long; long is majority; floor already OK → keep long.
|
||||
const streakForced = resolveAutoNoBetOutcome(
|
||||
['short_win', 'short_win', 'short_win', 'short_win', 'short_win'],
|
||||
5
|
||||
);
|
||||
assert.equal(streakForced.winner, 'long');
|
||||
const outcome = resolveDailyRevenueOutcome({
|
||||
shortPool: 30,
|
||||
longPool: 70,
|
||||
randomWinner: streakForced.winner!,
|
||||
projectedMajorityRoundPnlRaw: 1_000_000n,
|
||||
dailyNetRaw: 10_000_000n,
|
||||
targetRaw: 5_000_000n,
|
||||
overflowStrategy: 'neutral',
|
||||
});
|
||||
assert.equal(outcome.type, 'long_win');
|
||||
assert.equal(outcome.winner, 'long');
|
||||
});
|
||||
|
||||
test('streak-capped majority randomWinner still overflows when floor would breach', () => {
|
||||
const streakForced = resolveAutoNoBetOutcome(
|
||||
['short_win', 'short_win', 'short_win', 'short_win', 'short_win'],
|
||||
5
|
||||
);
|
||||
assert.equal(streakForced.winner, 'long');
|
||||
const outcome = resolveDailyRevenueOutcome({
|
||||
shortPool: 30,
|
||||
longPool: 70,
|
||||
randomWinner: streakForced.winner!,
|
||||
projectedMajorityRoundPnlRaw: -8_000_000n,
|
||||
dailyNetRaw: 10_000_000n,
|
||||
targetRaw: 5_000_000n,
|
||||
overflowStrategy: 'neutral',
|
||||
});
|
||||
assert.equal(outcome.type, 'neutral');
|
||||
});
|
||||
|
||||
test('streak-capped minority randomWinner bypasses financial gate', () => {
|
||||
// 5 long in a row → force short; short is minority → keep short regardless of floor.
|
||||
const streakForced = resolveAutoNoBetOutcome(
|
||||
['long_win', 'long_win', 'long_win', 'long_win', 'long_win'],
|
||||
5
|
||||
);
|
||||
assert.equal(streakForced.winner, 'short');
|
||||
const outcome = resolveDailyRevenueOutcome({
|
||||
shortPool: 30,
|
||||
longPool: 70,
|
||||
randomWinner: streakForced.winner!,
|
||||
projectedMajorityRoundPnlRaw: -50_000_000n,
|
||||
dailyNetRaw: 0n,
|
||||
targetRaw: 5_000_000n,
|
||||
overflowStrategy: 'neutral',
|
||||
});
|
||||
assert.equal(outcome.type, 'short_win');
|
||||
assert.equal(outcome.winner, 'short');
|
||||
});
|
||||
|
||||
test('overflow to neutral when majority would breach floor', () => {
|
||||
// daily 10 + round pnl -8 = 2 < target 5
|
||||
const outcome = resolveDailyRevenueOutcome({
|
||||
|
||||
@ -51,6 +51,7 @@ export const candlePredictAdminConfigBodySchema = atLeastOneField(
|
||||
priceDigits: z.number().int().min(0).max(8).optional(),
|
||||
})
|
||||
.optional(),
|
||||
maxConsecutiveSameDirection: z.number().int().min(0).max(50).optional(),
|
||||
instrumentSymbol: z.string().trim().min(1).max(16).optional(),
|
||||
instrumentDisplayName: z.string().trim().min(1).max(64).optional(),
|
||||
instrumentQuoteCurrency: z.string().trim().min(1).max(16).optional(),
|
||||
|
||||
@ -53,6 +53,7 @@ export function CandlePredictConfigPanel() {
|
||||
instrumentDisplayName: 'Full Option',
|
||||
instrumentQuoteCurrency: 'USDT',
|
||||
instrumentPriceDigits: 2,
|
||||
maxConsecutiveSameDirection: 5,
|
||||
});
|
||||
const [feedback, setFeedback] = useState<{ severity: 'success' | 'error'; text: string } | null>(
|
||||
null
|
||||
@ -85,6 +86,7 @@ export function CandlePredictConfigPanel() {
|
||||
quoteCurrency?: string;
|
||||
priceDigits?: number;
|
||||
};
|
||||
maxConsecutiveSameDirection?: number;
|
||||
};
|
||||
setForm({
|
||||
stakeAmounts: c.stakeAmounts.join(','),
|
||||
@ -111,6 +113,7 @@ export function CandlePredictConfigPanel() {
|
||||
instrumentDisplayName: c.instrument?.displayName ?? 'Full Option',
|
||||
instrumentQuoteCurrency: c.instrument?.quoteCurrency ?? 'USDT',
|
||||
instrumentPriceDigits: c.instrument?.priceDigits ?? 2,
|
||||
maxConsecutiveSameDirection: c.maxConsecutiveSameDirection ?? 5,
|
||||
});
|
||||
}
|
||||
}, [configQ.data]);
|
||||
@ -152,6 +155,7 @@ export function CandlePredictConfigPanel() {
|
||||
quoteCurrency: form.instrumentQuoteCurrency.trim(),
|
||||
priceDigits: form.instrumentPriceDigits,
|
||||
},
|
||||
maxConsecutiveSameDirection: form.maxConsecutiveSameDirection,
|
||||
});
|
||||
setFeedback({
|
||||
severity: 'success',
|
||||
@ -269,6 +273,17 @@ export function CandlePredictConfigPanel() {
|
||||
fullWidth
|
||||
helperText={t('admin.catalog.candlePredict.config.predictionWindowHint')}
|
||||
/>
|
||||
<TextField
|
||||
label={t('admin.catalog.candlePredict.config.maxConsecutiveSameDirection')}
|
||||
type="number"
|
||||
slotProps={{ htmlInput: { step: 1, min: 0, max: 50 } }}
|
||||
value={form.maxConsecutiveSameDirection}
|
||||
onChange={(e) =>
|
||||
setForm({ ...form, maxConsecutiveSameDirection: Number(e.target.value) })
|
||||
}
|
||||
fullWidth
|
||||
helperText={t('admin.catalog.candlePredict.config.maxConsecutiveSameDirectionHint')}
|
||||
/>
|
||||
<Typography variant="subtitle2" sx={{ gridColumn: '1 / -1', fontWeight: 800, mt: 1 }}>
|
||||
{t('admin.catalog.candlePredict.config.neutralTitle')}
|
||||
</Typography>
|
||||
|
||||
@ -1718,6 +1718,9 @@ export const en = {
|
||||
maxStake: 'Maximum stake',
|
||||
predictionWindow: 'Default prediction window (seconds)',
|
||||
predictionWindowHint: 'Default seconds before each candle close to place predictions',
|
||||
maxConsecutiveSameDirection: 'Max consecutive same-color candles (random mode)',
|
||||
maxConsecutiveSameDirectionHint:
|
||||
'Force the opposite color after this many identical candles in random generation: no real-money auto mode, and the random draw in daily-revenue mode (financial gate still applies after). Default 5. 0 = no limit.',
|
||||
neutralTitle: 'Neutral round rules',
|
||||
neutralBehavior:
|
||||
'Neutral rounds refund all stakes — no winners and no losers. Use the rules below to declare a round neutral when pools are too balanced or too one-sided.',
|
||||
|
||||
@ -1736,6 +1736,9 @@ export const fr = {
|
||||
maxStake: 'Mise maximale',
|
||||
predictionWindow: 'Fenêtre de prédiction par défaut (secondes)',
|
||||
predictionWindowHint: 'Secondes par défaut avant la clôture de chaque bougie pour placer une prédiction',
|
||||
maxConsecutiveSameDirection: 'Max. de bougies consécutives de même couleur (mode aléatoire)',
|
||||
maxConsecutiveSameDirectionHint:
|
||||
'Force la couleur opposée après ce nombre de bougies identiques en génération aléatoire : mode auto sans fonds réels, et tirage aléatoire du mode target journalier (le filtre financier s’applique ensuite). Défaut 5. 0 = pas de limite.',
|
||||
neutralTitle: 'Règles de manche neutre',
|
||||
neutralBehavior:
|
||||
'Les manches neutres remboursent toutes les mises — ni gagnants ni perdants. Utilisez les règles ci-dessous pour déclarer une manche neutre lorsque les pools sont trop équilibrés ou trop déséquilibrés.',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user