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: 2 additions & 0 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
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 'Algorithm.Settings' '{FormatCode("MaxAbsolutePortfolioTargetPercentage")}': {
algorithm.Settings.MaxAbsolutePortfolioTargetPercentage} or '{FormatCode("MinAbsolutePortfolioTargetPercentage")}': {
algorithm.Settings.MinAbsolutePortfolioTargetPercentage}. Skipping");
}

Expand Down
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.ToString())}. Please move this code to the {FormatCode("OnWarmupFinished")}() method.");
}
}

Expand Down
51 changes: 33 additions & 18 deletions Common/Messages/Messages.QuantConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,29 @@ namespace QuantConnect
/// </summary>
public static partial class Messages
{
private static Language _algorithmLanguage = Language.CSharp;

/// <summary>
/// Sets the algorithm language used to format code identifiers in error messages.
/// </summary>
public static void SetAlgorithmLanguage(Language language)
{
_algorithmLanguage = language;
}

/// <summary>
/// Returns the code identifier formatted for the current algorithm language.
/// For Python, converts PascalCase/camelCase to snake_case.
/// </summary>
private static string FormatCode(string code)
{
return _algorithmLanguage switch
{
Language.Python => code.ToSnakeCase(),
_ => code
};
}

/// <summary>
/// Provides user-facing messages for the <see cref="AlphaRuntimeStatistics"/> class and its consumers or related classes
/// </summary>
Expand Down Expand Up @@ -113,8 +136,7 @@ public static class Candlestick
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ToString(QuantConnect.Candlestick instance)
{
return Invariant($@"{instance.Time:o} - (O:{instance.Open} H: {instance.High} L: {
instance.Low} C: {instance.Close})");
return Invariant($@"{instance.Time:o} - (O:{instance.Open} H: {instance.High} L: {instance.Low} C: {instance.Close})");
}
}

Expand Down Expand Up @@ -183,8 +205,8 @@ public static string RemoveInvalidOperation<TKey, TValue>(ExtendedDictionary<TKe
public static string TickerNotFoundInSymbolCache(string ticker)
{
return $"The ticker {ticker} was not found in the SymbolCache. Use the Symbol object as key instead. " +
"Accessing the securities collection/slice object by string ticker is only available for securities added with " +
"the AddSecurity-family methods. For more details, please check out the documentation.";
$"Accessing the securities collection/slice object by string ticker is only available for securities added with " +
$"the {FormatCode("AddSecurity")}-family methods. For more details, please check out the documentation.";
}

/// <summary>
Expand Down Expand Up @@ -278,7 +300,7 @@ public static string DownloadDataFailed(string url)
public static string ZeroPriceForSecurity(QuantConnect.Symbol symbol)
{
return $"{symbol}: The security does not have an accurate price as it has not yet received a bar of data. " +
"Before placing a trade (or using SetHoldings) warm up your algorithm with SetWarmup, or use slice.Contains(symbol) " +
$"Before placing a trade (or using {FormatCode("SetHoldings")}) warm up your algorithm with {FormatCode("SetWarmup")}, or use slice.Contains(symbol) " +
"to confirm the Slice object has price before using the data. Data does not necessarily all arrive at the same " +
"time so your algorithm should confirm the data is ready before using it. In live trading this can mean you do " +
"not have an active subscription to the asset class you're trying to trade. If using custom data make sure you've " +
Expand Down Expand Up @@ -338,8 +360,7 @@ public static string TypeIsNotBaseData(Type type)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string CannotCastNonFiniteFloatingPointValueToDecimal(double input)
{
return Invariant($@"It is not possible to cast a non-finite floating-point value ({
input}) as decimal. Please review math operations and verify the result is valid.");
return Invariant($@"It is not possible to cast a non-finite floating-point value ({input}) as decimal. Please review math operations and verify the result is valid.");
}

/// <summary>
Expand Down Expand Up @@ -471,8 +492,7 @@ public static string ToString(QuantConnect.Holding instance)
{
currencySymbol = "$";
}
var value = Invariant($@"{instance.Symbol?.Value}: {instance.Quantity} @ {
currencySymbol}{instance.AveragePrice} - Market: {currencySymbol}{instance.MarketPrice}");
var value = Invariant($@"{instance.Symbol?.Value}: {instance.Quantity} @ {currencySymbol}{instance.AveragePrice} - Market: {currencySymbol}{instance.MarketPrice}");

if (instance.ConversionRate.HasValue && instance.ConversionRate != 1m)
{
Expand Down Expand Up @@ -526,8 +546,7 @@ public static string MemoryUsageOver80Percent(double lastSample)
public static string MemoryUsageInfo(string memoryUsed, string lastSample, string memoryUsedByApp, TimeSpan currentTimeStepElapsed,
int cpuUsage)
{
return Invariant($@"Used: {memoryUsed}, Sample: {lastSample}, App: {memoryUsedByApp}, CurrentTimeStepElapsed: {
currentTimeStepElapsed:mm':'ss'.'fff}. CPU: {cpuUsage}%");
return Invariant($@"Used: {memoryUsed}, Sample: {lastSample}, App: {memoryUsedByApp}, CurrentTimeStepElapsed: {currentTimeStepElapsed:mm':'ss'.'fff}. CPU: {cpuUsage}%");
}

/// <summary>
Expand All @@ -537,8 +556,7 @@ public static string MemoryUsageInfo(string memoryUsed, string lastSample, strin
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string MemoryUsageMonitorTaskTimedOut(TimeSpan timeout)
{
return $@"Execution Security Error: Operation timed out - {
timeout.TotalMinutes.ToStringInvariant()} minutes max. Check for recursive loops.";
return $@"Execution Security Error: Operation timed out - {timeout.TotalMinutes.ToStringInvariant()} minutes max. Check for recursive loops.";
}
}

Expand Down Expand Up @@ -724,8 +742,7 @@ public static string ErrorParsingSecurityIdentifier(string value, Exception exce
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string MarketNotFound(string market)
{
return $@"The specified market wasn't found in the markets lookup. Requested: {
market}. You can add markets by calling QuantConnect.Market.Add(string,int)";
return $@"The specified market wasn't found in the markets lookup. Requested: {market}. You can add markets by calling QuantConnect.Market.Add(string,int)";
}
}

