Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Algorithm/QCAlgorithm.History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ private void SetWarmup(int? barCount, TimeSpan? timeSpan, Resolution? resolution
{
if (_locked)
{
throw new InvalidOperationException("QCAlgorithm.SetWarmup(): This method cannot be used after algorithm initialized");
throw new InvalidOperationException(Messages.QCAlgorithm.SetWarmupAlreadyInitialized());
}

_warmupTimeSpan = timeSpan;
Expand Down
19 changes: 9 additions & 10 deletions Algorithm/QCAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ public void SetTimeZone(DateTimeZone timeZone)
{
if (_locked)
{
throw new InvalidOperationException("Algorithm.SetTimeZone(): Cannot change time zone after algorithm running.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetTimeZoneAlreadyRunning());
}

if (timeZone == null) throw new ArgumentNullException(nameof(timeZone));
Expand Down Expand Up @@ -1450,7 +1450,7 @@ public void SetBenchmark(SecurityType securityType, string symbol)
{
if (_locked)
{
throw new InvalidOperationException("Algorithm.SetBenchmark(): Cannot change Benchmark after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetBenchmarkAlreadyInitialized());
}

var market = GetMarket(null, symbol, securityType, defaultMarket: Market.USA);
Expand Down Expand Up @@ -1503,7 +1503,7 @@ public void SetBenchmark(Symbol symbol)
{
if (_locked)
{
throw new InvalidOperationException("Algorithm.SetBenchmark(): Cannot change Benchmark after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetBenchmarkAlreadyInitialized());
}

// Create our security benchmark
Expand All @@ -1522,7 +1522,7 @@ public void SetBenchmark(Func<DateTime, decimal> benchmark)
{
if (_locked)
{
throw new InvalidOperationException("Algorithm.SetBenchmark(): Cannot change Benchmark after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetBenchmarkAlreadyInitialized());
}

Benchmark = new FuncBenchmark(benchmark);
Expand Down Expand Up @@ -1599,8 +1599,7 @@ public void SetAccountCurrency(string accountCurrency, decimal? startingCash = n
{
if (_locked)
{
throw new InvalidOperationException("Algorithm.SetAccountCurrency(): " +
"Cannot change AccountCurrency after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetAccountCurrencyAlreadyInitialized());
}

if (startingCash == null)
Expand Down Expand Up @@ -1653,7 +1652,7 @@ public void SetCash(decimal startingCash)
}
else
{
throw new InvalidOperationException("Algorithm.SetCash(): Cannot change cash available after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetCashAlreadyInitialized());
}
}

Expand All @@ -1672,7 +1671,7 @@ public void SetCash(string symbol, decimal startingCash, decimal conversionRate
}
else
{
throw new InvalidOperationException("Algorithm.SetCash(): Cannot change cash available after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetCashAlreadyInitialized());
}
}

Expand Down Expand Up @@ -1778,7 +1777,7 @@ public void SetStartDate(DateTime start)
}
else
{
throw new InvalidOperationException("Algorithm.SetStartDate(): Cannot change start date after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetStartDateAlreadyInitialized());
}
}

Expand All @@ -1797,7 +1796,7 @@ public void SetEndDate(DateTime end)
//1. Check not locked already:
if (_locked)
{
throw new InvalidOperationException("Algorithm.SetEndDate(): Cannot change end date after algorithm initialized.");
throw new InvalidOperationException(Messages.QCAlgorithm.SetEndDateAlreadyInitialized());
}

//Validate:
Expand Down
6 changes: 4 additions & 2 deletions AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public AlgorithmPythonWrapper(string moduleName)
{
throw new Exception("Please ensure that one class inherits from QCAlgorithm.");
}

Messages.SetAlgorithmLanguage(Language.Python);
}
}
catch (Exception e)
Expand Down Expand Up @@ -901,7 +903,7 @@ public void OnMarginCall(List<SubmitOrderRequest> requests)
// If the method does not return or returns a non-iterable PyObject, throw an exception
if (result == null || !result.IsIterable())
{
throw new Exception("OnMarginCall must return a non-empty list of SubmitOrderRequest");
throw new Exception(Messages.AlgorithmPythonWrapper.OnMarginCallMustReturnNonEmptyList());
}

requests.Clear();
Expand All @@ -919,7 +921,7 @@ public void OnMarginCall(List<SubmitOrderRequest> requests)
// If the PyObject is an empty list or its items are not SubmitOrderRequest objects, throw an exception
if (requests.Count == 0)
{
throw new Exception("OnMarginCall must return a non-empty list of SubmitOrderRequest");
throw new Exception(Messages.AlgorithmPythonWrapper.OnMarginCallMustReturnNonEmptyList());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Common/Messages/Messages.Algorithm.Framework.Portfolio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public static class PortfolioTarget
public static string InvalidTargetPercent(IAlgorithm algorithm, decimal percent)
{
return Invariant($@"The portfolio target percent: {
percent}, does not comply with the current 'Algorithm.Settings' 'MaxAbsolutePortfolioTargetPercentage': {
algorithm.Settings.MaxAbsolutePortfolioTargetPercentage} or 'MinAbsolutePortfolioTargetPercentage': {
percent}, does not comply with the current 'QCAlgorithm.{FormatCode("Settings")}' '{FormatCode("MaxAbsolutePortfolioTargetPercentage")}': {
algorithm.Settings.MaxAbsolutePortfolioTargetPercentage} or '{FormatCode("MinAbsolutePortfolioTargetPercentage")}': {
algorithm.Settings.MinAbsolutePortfolioTargetPercentage}. Skipping");
}

Expand Down
110 changes: 110 additions & 0 deletions Common/Messages/Messages.Algorithm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System.Runtime.CompilerServices;

namespace QuantConnect
{
/// <summary>
/// Provides user-facing message construction methods and static messages for the <see cref="Algorithm"/> namespace
/// </summary>
public static partial class Messages
{
/// <summary>
/// Provides user-facing messages for the <see cref="Algorithm.QCAlgorithm"/> class and its consumers or related classes
/// </summary>
public static class QCAlgorithm
{
/// <summary>
/// Returns a string message saying the time zone cannot be changed after the algorithm is running
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SetTimeZoneAlreadyRunning()
{
return $"QCAlgorithm.{FormatCode("SetTimeZone")}(): Cannot change time zone after algorithm running.";
}

/// <summary>
/// Returns a string message saying the benchmark cannot be changed after the algorithm is initialized
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SetBenchmarkAlreadyInitialized()
{
return $"QCAlgorithm.{FormatCode("SetBenchmark")}(): Cannot change Benchmark after algorithm initialized.";
}

/// <summary>
/// Returns a string message saying the account currency cannot be changed after the algorithm is initialized
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SetAccountCurrencyAlreadyInitialized()
{
return $"QCAlgorithm.{FormatCode("SetAccountCurrency")}(): Cannot change AccountCurrency after algorithm initialized.";
}

/// <summary>
/// Returns a string message saying the cash cannot be changed after the algorithm is initialized
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SetCashAlreadyInitialized()
{
return $"QCAlgorithm.{FormatCode("SetCash")}(): Cannot change cash available after algorithm initialized.";
}

/// <summary>
/// Returns a string message saying the start date cannot be changed after the algorithm is initialized
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SetStartDateAlreadyInitialized()
{
return $"QCAlgorithm.{FormatCode("SetStartDate")}(): Cannot change start date after algorithm initialized.";
}

/// <summary>
/// Returns a string message saying the end date cannot be changed after the algorithm is initialized
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SetEndDateAlreadyInitialized()
{
return $"QCAlgorithm.{FormatCode("SetEndDate")}(): Cannot change end date after algorithm initialized.";
}

/// <summary>
/// Returns a string message saying SetWarmup cannot be used after the algorithm is initialized
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string SetWarmupAlreadyInitialized()
{
return $"QCAlgorithm.{FormatCode("SetWarmup")}(): This method cannot be used after algorithm initialized";
}
}

/// <summary>
/// Provides user-facing messages for the <see cref="AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper"/> class
/// and its consumers or related classes
/// </summary>
public static class AlgorithmPythonWrapper
{
/// <summary>
/// Returns a string message saying OnMarginCall must return a non-empty list of SubmitOrderRequest
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string OnMarginCallMustReturnNonEmptyList()
{
return $"{FormatCode("OnMarginCall")} must return a non-empty list of SubmitOrderRequest";
}
}
}
}
2 changes: 1 addition & 1 deletion Common/Messages/Messages.Brokerages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public static class FxcmBrokerageModel
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string InvalidOrderQuantityForLotSize(Securities.Security security)
{
return Invariant($"The order quantity must be a multiple of LotSize: [{security.SymbolProperties.LotSize}].");
return Invariant($"The order quantity must be a multiple of {FormatCode("LotSize")}: [{security.SymbolProperties.LotSize}].");
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Common/Messages/Messages.Orders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public static string ZeroQuantity(Orders.OrderRequest request)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string MissingSecurity(Orders.SubmitOrderRequest request)
{
return Invariant($"You haven't requested {request.Symbol} data. Add this with AddSecurity() in the Initialize() Method.");
return Invariant($"You haven't requested {request.Symbol} data. Add this with {FormatCode("AddSecurity")}() in the {FormatCode("Initialize")}() method.");
}

/// <summary>
Expand All @@ -365,8 +365,8 @@ public static string MissingSecurity(Orders.SubmitOrderRequest request)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string WarmingUp(Orders.OrderRequest request)
{
return Invariant($@"This operation is not allowed in Initialize or during warm up: OrderRequest.{
request.OrderRequestType}. Please move this code to the OnWarmupFinished() method.");
return Invariant($@"This operation is not allowed in {FormatCode("Initialize")} or during warm up: OrderRequest.{
FormatCode(request.OrderRequestType)}. Please move this code to the {FormatCode("OnWarmupFinished")}() method.");
}
}

Expand Down
Loading
Loading