Compare commits

...

1 Commits

Author SHA1 Message Date
Martin Molinero
1b088de758 Private cloud tweaks 2024-11-11 15:52:40 -03:00
11 changed files with 60 additions and 24 deletions

View File

@@ -50,7 +50,7 @@ namespace QuantConnect.Api
{
_token = token;
_userId = userId.ToStringInvariant();
Client = new RestClient("https://www.quantconnect.com/api/v2/");
Client = new RestClient(Globals.Api);
}
/// <summary>
@@ -112,7 +112,7 @@ namespace QuantConnect.Api
if (!restsharpResponse.IsSuccessful)
{
Log.Error($"ApiConnect.TryRequest(): Content: {restsharpResponse.Content}");
Log.Error($"ApiConnect.TryRequest({request.Resource}): Content: {restsharpResponse.Content}");
}
responseContent = restsharpResponse.Content;
@@ -120,7 +120,7 @@ namespace QuantConnect.Api
if (result == null || !result.Success)
{
Log.Debug($"ApiConnection.TryRequest(): Raw response: '{responseContent}'");
Log.Debug($"ApiConnection.TryRequest({request.Resource}): Raw response: '{responseContent}'");
return new Tuple<bool, T>(false, result);
}
}

View File

@@ -18,6 +18,7 @@ using Newtonsoft.Json;
using QuantConnect.Statistics;
using System.Collections.Generic;
using QuantConnect.Optimizer.Parameters;
using QuantConnect.Util;
namespace QuantConnect.Api
{
@@ -52,6 +53,16 @@ namespace QuantConnect.Api
/// </summary>
public class BasicBacktest : RestResponse
{
/// <summary>
/// Backtest error message
/// </summary>
public string Error { get; set; }
/// <summary>
/// Backtest error stacktrace
/// </summary>
public string Stacktrace { get; set; }
/// <summary>
/// Assigned backtest Id
/// </summary>
@@ -70,6 +81,7 @@ namespace QuantConnect.Api
/// <summary>
/// Backtest creation date and time
/// </summary>
[JsonConverter(typeof(DateTimeJsonConverter), DateFormat.UI)]
public DateTime Created { get; set; }
/// <summary>
@@ -103,7 +115,6 @@ namespace QuantConnect.Api
/// </summary>
public class Backtest : BasicBacktest
{
/// <summary>
/// Note on the backtest attached by the user
/// </summary>
@@ -114,16 +125,6 @@ namespace QuantConnect.Api
/// </summary>
public bool Completed { get; set; }
/// <summary>
/// Backtest error message
/// </summary>
public string Error { get; set; }
/// <summary>
/// Backtest error stacktrace
/// </summary>
public string StackTrace { get; set; }
/// <summary>
/// Organization ID
/// </summary>
@@ -185,6 +186,11 @@ namespace QuantConnect.Api
/// </summary>
public string NodeName { get; set; }
/// <summary>
/// The associated project id
/// </summary>
public int ProjectId { get; set; }
/// <summary>
/// End date of out of sample data
/// </summary>

View File

@@ -33,7 +33,7 @@ namespace QuantConnect
/// <summary>
/// The base api url address to use
/// </summary>
public static string Api { get; } = "https://www.quantconnect.com/api/v2/";
public static string Api { get; set; }
/// <summary>
/// The user Id
@@ -96,6 +96,7 @@ namespace QuantConnect
ProjectId = Config.GetInt("project-id");
UserToken = Config.Get("api-access-token");
OrganizationID = Config.Get("job-organization-id");
Api = Config.Get("api-url", "https://www.quantconnect.com/api/v2/");
ResultsDestinationFolder = Config.Get("results-destination-folder", Directory.GetCurrentDirectory());
}

View File

@@ -100,6 +100,12 @@ namespace QuantConnect
memoryCap *= 1024 * 1024;
var spikeLimit = memoryCap*2;
if (memoryCap <= 0)
{
memoryCap = int.MaxValue;
spikeLimit = int.MaxValue;
}
while (!task.IsCompleted && !CancellationTokenSource.IsCancellationRequested && utcNow < end)
{
// if over 80% allocation force GC then sample

View File

@@ -46,10 +46,10 @@ namespace QuantConnect.Optimizer.Parameters
/// </summary>
/// <param name="id">Unique identifier</param>
/// <param name="value">Combination of optimization parameters</param>
public ParameterSet(int id, Dictionary<string, string> value)
public ParameterSet(int id, IReadOnlyDictionary<string, string> value)
{
Id = id;
Value = value?.ToReadOnlyDictionary();
Value = value;
}
/// <summary>

View File

@@ -124,7 +124,7 @@ namespace QuantConnect.Packets
/// The maximum amount of RAM (in MB) this algorithm is allowed to utilize
/// </summary>
public int RamAllocation {
get { return Controls.RamAllocation; }
get { return Controls?.RamAllocation ?? 0; }
}
/// <summary>

View File

@@ -194,5 +194,8 @@ namespace QuantConnect.Packets
/// Research job packet
ResearchNode,
/// Organization update
OrganizationUpdate,
}
}

View File

@@ -90,6 +90,11 @@ namespace QuantConnect.Lean.Engine.Results
/// </summary>
public const string PortfolioMarginKey = "Portfolio Margin";
/// <summary>
/// String message saying: Portfolio Margin
/// </summary>
public const string AssetsSalesVolumeKey = "Assets Sales Volume";
/// <summary>
/// The main loop update interval
/// </summary>
@@ -720,7 +725,7 @@ namespace QuantConnect.Lean.Engine.Results
foreach (var holding in Algorithm.Portfolio.Values.Where(y => y.TotalSaleVolume != 0)
.OrderByDescending(x => x.TotalSaleVolume).Take(30))
{
Sample("Assets Sales Volume", $"{holding.Symbol.Value}", 0, SeriesType.Treemap, new ChartPoint(time, holding.TotalSaleVolume),
Sample(AssetsSalesVolumeKey, $"{holding.Symbol.Value}", 0, SeriesType.Treemap, new ChartPoint(time, holding.TotalSaleVolume),
AlgorithmCurrencySymbol);
}
}

View File

@@ -132,9 +132,7 @@ namespace QuantConnect.Lean.Engine.Setup
throw new ArgumentException("Expected BacktestNodePacket but received " + parameters.AlgorithmNodePacket.GetType().Name);
}
Log.Trace($"BacktestingSetupHandler.Setup(): Setting up job: UID: {job.UserId.ToStringInvariant()}, " +
$"PID: {job.ProjectId.ToStringInvariant()}, Version: {job.Version}, Source: {job.RequestSource}"
);
BaseSetupHandler.Setup(parameters);
if (algorithm == null)
{
@@ -164,7 +162,6 @@ namespace QuantConnect.Lean.Engine.Setup
//Algorithm is backtesting, not live:
algorithm.SetAlgorithmMode(job.AlgorithmMode);
algorithm.SetDeploymentTarget(job.DeploymentTarget);
//Set the source impl for the event scheduling
algorithm.Schedule.SetEventSchedule(parameters.RealTimeHandler);

View File

@@ -45,6 +45,24 @@ namespace QuantConnect.Lean.Engine.Setup
/// </summary>
public static TimeSpan AlgorithmCreationTimeout { get; } = TimeSpan.FromSeconds(Config.GetDouble("algorithm-creation-timeout", 90));
/// <summary>
/// Primary entry point to setup a new algorithm
/// </summary>
/// <param name="parameters">The parameters object to use</param>
/// <returns>True on successfully setting up the algorithm state, or false on error.</returns>
public static bool Setup(SetupHandlerParameters parameters)
{
var algorithm = parameters.Algorithm;
var job = parameters.AlgorithmNodePacket;
algorithm?.SetDeploymentTarget(job.DeploymentTarget);
Log.Trace($"BaseSetupHandler.Setup({job.DeploymentTarget}): UID: {job.UserId.ToStringInvariant()}, " +
$"PID: {job.ProjectId.ToStringInvariant()}, Version: {job.Version}, Source: {job.RequestSource}"
);
return true;
}
/// <summary>
/// Will first check and add all the required conversion rate securities
/// and later will seed an initial value to them.

View File

@@ -163,6 +163,7 @@ namespace QuantConnect.Lean.Engine.Setup
return false;
}
BaseSetupHandler.Setup(parameters);
// attach to the message event to relay brokerage specific initialization messages
EventHandler<BrokerageMessageEvent> brokerageOnMessage = (sender, args) =>
@@ -243,7 +244,6 @@ namespace QuantConnect.Lean.Engine.Setup
//Algorithm is live, not backtesting:
algorithm.SetAlgorithmMode(liveJob.AlgorithmMode);
algorithm.SetDeploymentTarget(liveJob.DeploymentTarget);
//Initialize the algorithm's starting date
algorithm.SetDateTime(DateTime.UtcNow);