Expand Down Expand Up @@ -940,9 +957,7 @@ public static class TradingCalendar
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string InvalidTotalDays(int totalDays)
{
return Invariant($@"Total days is negative ({
totalDays
}), indicating reverse start and end times. Check your usage of TradingCalendar to ensure proper arrangement of variables");
return Invariant($@"Total days is negative ({totalDays}), indicating reverse start and end times. Check your usage of TradingCalendar to ensure proper arrangement of variables");
}
}
}
Expand Down
35 changes: 25 additions & 10 deletions Common/Messages/Messages.Securities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static string TargetOrderMarginNotAboveMinimum(decimal absDifferenceOfMar
public static string TargetOrderMarginNotAboveMinimum()
{
return "Warning: Portfolio rebalance result ignored as it resulted in a single share trade recommendation which can generate high fees." +
" To disable minimum order size checks please set Settings.MinimumOrderMarginPortfolioPercentage = 0.";
$" To disable minimum order size checks please set {FormatCode("Settings")}.{FormatCode("MinimumOrderMarginPortfolioPercentage")} = 0.";
}

/// <summary>
Expand Down Expand Up @@ -886,15 +886,19 @@ public static class SecurityPortfolioManager
/// Returns a string message saying the AccountCurrency cannot be changed after adding a Security and that the method
/// SetAccountCurrency() should be moved before AddSecurity()
/// </summary>
public static string CannotChangeAccountCurrencyAfterAddingSecurity =
"Cannot change AccountCurrency after adding a Security. Please move SetAccountCurrency() before AddSecurity().";
public static string CannotChangeAccountCurrencyAfterAddingSecurity()
{
return $"Cannot change AccountCurrency after adding a Security. Please move {FormatCode("SetAccountCurrency")}() before {FormatCode("AddSecurity")}().";
}

/// <summary>
/// Returns a string message saying the AccountCurrency cannot be changed after setting cash and that the method
/// SetAccountCurrency() should be moved before SetCash()
/// </summary>
public static string CannotChangeAccountCurrencyAfterSettingCash =
"Cannot change AccountCurrency after setting cash. Please move SetAccountCurrency() before SetCash().";
public static string CannotChangeAccountCurrencyAfterSettingCash()
{
return $"Cannot change AccountCurrency after setting cash. Please move {FormatCode("SetAccountCurrency")}() before {FormatCode("SetCash")}().";
}

/// <summary>
/// Returns a string message saying the AccountCurrency has already been set and that the new value for this property
Expand Down Expand Up @@ -958,8 +962,10 @@ public static class SecurityTransactionManager
/// <summary>
/// Returns a string message saying CancelOpenOrders operation is not allowed in Initialize or during warm up
/// </summary>
public static string CancelOpenOrdersNotAllowedOnInitializeOrWarmUp =
"This operation is not allowed in Initialize or during warm up: CancelOpenOrders. Please move this code to the OnWarmupFinished() method.";
public static string CancelOpenOrdersNotAllowedOnInitializeOrWarmUp()
{
return $"This operation is not allowed in {FormatCode("Initialize")} or during warm up: {FormatCode("CancelOpenOrders")}. Please move this code to the {FormatCode("OnWarmupFinished")}() method.";
}

/// <summary>
/// Returns a string message saying the order was canceled by the CancelOpenOrders() at the given time
Expand Down Expand Up @@ -997,17 +1003,26 @@ public static class SymbolProperties
/// <summary>
/// String message saying the SymbolProperties LotSize can not be less than or equal to 0
/// </summary>
public static string InvalidLotSize = "SymbolProperties LotSize can not be less than or equal to 0";
public static string InvalidLotSize()
{
return $"{FormatCode("SymbolProperties")} {FormatCode("LotSize")} can not be less than or equal to 0";
}

/// <summary>
/// String message saying the SymbolProperties PriceMagnifier can not be less than or equal to 0
/// </summary>
public static string InvalidPriceMagnifier = "SymbolProprties PriceMagnifier can not be less than or equal to 0";
public static string InvalidPriceMagnifier()
{
return $"{FormatCode("SymbolProperties")} {FormatCode("PriceMagnifier")} can not be less than or equal to 0";
}

/// <summary>
/// String message saying the SymbolProperties StrikeMultiplier can not be less than or equal to 0
/// </summary>
public static string InvalidStrikeMultiplier = "SymbolProperties StrikeMultiplier can not be less than or equal to 0";
public static string InvalidStrikeMultiplier()
{
return $"{FormatCode("SymbolProperties")} {FormatCode("StrikeMultiplier")} can not be less than or equal to 0";
}

/// <summary>
/// Parses a given SymbolProperties object into a string message
Expand Down
4 changes: 2 additions & 2 deletions Common/Securities/SecurityPortfolioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -642,13 +642,13 @@ public void SetAccountCurrency(string accountCurrency, decimal? startingCash = n
if (Securities.Count > 0)
{
throw new InvalidOperationException("SecurityPortfolioManager.SetAccountCurrency(): " +
Messages.SecurityPortfolioManager.CannotChangeAccountCurrencyAfterAddingSecurity);
Messages.SecurityPortfolioManager.CannotChangeAccountCurrencyAfterAddingSecurity());
}

if (_setCashWasCalled)
{
throw new InvalidOperationException("SecurityPortfolioManager.SetAccountCurrency(): " +
Messages.SecurityPortfolioManager.CannotChangeAccountCurrencyAfterSettingCash);
Messages.SecurityPortfolioManager.CannotChangeAccountCurrencyAfterSettingCash());
}

