Skip to content

Commit 68acc8f

Browse files
committed
Address review comments
1 parent 0e90880 commit 68acc8f

6 files changed

Lines changed: 22 additions & 18 deletions

File tree

AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ public AlgorithmPythonWrapper(string moduleName)
177177
{
178178
throw new Exception("Please ensure that one class inherits from QCAlgorithm.");
179179
}
180-
181-
Messages.SetAlgorithmLanguage(Language.Python);
182180
}
183181
}
184182
catch (Exception e)

Common/Messages/Messages.Algorithm.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static class QCAlgorithm
3333
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3434
public static string SetTimeZoneAlreadyRunning()
3535
{
36-
return $"QCAlgorithm.{FormatCode("SetTimeZone")}(): Cannot change time zone after algorithm running.";
36+
return $"{AlgorithmPrefix()}.{FormatCode("SetTimeZone")}(): Cannot change time zone after algorithm running.";
3737
}
3838

3939
/// <summary>
@@ -42,7 +42,7 @@ public static string SetTimeZoneAlreadyRunning()
4242
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4343
public static string SetBenchmarkAlreadyInitialized()
4444
{
45-
return $"QCAlgorithm.{FormatCode("SetBenchmark")}(): Cannot change Benchmark after algorithm initialized.";
45+
return $"{AlgorithmPrefix()}.{FormatCode("SetBenchmark")}(): Cannot change Benchmark after algorithm initialized.";
4646
}
4747

4848
/// <summary>
@@ -51,7 +51,7 @@ public static string SetBenchmarkAlreadyInitialized()
5151
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5252
public static string SetAccountCurrencyAlreadyInitialized()
5353
{
54-
return $"QCAlgorithm.{FormatCode("SetAccountCurrency")}(): Cannot change AccountCurrency after algorithm initialized.";
54+
return $"{AlgorithmPrefix()}.{FormatCode("SetAccountCurrency")}(): Cannot change AccountCurrency after algorithm initialized.";
5555
}
5656

5757
/// <summary>
@@ -60,7 +60,7 @@ public static string SetAccountCurrencyAlreadyInitialized()
6060
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6161
public static string SetCashAlreadyInitialized()
6262
{
63-
return $"QCAlgorithm.{FormatCode("SetCash")}(): Cannot change cash available after algorithm initialized.";
63+
return $"{AlgorithmPrefix()}.{FormatCode("SetCash")}(): Cannot change cash available after algorithm initialized.";
6464
}
6565

6666
/// <summary>
@@ -69,7 +69,7 @@ public static string SetCashAlreadyInitialized()
6969
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7070
public static string SetStartDateAlreadyInitialized()
7171
{
72-
return $"QCAlgorithm.{FormatCode("SetStartDate")}(): Cannot change start date after algorithm initialized.";
72+
return $"{AlgorithmPrefix()}.{FormatCode("SetStartDate")}(): Cannot change start date after algorithm initialized.";
7373
}
7474

7575
/// <summary>
@@ -78,7 +78,7 @@ public static string SetStartDateAlreadyInitialized()
7878
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7979
public static string SetEndDateAlreadyInitialized()
8080
{
81-
return $"QCAlgorithm.{FormatCode("SetEndDate")}(): Cannot change end date after algorithm initialized.";
81+
return $"{AlgorithmPrefix()}.{FormatCode("SetEndDate")}(): Cannot change end date after algorithm initialized.";
8282
}
8383

8484
/// <summary>
@@ -87,7 +87,7 @@ public static string SetEndDateAlreadyInitialized()
8787
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8888
public static string SetWarmupAlreadyInitialized()
8989
{
90-
return $"QCAlgorithm.{FormatCode("SetWarmup")}(): This method cannot be used after algorithm initialized";
90+
return $"{AlgorithmPrefix()}.{FormatCode("SetWarmup")}(): This method cannot be used after algorithm initialized";
9191
}
9292
}
9393

Common/Messages/Messages.Brokerages.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static string UnsupportedMarketOnOpenOrderTime(
163163
in TimeOnly windowStart,
164164
in TimeOnly windowEnd)
165165
{
166-
return Invariant($"MarketOnOpen submission time is invalid. Valid local times are {windowStart: hh\\:mm}{windowEnd: hh\\:mm}. Consider setting DailyPreciseEndTime = false or using {nameof(Schedule)}.{nameof(Schedule.On)}.");
166+
return Invariant($"MarketOnOpen submission time is invalid. Valid local times are {windowStart: hh\\:mm}{windowEnd: hh\\:mm}. Consider setting {FormatCode(nameof(AlgorithmSettings.DailyPreciseEndTime))} = false or using {FormatCodeRoot(nameof(Schedule))}.{FormatCode(nameof(Schedule.On))}.");
167167
}
168168
}
169169

Common/Messages/Messages.QuantConnect.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18-
using System.Linq;
1918
using System.Runtime.CompilerServices;
2019

