Skip to content

Commit

Permalink
MarketDataGenerator. Clone fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikasoukhov committed Jun 4, 2020
1 parent 36209d6 commit 4fb46bf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 28 deletions.
14 changes: 14 additions & 0 deletions Algo/Testing/MarketDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,19 @@ public RandomArray<int> Steps
}
protected set => _steps = value ?? throw new ArgumentNullException(nameof(value));
}

/// <summary>
/// Copy the message into the <paramref name="destination" />.
/// </summary>
/// <param name="destination">The object, to which copied information.</param>
protected void CopyTo(MarketDataGenerator destination)
{
destination.Interval = Interval;
destination.MinVolume = MinVolume;
destination.MaxVolume = MaxVolume;
destination.MaxPriceStepCount = MaxPriceStepCount;
destination._volumes = _volumes;
destination._steps = _steps;
}
}
}
35 changes: 19 additions & 16 deletions Algo/Testing/MarketDepthGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ protected QuoteChange CreateQuote(decimal startPrice, Sides side)

return new QuoteChange(price, Volumes.Next(), ordersCount);
}

/// <summary>
/// Copy the message into the <paramref name="destination" />.
/// </summary>
/// <param name="destination">The object, to which copied information.</param>
protected void CopyTo(MarketDepthGenerator destination)
{
base.CopyTo(destination);

destination.UseTradeVolume = UseTradeVolume;
destination.MinSpreadStepCount = MinSpreadStepCount;
destination.MaxSpreadStepCount = MaxSpreadStepCount;
destination.MaxBidsDepth = MaxBidsDepth;
destination.MaxAsksDepth = MaxAsksDepth;
destination.MaxGenerations = MaxGenerations;
}
}

/// <summary>
Expand Down Expand Up @@ -447,22 +463,9 @@ protected override Message OnProcess(Message message)
/// <returns>Copy.</returns>
public override MarketDataGenerator Clone()
{
return new TrendMarketDepthGenerator(SecurityId)
{
MaxVolume = MaxVolume,
MinVolume = MinVolume,
MaxPriceStepCount = MaxPriceStepCount,
Interval = Interval,
Volumes = Volumes,
Steps = Steps,

UseTradeVolume = UseTradeVolume,
MinSpreadStepCount = MinSpreadStepCount,
MaxSpreadStepCount = MaxSpreadStepCount,
MaxBidsDepth = MaxBidsDepth,
MaxAsksDepth = MaxAsksDepth,
MaxGenerations = MaxGenerations,
};
var clone = new TrendMarketDepthGenerator(SecurityId);
CopyTo(clone);
return clone;
}
}
}
10 changes: 8 additions & 2 deletions Algo/Testing/OrderLogGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public IdGenerator IdGenerator
/// </summary>
public override void Init()
{
TradeGenerator.Init();
base.Init();

_lastOrderPrice = default;
TradeGenerator.Init();
}

/// <inheritdoc />
Expand Down Expand Up @@ -236,11 +238,15 @@ protected override Message OnProcess(Message message)
/// <returns>Copy.</returns>
public override MarketDataGenerator Clone()
{
return new OrderLogGenerator(SecurityId, TradeGenerator.TypedClone())
var clone = new OrderLogGenerator(SecurityId, TradeGenerator.TypedClone())
{
_lastOrderPrice = _lastOrderPrice,
IdGenerator = IdGenerator
};

CopyTo(clone);

return clone;
}
}
}
23 changes: 13 additions & 10 deletions Algo/Testing/TradeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public RandomWalkTradeGenerator(SecurityId securityId)
{
}

/// <inheritdoc />
public override void Init()
{
base.Init();

_lastTradePrice = default;
}

/// <summary>
/// To generate the value for <see cref="ExecutionMessage.OriginSide"/>. By default is disabled.
/// </summary>
Expand Down Expand Up @@ -157,20 +165,15 @@ protected override Message OnProcess(Message message)
/// <returns>Copy.</returns>
public override MarketDataGenerator Clone()
{
return new RandomWalkTradeGenerator(SecurityId)
var clone = new RandomWalkTradeGenerator(SecurityId)
{
_lastTradePrice = _lastTradePrice,

MaxVolume = MaxVolume,
MinVolume = MinVolume,
MaxPriceStepCount = MaxPriceStepCount,
Interval = Interval,
Volumes = Volumes,
Steps = Steps,

GenerateOriginSide = GenerateOriginSide,
IdGenerator = IdGenerator
};

CopyTo(clone);

return clone;
}
}
}

0 comments on commit 4fb46bf

Please sign in to comment.