Log.Trace("SecurityPortfolioManager.SetAccountCurrency(): " +
Expand Down
4 changes: 2 additions & 2 deletions Common/Securities/SecurityTransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public List<OrderTicket> CancelOpenOrders()
{
if (_algorithm != null && _algorithm.IsWarmingUp)
{
throw new InvalidOperationException(Messages.SecurityTransactionManager.CancelOpenOrdersNotAllowedOnInitializeOrWarmUp);
throw new InvalidOperationException(Messages.SecurityTransactionManager.CancelOpenOrdersNotAllowedOnInitializeOrWarmUp());
}

var cancelledOrders = new List<OrderTicket>();
Expand All @@ -273,7 +273,7 @@ public List<OrderTicket> CancelOpenOrders(Symbol symbol, string tag = null)
{
if (_algorithm != null && _algorithm.IsWarmingUp)
{
throw new InvalidOperationException(Messages.SecurityTransactionManager.CancelOpenOrdersNotAllowedOnInitializeOrWarmUp);
throw new InvalidOperationException(Messages.SecurityTransactionManager.CancelOpenOrdersNotAllowedOnInitializeOrWarmUp());
}

var cancelledOrders = new List<OrderTicket>();
Expand Down
6 changes: 3 additions & 3 deletions Common/Securities/SymbolProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public SymbolPropertiesHolder(string description, string quoteCurrency, decimal

if (LotSize <= 0)
{
throw new ArgumentException(Messages.SymbolProperties.InvalidLotSize);
throw new ArgumentException(Messages.SymbolProperties.InvalidLotSize());
}

MarketTicker = marketTicker;
Expand All @@ -180,13 +180,13 @@ public SymbolPropertiesHolder(string description, string quoteCurrency, decimal
PriceMagnifier = priceMagnifier;
if (PriceMagnifier <= 0)
{
throw new ArgumentException(Messages.SymbolProperties.InvalidPriceMagnifier);
throw new ArgumentException(Messages.SymbolProperties.InvalidPriceMagnifier());
}

StrikeMultiplier = strikeMultiplier;
if (strikeMultiplier <= 0)
{
throw new ArgumentException(Messages.SymbolProperties.InvalidStrikeMultiplier);
throw new ArgumentException(Messages.SymbolProperties.InvalidStrikeMultiplier());
}
}
}
Expand Down
Loading
Loading