2120
using Python.Runtime;
@@ -65,7 +64,12 @@ private static string FormatCodeRoot(string code)
6564

6665
private static string FormatCode<T>(T value) where T : Enum
6766
{
68-
return string.Join(", ", value.ToString().Split(", ").Select(FormatCode));
67+
return FormatCode(value.ToString());
68+
}
69+
70+
private static string AlgorithmPrefix()
71+
{
72+
return _algorithmLanguage == Language.Python ? "self" : "QCAlgorithm";
6973
}
7074

7175
/// <summary>

Engine/Engine.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ public void Run(AlgorithmNodePacket job, AlgorithmManager manager, string assemb
9191

9292
try
9393
{
94+
Messages.SetAlgorithmLanguage(job.Language);
9495
Log.Trace($"Engine.Run(): Resource limits '{job.Controls.CpuAllocation}' CPUs. {job.Controls.RamAllocation} MB RAM.");
95-
TextSubscriptionDataSourceReader.SetCacheSize((int) (job.RamAllocation * 0.4));
96+
TextSubscriptionDataSourceReader.SetCacheSize((int)(job.RamAllocation * 0.4));
9697

9798
//Reset thread holders.
9899
var initializeComplete = false;
@@ -101,7 +102,7 @@ public void Run(AlgorithmNodePacket job, AlgorithmManager manager, string assemb
101102
SystemHandlers.Notify.SetAuthentication(job);
102103

103104
//-> Set the result handler type for this algorithm job, and launch the associated result thread.
104-
AlgorithmHandlers.Results.Initialize(new (job, SystemHandlers.Notify, SystemHandlers.Api, AlgorithmHandlers.Transactions, AlgorithmHandlers.MapFileProvider));
105+
AlgorithmHandlers.Results.Initialize(new(job, SystemHandlers.Notify, SystemHandlers.Api, AlgorithmHandlers.Transactions, AlgorithmHandlers.MapFileProvider));
105106

106107
IBrokerage brokerage = null;
107108
DataManager dataManager = null;
@@ -186,7 +187,7 @@ public void Run(AlgorithmNodePacket job, AlgorithmManager manager, string assemb
186187
AlgorithmHandlers.FactorFileProvider,
187188
AlgorithmHandlers.DataProvider,
188189
dataManager,
189-
(IDataFeedTimeProvider) synchronizer,
190+
(IDataFeedTimeProvider)synchronizer,
190191
AlgorithmHandlers.DataPermissionsManager.DataChannelProvider);
191192

192193
// set the history provider before setting up the algorithm
@@ -359,7 +360,7 @@ public void Run(AlgorithmNodePacket job, AlgorithmManager manager, string assemb
359360
}
360361

361362
Log.Trace("Engine.Run(): Exiting Algorithm Manager");
362-
}, job.Controls.RamAllocation, workerThread:workerThread, sleepIntervalMillis: algorithm.LiveMode ? 10000 : 1000);
363+
}, job.Controls.RamAllocation, workerThread: workerThread, sleepIntervalMillis: algorithm.LiveMode ? 10000 : 1000);
363364

364365
if (!complete)
365366
{
@@ -396,7 +397,7 @@ public void Run(AlgorithmNodePacket job, AlgorithmManager manager, string assemb
396397
//Diagnostics Completed, Send Result Packet:
397398
var totalSeconds = (DateTime.UtcNow - startTime).TotalSeconds;
398399
var dataPoints = algorithmManager.DataPoints + algorithm.HistoryProvider.DataPointCount;
399-
var kps = dataPoints / (double) 1000 / totalSeconds;
400+
var kps = dataPoints / (double)1000 / totalSeconds;
400401
AlgorithmHandlers.Results.DebugMessage($"Algorithm Id:({job.AlgorithmId}) completed in {totalSeconds:F2} seconds at {kps:F0}k data points per second. Processing total of {dataPoints:N0} data points.");
401402
}
402403
}
@@ -426,7 +427,7 @@ public void Run(AlgorithmNodePacket job, AlgorithmManager manager, string assemb
426427
|| (AlgorithmHandlers.Transactions != null && AlgorithmHandlers.Transactions.IsActive)
427428
|| (AlgorithmHandlers.DataFeed != null && AlgorithmHandlers.DataFeed.IsActive)
428429
|| (AlgorithmHandlers.RealTime != null && AlgorithmHandlers.RealTime.IsActive))
429-
&& millisecondTotalWait < 30*1000)
430+
&& millisecondTotalWait < 30 * 1000)
430431
{
431432
Thread.Sleep(millisecondInterval);
432433
if (millisecondTotalWait % (millisecondInterval * 10) == 0)

Research/QuantBook.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public QuantBook() : base()
9292
{
9393
try
9494
{
95+
Messages.SetAlgorithmLanguage(Language.Python);
9596
using (Py.GIL())
9697
{
9798
_pandas = Py.Import("pandas");

0 commit comments

Comments
 (0)