StockSharp/StockSharp · error · ArgumentException

{nameof(MinSpreadStepCount)} ({MinSpreadStepCount}) > {nameo

Error message

{nameof(MinSpreadStepCount)} ({MinSpreadStepCount}) > {nameof(MaxSpreadStepCount)} ({MaxSpreadStepCount})

What it means

Thrown by MarketDepthGenerator.Init() when MinSpreadStepCount is greater than MaxSpreadStepCount. The spread is sampled uniformly inside [min,max], so an inverted range is a configuration contradiction. This cross-property invariant is only checked at Init, not at each setter.

Source

Thrown at Algo.Testing/Generation/MarketDepthGenerator.cs:117

			_maxAsksDepth = value;
		}
	}

	/// <summary>
	/// Shall order books be generated after each trade. The default is <see langword="false" />.
	/// </summary>
	public bool GenerateDepthOnEachTrade { get; set; }

	/// <summary>
	/// Generate <see cref="QuoteChange.OrdersCount"/>.
	/// </summary>
	public bool GenerateOrdersCount { get; set; }

	/// <inheritdoc />
	public override void Init()
	{
		if (MinSpreadStepCount > MaxSpreadStepCount)
			throw new ArgumentException($"{nameof(MinSpreadStepCount)} ({MinSpreadStepCount}) > {nameof(MaxSpreadStepCount)} ({MaxSpreadStepCount})");

		base.Init();
	}

	private int _maxGenerations = 20;

	/// <summary>
	/// The maximal number of generations after last occurrence of source data for the order book.
	/// </summary>
	/// <remarks>
	/// The default value equals 20.
	/// </remarks>
	public int MaxGenerations
	{
		get => _maxGenerations;
		set
		{
			if (value < 1)

View on GitHub (pinned to 601a191de6)

Solutions

  1. Ensure MinSpreadStepCount <= MaxSpreadStepCount before calling Init().
  2. After loading config, normalize: if min > max, set max = min (or clamp min to max).
  3. Add a UI/validation rule that rejects inverted bounds at edit time.

Example fix

// before
gen.MinSpreadStepCount = 5;
gen.MaxSpreadStepCount = 2;
gen.Init(); // throws
// after
gen.MinSpreadStepCount = 5;
gen.MaxSpreadStepCount = Math.Max(5, cfgMax);
gen.Init();
Defensive patterns

Strategy: validation

Validate before calling

if (minSpread > maxSpread)
    throw new InvalidOperationException($"min {minSpread} > max {maxSpread}");
gen.MinSpreadStepCount = minSpread;
gen.MaxSpreadStepCount = maxSpread;
gen.Init();

Prevention

When it happens

Trigger: Calling gen.Init() after setting MinSpreadStepCount above MaxSpreadStepCount (e.g. Min=5, Max=2). Also fires if you raise Min without also raising Max, or lower Max below an existing Min.

Common situations: Config where min-spread > max-spread; UI letting users set bounds independently without a cross-check; loading partial overrides that leave the pair inconsistent.

Related errors


AI-assisted analysis of StockSharp/StockSharp@601a191de6 (2026-08-13). Data as JSON: /api/errors/3fcb2ec5849e0bd6. Report an issue: GitHub.