chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Account information for an organization
|
||||
/// </summary>
|
||||
public class Account : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The organization Id
|
||||
/// </summary>
|
||||
public string OrganizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current account balance
|
||||
/// </summary>
|
||||
public decimal CreditBalance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The current organizations credit card
|
||||
/// </summary>
|
||||
public Card Card { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Credit card
|
||||
/// </summary>
|
||||
public class Card
|
||||
{
|
||||
/// <summary>
|
||||
/// Credit card brand
|
||||
/// </summary>
|
||||
public string Brand { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The credit card expiration
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(Time.MonthYearJsonConverter))]
|
||||
public DateTime Expiration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The last 4 digits of the card
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "last4")]
|
||||
public decimal LastFourDigits { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Web;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods for api authentication and interaction
|
||||
/// </summary>
|
||||
public static class Authentication
|
||||
{
|
||||
/// <summary>
|
||||
/// Generate a secure hash for the authorization headers.
|
||||
/// </summary>
|
||||
/// <returns>Time based hash of user token and timestamp.</returns>
|
||||
public static string Hash(int timestamp)
|
||||
{
|
||||
return Hash(timestamp, Globals.UserToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a secure hash for the authorization headers.
|
||||
/// </summary>
|
||||
/// <returns>Time based hash of user token and timestamp.</returns>
|
||||
public static string Hash(int timestamp, string token)
|
||||
{
|
||||
// Create a new hash using current UTC timestamp.
|
||||
// Hash must be generated fresh each time.
|
||||
var data = $"{token}:{timestamp.ToStringInvariant()}";
|
||||
return data.ToSHA256();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an authenticated link for the target endpoint using the optional given payload
|
||||
/// </summary>
|
||||
/// <param name="endpoint">The endpoint</param>
|
||||
/// <param name="payload">The payload</param>
|
||||
/// <returns>The authenticated link to trigger the request</returns>
|
||||
public static string Link(string endpoint, IEnumerable<KeyValuePair<string, object>> payload = null)
|
||||
{
|
||||
var queryString = HttpUtility.ParseQueryString(string.Empty);
|
||||
|
||||
var timestamp = (int)Time.TimeStamp();
|
||||
queryString.Add("authorization", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Globals.UserId}:{Hash(timestamp)}")));
|
||||
queryString.Add("timestamp", timestamp.ToStringInvariant());
|
||||
|
||||
PopulateQueryString(queryString, payload);
|
||||
|
||||
return $"{Globals.Api}{endpoint.RemoveFromStart("/").RemoveFromEnd("/")}?{queryString}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method to populate a query string with the given payload
|
||||
/// </summary>
|
||||
/// <remarks>Useful for testing purposes</remarks>
|
||||
public static void PopulateQueryString(NameValueCollection queryString, IEnumerable<KeyValuePair<string, object>> payload = null)
|
||||
{
|
||||
if (payload != null)
|
||||
{
|
||||
foreach (var kv in payload)
|
||||
{
|
||||
AddToQuery(queryString, kv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will add the given key value pairs to the query encoded as xform data
|
||||
/// </summary>
|
||||
private static void AddToQuery(NameValueCollection queryString, KeyValuePair<string, object> keyValuePairs)
|
||||
{
|
||||
var objectType = keyValuePairs.Value.GetType();
|
||||
if (objectType.IsValueType || objectType == typeof(string))
|
||||
{
|
||||
// straight
|
||||
queryString.Add(keyValuePairs.Key, keyValuePairs.Value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// let's take advantage of json to load the properties we should include
|
||||
var serialized = JsonConvert.SerializeObject(keyValuePairs.Value);
|
||||
foreach (var jObject in JObject.Parse(serialized))
|
||||
{
|
||||
var subKey = $"{keyValuePairs.Key}[{jObject.Key}]";
|
||||
if (jObject.Value is JObject)
|
||||
{
|
||||
// inception
|
||||
AddToQuery(queryString, new KeyValuePair<string, object>(subKey, jObject.Value.ToObject<object>()));
|
||||
}
|
||||
else if(jObject.Value is JArray jArray)
|
||||
{
|
||||
var counter = 0;
|
||||
foreach (var value in jArray.ToObject<List<object>>())
|
||||
{
|
||||
queryString.Add($"{subKey}[{counter++}]", value.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
queryString.Add(subKey, jObject.Value.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Verify if the credentials are OK.
|
||||
/// </summary>
|
||||
public class AuthenticationResponse : RestResponse
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* 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;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Statistics;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Optimizer.Parameters;
|
||||
using QuantConnect.Util;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// A power gauge for backtests, time and parameters to estimate the overfitting risk
|
||||
/// </summary>
|
||||
public class ResearchGuide
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of minutes used in developing the current backtest
|
||||
/// </summary>
|
||||
public int Minutes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The quantity of backtests run in the project
|
||||
/// </summary>
|
||||
public int BacktestCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of parameters detected
|
||||
/// </summary>
|
||||
public int Parameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project ID
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base class for backtest result object response
|
||||
/// </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>
|
||||
public string BacktestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Status of the backtest
|
||||
/// </summary>
|
||||
public string Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the backtest
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backtest creation date and time
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(DateTimeJsonConverter), DateFormat.ISOShort, DateFormat.UI)]
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Progress of the backtest in percent 0-1.
|
||||
/// </summary>
|
||||
public decimal Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization task ID, if the backtest is part of an optimization
|
||||
/// </summary>
|
||||
public string OptimizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of tradeable days
|
||||
/// </summary>
|
||||
public int TradeableDates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization parameters
|
||||
/// </summary>
|
||||
public ParameterSet ParameterSet { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Snapshot id of this backtest result
|
||||
/// </summary>
|
||||
public int SnapShotId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Results object class. Results are exhaust from backtest or live algorithms running in LEAN
|
||||
/// </summary>
|
||||
public class Backtest : BasicBacktest
|
||||
{
|
||||
/// <summary>
|
||||
/// Note on the backtest attached by the user
|
||||
/// </summary>
|
||||
public string Note { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Boolean true when the backtest is completed.
|
||||
/// </summary>
|
||||
public bool Completed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Organization ID
|
||||
/// </summary>
|
||||
public string OrganizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Rolling window detailed statistics.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public Dictionary<string, AlgorithmPerformance> RollingWindow { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total algorithm performance statistics.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public AlgorithmPerformance TotalPerformance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Charts updates for the live algorithm since the last result packet
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, Chart> Charts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Statistics information sent during the algorithm operations.
|
||||
/// </summary>
|
||||
/// <remarks>Intended for update mode -- send updates to the existing statistics in the result GUI. If statistic key does not exist in GUI, create it</remarks>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, string> Statistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Runtime banner/updating statistics in the title banner of the live algorithm GUI.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, string> RuntimeStatistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A power gauge for backtests, time and parameters to estimate the overfitting risk
|
||||
/// </summary>
|
||||
public ResearchGuide ResearchGuide { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The starting time of the backtest
|
||||
/// </summary>
|
||||
public DateTime? BacktestStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ending time of the backtest
|
||||
/// </summary>
|
||||
public DateTime? BacktestEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the backtest has error during initialization
|
||||
/// </summary>
|
||||
public bool HasInitializeError { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest node name
|
||||
/// </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>
|
||||
public DateTime? OutOfSampleMaxEndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of days of out of sample days
|
||||
/// </summary>
|
||||
public int? OutOfSampleDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backtest analysis results.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IReadOnlyList<Analysis> Analysis { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Result object class for the List Backtest response from the API
|
||||
/// </summary>
|
||||
public class BacktestSummary : BasicBacktest
|
||||
{
|
||||
/// <summary>
|
||||
/// Sharpe ratio with respect to risk free rate: measures excess of return per unit of risk
|
||||
/// </summary>
|
||||
public decimal? SharpeRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm "Alpha" statistic - abnormal returns over the risk free rate and the relationshio (beta) with the benchmark returns
|
||||
/// </summary>
|
||||
public decimal? Alpha { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm "beta" statistic - the covariance between the algorithm and benchmark performance, divided by benchmark's variance
|
||||
/// </summary>
|
||||
public decimal? Beta { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Annual compounded returns statistic based on the final-starting capital and years
|
||||
/// </summary>
|
||||
public decimal? CompoundingAnnualReturn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Drawdown maximum percentage
|
||||
/// </summary>
|
||||
public decimal? Drawdown { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ratio of the number of trades with zero or negative profit loss to the total number of trades
|
||||
/// </summary>
|
||||
public decimal? LossRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Net profit percentage
|
||||
/// </summary>
|
||||
public decimal? NetProfit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of parameters in the backtest
|
||||
/// </summary>
|
||||
public int? Parameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Price-to-sales ratio
|
||||
/// </summary>
|
||||
public decimal? Psr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// SecurityTypes present in the backtest
|
||||
/// </summary>
|
||||
public string? SecurityTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sortino ratio with respect to risk free rate: measures excess of return per unit of downside risk
|
||||
/// </summary>
|
||||
public decimal? SortinoRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of trades in the backtest
|
||||
/// </summary>
|
||||
public int? Trades { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Treynor ratio statistic is a measurement of the returns earned in excess of that which could have been earned on an investment that has no diversifiable risk
|
||||
/// </summary>
|
||||
public decimal? TreynorRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ratio of the number of trades with positive profit loss to the total number of trades
|
||||
/// </summary>
|
||||
public decimal? WinRate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of tags for the backtest
|
||||
/// </summary>
|
||||
public List<string> Tags { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper class for Backtest/* endpoints JSON response
|
||||
/// Currently used by Backtest/Read and Backtest/Create
|
||||
/// </summary>
|
||||
public class BacktestResponseWrapper : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Backtest Object
|
||||
/// </summary>
|
||||
public Backtest Backtest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the backtest is run under debugging mode
|
||||
/// </summary>
|
||||
public bool Debugging { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collection container for a list of backtests for a project
|
||||
/// </summary>
|
||||
public class BacktestList : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of summarized backtest objects
|
||||
/// </summary>
|
||||
public List<Backtest> Backtests { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collection container for a list of backtest summaries for a project
|
||||
/// </summary>
|
||||
public class BacktestSummaryList : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of summarized backtest summary objects
|
||||
/// </summary>
|
||||
public List<BacktestSummary> Backtests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of backtest summaries retrieved in the response
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collection container for a list of backtest tags
|
||||
/// </summary>
|
||||
public class BacktestTags : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of tags for a backtest
|
||||
/// </summary>
|
||||
public List<string> Tags { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Backtest Report Response wrapper
|
||||
/// </summary>
|
||||
public class BacktestReport : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// HTML data of the report with embedded base64 images
|
||||
/// </summary>
|
||||
public string Report { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Optimizer;
|
||||
using QuantConnect.Optimizer.Objectives;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Optimizer.Parameters;
|
||||
using QuantConnect.Util;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// BaseOptimization item from the QuantConnect.com API.
|
||||
/// </summary>
|
||||
public class BaseOptimization : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Optimization ID
|
||||
/// </summary>
|
||||
public string OptimizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project ID of the project the optimization belongs to
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the optimization
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Status of the optimization
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter), converterParameters: typeof(CamelCaseNamingStrategy))]
|
||||
public OptimizationStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization node type
|
||||
/// </summary>
|
||||
/// <remarks><see cref="OptimizationNodes"/></remarks>
|
||||
public string NodeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of days of out of sample days
|
||||
/// </summary>
|
||||
public int OutOfSampleDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// End date of out of sample data
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(DateTimeJsonConverter), DateFormat.ISOShort, DateFormat.UI)]
|
||||
public DateTime? OutOfSampleMaxEndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parameters used in this optimization
|
||||
/// </summary>
|
||||
public List<OptimizationParameter> Parameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization statistical target
|
||||
/// </summary>
|
||||
public Target Criterion { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optimization summary response for creating an optimization
|
||||
/// </summary>
|
||||
public class OptimizationSummary: BaseOptimization
|
||||
{
|
||||
/// <summary>
|
||||
/// Date when this optimization was created
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(DateTimeJsonConverter), DateFormat.ISOShort, DateFormat.UI)]
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Price-sales ratio stastic
|
||||
/// </summary>
|
||||
public decimal? PSR { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sharpe ratio statistic
|
||||
/// </summary>
|
||||
public decimal? SharpeRatio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of trades
|
||||
/// </summary>
|
||||
public int? Trades { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID of project, were this current project was originally cloned
|
||||
/// </summary>
|
||||
public int? CloneId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Response from the compiler on a build event
|
||||
/// </summary>
|
||||
public class Compile : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Compile Id for a sucessful build
|
||||
/// </summary>
|
||||
public string CompileId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True on successful compile
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public CompileState State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Logs of the compilation request
|
||||
/// </summary>
|
||||
public List<string> Logs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project Id we sent for compile
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Signature key of compilation
|
||||
/// </summary>
|
||||
public string Signature { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Signature order of files to be compiled
|
||||
/// </summary>
|
||||
public List<string> SignatureOrder { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// State of the compilation request
|
||||
/// </summary>
|
||||
public enum CompileState
|
||||
{
|
||||
/// <summary>
|
||||
/// Compile waiting in the queue to be processed.
|
||||
/// </summary>
|
||||
InQueue,
|
||||
|
||||
/// <summary>
|
||||
/// Compile was built successfully
|
||||
/// </summary>
|
||||
BuildSuccess,
|
||||
|
||||
/// <summary>
|
||||
/// Build error, check logs for more information
|
||||
/// </summary>
|
||||
BuildError
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
// Collection of response objects for Quantconnect Data/ endpoints
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Data/Read response wrapper, contains link to requested data
|
||||
/// </summary>
|
||||
public class DataLink : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Url to the data requested
|
||||
/// </summary>
|
||||
public string Link { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Remaining QCC balance on account after this transaction
|
||||
/// </summary>
|
||||
public double Balance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// QCC Cost for this data link
|
||||
/// </summary>
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data/List response wrapper for available data
|
||||
/// </summary>
|
||||
public class DataList : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// List of all available data from this request
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "objects")]
|
||||
public List<string> AvailableData { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Data/Prices response wrapper for prices by vendor
|
||||
/// </summary>
|
||||
public class DataPricesList : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of prices objects
|
||||
/// </summary>
|
||||
public List<PriceEntry> Prices { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Agreement URL for this Organization
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "agreement")]
|
||||
public string AgreementUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the price in QCC for a given data file
|
||||
/// </summary>
|
||||
/// <param name="path">Lean data path of the file</param>
|
||||
/// <returns>QCC price for data, -1 if no entry found</returns>
|
||||
public int GetPrice(string path)
|
||||
{
|
||||
if (path == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var entry = Prices.FirstOrDefault(x => x.RegEx.IsMatch(path));
|
||||
return entry?.Price ?? -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prices entry for Data/Prices response
|
||||
/// </summary>
|
||||
public class PriceEntry
|
||||
{
|
||||
private Regex _regex;
|
||||
|
||||
/// <summary>
|
||||
/// Vendor for this price
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "vendorName")]
|
||||
public string Vendor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Regex for this data price entry
|
||||
/// Trims regex open, close, and multiline flag
|
||||
/// because it won't match otherwise
|
||||
/// </summary>
|
||||
public Regex RegEx
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_regex == null && RawRegEx != null)
|
||||
{
|
||||
_regex = new Regex(RawRegEx.TrimStart('/').TrimEnd('m').TrimEnd('/'), RegexOptions.Compiled);
|
||||
}
|
||||
return _regex;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RegEx directly from response
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "regex")]
|
||||
public string RawRegEx { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The price for this entry in QCC
|
||||
/// </summary>
|
||||
public int? Price { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The type associated to this price entry if any
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the user is subscribed
|
||||
/// </summary>
|
||||
public bool? Subscribed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The associated product id
|
||||
/// </summary>
|
||||
public int ProductId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The associated data paths
|
||||
/// </summary>
|
||||
public HashSet<string> Paths { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Estimate response packet from the QuantConnect.com API.
|
||||
/// </summary>
|
||||
public class Estimate: StringRepresentation
|
||||
{
|
||||
/// <summary>
|
||||
/// Estimate id
|
||||
/// </summary>
|
||||
public string EstimateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Estimate time in seconds
|
||||
/// </summary>
|
||||
public int Time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Estimate balance in QCC
|
||||
/// </summary>
|
||||
public int Balance { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper class for Optimizations/* endpoints JSON response
|
||||
/// Currently used by Optimizations/Estimate
|
||||
/// </summary>
|
||||
public class EstimateResponseWrapper : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Estimate object
|
||||
/// </summary>
|
||||
public Estimate Estimate { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using QuantConnect.Algorithm.Framework.Alphas;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing insights and the number of insights of the live algorithm in the request criteria
|
||||
/// </summary>
|
||||
public class InsightResponse: RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of insights
|
||||
/// </summary>
|
||||
public List<Insight> Insights { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total number of returned insights
|
||||
/// </summary>
|
||||
public int Length { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Class representing the REST response from QC API when creating or reading a live algorithm
|
||||
/// </summary>
|
||||
public class BaseLiveAlgorithm : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Project id for the live instance
|
||||
/// </summary>
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unique live algorithm deployment identifier (similar to a backtest id).
|
||||
/// </summary>
|
||||
public string DeployId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class representing the REST response from QC API when creating a live algorithm
|
||||
/// </summary>
|
||||
public class CreateLiveAlgorithmResponse : BaseLiveAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// The version of the Lean used to run the algorithm
|
||||
/// </summary>
|
||||
public int VersionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id of the node that will run the algorithm
|
||||
/// </summary>
|
||||
public string Source { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// HTTP status response code
|
||||
/// </summary>
|
||||
public string ResponseCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response from List Live Algorithms request to QuantConnect Rest API.
|
||||
/// </summary>
|
||||
public class LiveAlgorithmSummary : BaseLiveAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm status: running, stopped or runtime error.
|
||||
/// </summary>
|
||||
public AlgorithmStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Datetime the algorithm was launched in UTC.
|
||||
/// </summary>
|
||||
public DateTime Launched { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Datetime the algorithm was stopped in UTC, null if its still running.
|
||||
/// </summary>
|
||||
public DateTime? Stopped { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Brokerage
|
||||
/// </summary>
|
||||
public string Brokerage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Chart we're subscribed to
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Data limitations mean we can only stream one chart at a time to the consumer. See which chart you're watching here.
|
||||
/// </remarks>
|
||||
public string Subscription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Live algorithm error message from a crash or algorithm runtime error.
|
||||
/// </summary>
|
||||
public string Error { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of the live algorithms running which match the requested status
|
||||
/// </summary>
|
||||
public class LiveList : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Algorithm list matching the requested status.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "live")]
|
||||
public List<LiveAlgorithmSummary> Algorithms { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using QuantConnect.Packets;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Details a live algorithm from the "live/read" Api endpoint
|
||||
/// </summary>
|
||||
public class LiveAlgorithmResults : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Error message
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the status of the algorihtm, i.e. 'Running', 'Stopped'
|
||||
/// </summary>
|
||||
public string Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Algorithm deployment ID
|
||||
/// </summary>
|
||||
public string DeployId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The snapshot project ID for cloning the live development's source code.
|
||||
/// </summary>
|
||||
public int CloneId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date the live algorithm was launched
|
||||
/// </summary>
|
||||
public DateTime Launched { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date the live algorithm was stopped
|
||||
/// </summary>
|
||||
public DateTime? Stopped { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Brokerage used in the live algorithm
|
||||
/// </summary>
|
||||
public string Brokerage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Security types present in the live algorithm
|
||||
/// </summary>
|
||||
public string SecurityTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the project the live algorithm is in
|
||||
/// </summary>
|
||||
public string ProjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the data center where the algorithm is physically located.
|
||||
/// </summary>
|
||||
public string Datacenter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the algorithm is being live shared
|
||||
/// </summary>
|
||||
public bool Public { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Files present in the project in which the algorithm is
|
||||
/// </summary>
|
||||
public List<ProjectFile> Files { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Runtime banner/updating statistics in the title banner of the live algorithm GUI.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, string> RuntimeStatistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Charts updates for the live algorithm since the last result packet
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, Chart> Charts { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holds information about the state and operation of the live running algorithm
|
||||
/// </summary>
|
||||
public class LiveResultsData
|
||||
{
|
||||
/// <summary>
|
||||
/// Results version
|
||||
/// </summary>
|
||||
public int Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Temporal resolution of the results returned from the Api
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "resolution"), JsonConverter(typeof(StringEnumConverter))]
|
||||
public Resolution Resolution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Class to represent the data groups results return from the Api
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "results")]
|
||||
public LiveResult Results { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Util;
|
||||
using QuantConnect.Orders;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using QuantConnect.Packets;
|
||||
using QuantConnect.Securities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom JsonConverter for LiveResults data for live algorithms
|
||||
/// </summary>
|
||||
public class LiveAlgorithmResultsJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this <see cref="T:Newtonsoft.Json.JsonConverter"/> can write JSON.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this <see cref="T:Newtonsoft.Json.JsonConverter"/> can write JSON; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param><param name="value">The value.</param><param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException("The LiveAlgorithmResultsJsonConverter does not implement a WriteJson method.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
/// </summary>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return typeof(LiveAlgorithmResults).IsAssignableFrom(objectType);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param><param name="objectType">Type of the object.</param><param name="existingValue">The existing value of object being read.</param><param name="serializer">The calling serializer.</param>
|
||||
/// <returns>
|
||||
/// The object value.
|
||||
/// </returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var jObject = JObject.Load(reader);
|
||||
|
||||
// We don't deserialize the json object directly since it contains properties such as `files` and `charts`
|
||||
// that need to be deserialized in a different way
|
||||
var liveAlgoResults = new LiveAlgorithmResults
|
||||
{
|
||||
Message = jObject["message"].Value<string>(),
|
||||
Status = jObject["status"].Value<string>(),
|
||||
DeployId = jObject["deployId"].Value<string>(),
|
||||
CloneId = jObject["cloneId"].Value<int>(),
|
||||
Launched = jObject["launched"].Value<DateTime>(),
|
||||
Stopped = jObject["stopped"].Value<DateTime?>(),
|
||||
Brokerage = jObject["brokerage"].Value<string>(),
|
||||
SecurityTypes = jObject["securityTypes"].Value<string>(),
|
||||
ProjectName = jObject["projectName"].Value<string>(),
|
||||
Datacenter = jObject["datacenter"].Value<string>(),
|
||||
Public = jObject["public"].Value<bool>(),
|
||||
Success = jObject["success"].Value<bool>()
|
||||
};
|
||||
|
||||
if (!liveAlgoResults.Success)
|
||||
{
|
||||
// Either there was an error in the running algorithm or the algorithm hasn't started
|
||||
liveAlgoResults.Errors = jObject.Last.Children().Select(error => error.ToString()).ToList();
|
||||
return liveAlgoResults;
|
||||
}
|
||||
|
||||
// Deserialize charting data
|
||||
var chartDictionary = new Dictionary<string, Chart>();
|
||||
var charts = jObject["charts"] ?? jObject["Charts"];
|
||||
if (charts != null)
|
||||
{
|
||||
var stringCharts = jObject["charts"]?.ToString() ?? jObject["Charts"].ToString();
|
||||
if(!string.IsNullOrEmpty(stringCharts))
|
||||
{
|
||||
chartDictionary = JsonConvert.DeserializeObject<Dictionary<string, Chart>>(stringCharts);
|
||||
}
|
||||
}
|
||||
|
||||
// Deserialize files data
|
||||
var projectFiles = new List<ProjectFile>();
|
||||
var files = jObject["files"] ?? jObject["Files"];
|
||||
if (files != null)
|
||||
{
|
||||
var stringFiles = jObject["files"]?.ToString() ?? jObject["Files"].ToString();
|
||||
if (!string.IsNullOrEmpty(stringFiles))
|
||||
{
|
||||
projectFiles = JsonConvert.DeserializeObject<List<ProjectFile>>(stringFiles);
|
||||
}
|
||||
}
|
||||
|
||||
liveAlgoResults.Charts = chartDictionary;
|
||||
liveAlgoResults.Files = projectFiles;
|
||||
|
||||
return liveAlgoResults;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Brokerages;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class to put BaseLiveAlgorithmSettings in proper format.
|
||||
/// </summary>
|
||||
public class LiveAlgorithmApiSettingsWrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructor for LiveAlgorithmApiSettingsWrapper
|
||||
/// </summary>
|
||||
/// <param name="projectId">Id of project from QuantConnect</param>
|
||||
/// <param name="compileId">Id of compilation of project from QuantConnect</param>
|
||||
/// <param name="nodeId">Server type to run live Algorithm</param>
|
||||
/// <param name="settings">Dictionary with brokerage specific settings. Each brokerage requires certain specific credentials
|
||||
/// in order to process the given orders. Each key in this dictionary represents a required field/credential
|
||||
/// to provide to the brokerage API and its value represents the value of that field. For example: "brokerageSettings: {
|
||||
/// "id": "Binance", "binance-api-secret": "123ABC", "binance-api-key": "ABC123"}. It is worth saying,
|
||||
/// that this dictionary must always contain an entry whose key is "id" and its value is the name of the brokerage
|
||||
/// (see <see cref="Brokerages.BrokerageName"/>)</param>
|
||||
/// <param name="version">The version identifier</param>
|
||||
/// <param name="dataProviders">Dictionary with data providers credentials. Each data provider requires certain credentials
|
||||
/// in order to retrieve data from their API. Each key in this dictionary describes a data provider name
|
||||
/// and its corresponding value is another dictionary with the required key-value pairs of credential
|
||||
/// names and values. For example: "dataProviders: {InteractiveBrokersBrokerage : { "id": 12345, "environement" : "paper",
|
||||
/// "username": "testUsername", "password": "testPassword"}}"</param>
|
||||
/// <param name="parameters">Dictionary to specify the parameters for the live algorithm</param>
|
||||
/// <param name="notification">Dictionary with the lists of events and targets</param>
|
||||
public LiveAlgorithmApiSettingsWrapper(
|
||||
int projectId,
|
||||
string compileId,
|
||||
string nodeId,
|
||||
Dictionary<string, object> settings,
|
||||
string version = "-1",
|
||||
Dictionary<string, object> dataProviders = null,
|
||||
Dictionary<string, string> parameters = null,
|
||||
Dictionary<string, List<string>> notification = null)
|
||||
{
|
||||
VersionId = version;
|
||||
ProjectId = projectId;
|
||||
CompileId = compileId;
|
||||
NodeId = nodeId;
|
||||
Brokerage = settings;
|
||||
|
||||
var quantConnectDataProvider = new Dictionary<string, string>
|
||||
{
|
||||
{ "id", "QuantConnectBrokerage" },
|
||||
};
|
||||
|
||||
DataProviders = dataProviders ?? new Dictionary<string, object>()
|
||||
{
|
||||
{ "QuantConnectBrokerage", quantConnectDataProvider },
|
||||
};
|
||||
Signature = CompileId.Split("-").LastOrDefault();
|
||||
Parameters = parameters ?? new Dictionary<string, string>();
|
||||
Notification = notification ?? new Dictionary<string, List<string>>();
|
||||
AutomaticRedeploy = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// -1 is master
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "versionId")]
|
||||
public string VersionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project id for the live instance
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "projectId")]
|
||||
public int ProjectId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compile Id for the live algorithm
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "compileId")]
|
||||
public string CompileId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id of the node being used to run live algorithm
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "nodeId")]
|
||||
public string NodeId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Signature of the live algorithm
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "signature")]
|
||||
public string Signature { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// True to enable Automatic Re-Deploy of the live algorithm,
|
||||
/// false otherwise
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "automaticRedeploy")]
|
||||
public bool AutomaticRedeploy { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The API expects the settings as part of a brokerage object
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "brokerage")]
|
||||
public Dictionary<string, object> Brokerage { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary with the data providers and their corresponding credentials
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "dataProviders")]
|
||||
public Dictionary<string, object> DataProviders { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary with the parameters to be used in the live algorithm
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "parameters")]
|
||||
public Dictionary<string, string> Parameters { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary with the lists of events and targets
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "notification")]
|
||||
public Dictionary<string, List<string>> Notification { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Logs from a live algorithm
|
||||
/// </summary>
|
||||
public class LiveLog : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// List of logs from the live algorithm
|
||||
/// </summary>
|
||||
public List<string> Logs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total amount of rows in the logs
|
||||
/// </summary>
|
||||
public int Length { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Amount of log rows before the current deployment
|
||||
/// </summary>
|
||||
public int DeploymentOffset { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Node class built for API endpoints nodes/read and nodes/create.
|
||||
/// Converts JSON properties from API response into data members for the class.
|
||||
/// Contains all relevant information on a Node to interact through API endpoints.
|
||||
/// </summary>
|
||||
public class Node
|
||||
{
|
||||
/// <summary>
|
||||
/// The nodes cpu clock speed in GHz.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "speed")]
|
||||
public decimal Speed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The monthly and yearly prices of the node in US dollars,
|
||||
/// see <see cref="NodePrices"/> for type.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "price")]
|
||||
public NodePrices Prices { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// CPU core count of node.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "cpu")]
|
||||
public int CpuCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if the node has GPU (1) or not (0)
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "hasGpu")]
|
||||
public int HasGPU { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of RAM in Gigabytes.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "ram")]
|
||||
public decimal Ram { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the node.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Node type identifier for configuration.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "sku")]
|
||||
public string SKU { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Description of the node.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// User currently using the node.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "usedBy")]
|
||||
public string UsedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// URL of the user using the node
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "userProfile")]
|
||||
public string UserProfile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Project the node is being used for.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "projectName")]
|
||||
public string ProjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id of the project the node is being used for.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "projectId")]
|
||||
public int? ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the node is currently busy.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "busy")]
|
||||
public bool Busy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Full ID of node.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of assets recommended for this node.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "assets")]
|
||||
public int Assets { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Node host.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "host")]
|
||||
public string Host { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if this is the active node. The project will use this node if it's not busy.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "active")]
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collection of <see cref="Node"/> objects for each target environment.
|
||||
/// </summary>
|
||||
public class NodeList : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of backtest nodes
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "backtest")]
|
||||
public List<Node> BacktestNodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of research nodes
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "research")]
|
||||
public List<Node> ResearchNodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of live nodes
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "live")]
|
||||
public List<Node> LiveNodes { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rest api response wrapper for node/create, reads in the nodes information into a
|
||||
/// node object
|
||||
/// </summary>
|
||||
public class CreatedNode : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The created node from node/create
|
||||
/// </summary>
|
||||
[JsonProperty("node")]
|
||||
public Node Node { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class for generating a SKU for a node with a given configuration
|
||||
/// Every SKU is made up of 3 variables:
|
||||
/// - Target environment (L for live, B for Backtest, R for Research)
|
||||
/// - CPU core count
|
||||
/// - Dedicated RAM (GB)
|
||||
/// </summary>
|
||||
public class SKU
|
||||
{
|
||||
/// <summary>
|
||||
/// The number of CPU cores in the node
|
||||
/// </summary>
|
||||
public int Cores { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of RAM in GB of the Node
|
||||
/// </summary>
|
||||
public int Memory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Target environment for the node
|
||||
/// </summary>
|
||||
public NodeType Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a SKU object out of the provided node configuration
|
||||
/// </summary>
|
||||
/// <param name="cores">Number of cores</param>
|
||||
/// <param name="memory">Size of RAM in GBs</param>
|
||||
/// <param name="target">Target Environment Live/Backtest/Research</param>
|
||||
public SKU(int cores, int memory, NodeType target)
|
||||
{
|
||||
Cores = cores;
|
||||
Memory = memory;
|
||||
Target = target;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates the SKU string for API calls based on the specifications of the node
|
||||
/// </summary>
|
||||
/// <returns>String representation of the SKU</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
string result = "";
|
||||
|
||||
switch (Target)
|
||||
{
|
||||
case NodeType.Backtest:
|
||||
result += "B";
|
||||
break;
|
||||
case NodeType.Research:
|
||||
result += "R";
|
||||
break;
|
||||
case NodeType.Live:
|
||||
result += "L";
|
||||
break;
|
||||
}
|
||||
|
||||
if (Cores == 0)
|
||||
{
|
||||
result += "-MICRO";
|
||||
}
|
||||
else
|
||||
{
|
||||
result += Cores + "-" + Memory;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NodeTypes enum for all possible options of target environments
|
||||
/// Used in conjuction with SKU class as a NodeType is a required parameter for SKU
|
||||
/// </summary>
|
||||
public enum NodeType
|
||||
{
|
||||
/// <summary>
|
||||
/// A node for running backtests (0)
|
||||
/// </summary>
|
||||
Backtest,
|
||||
|
||||
/// <summary>
|
||||
/// A node for running research (1)
|
||||
/// </summary>
|
||||
Research,
|
||||
|
||||
/// <summary>
|
||||
/// A node for live trading (2)
|
||||
/// </summary>
|
||||
Live
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class for deserializing node prices from node object
|
||||
/// </summary>
|
||||
public class NodePrices
|
||||
{
|
||||
/// <summary>
|
||||
/// The monthly price of the node in US dollars
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "monthly")]
|
||||
public int Monthly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The yearly prices of the node in US dollars
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "yearly")]
|
||||
public int Yearly { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Supported optimization nodes
|
||||
/// </summary>
|
||||
public static class OptimizationNodes
|
||||
{
|
||||
/// <summary>
|
||||
/// 2 CPUs 8 GB ram
|
||||
/// </summary>
|
||||
public static string O2_8 => "O2-8";
|
||||
|
||||
/// <summary>
|
||||
/// 4 CPUs 12 GB ram
|
||||
/// </summary>
|
||||
public static string O4_12 => "O4-12";
|
||||
|
||||
/// <summary>
|
||||
/// 8 CPUs 16 GB ram
|
||||
/// </summary>
|
||||
public static string O8_16 => "O8-16";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Response received when fetching Object Store
|
||||
/// </summary>
|
||||
public class GetObjectStoreResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Job ID which can be used for querying state or packaging
|
||||
/// </summary>
|
||||
[JsonProperty("jobId")]
|
||||
public string JobId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL to download the object. This can also be null
|
||||
/// </summary>
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class contining basic store properties present in the REST response from QC API
|
||||
/// </summary>
|
||||
public class BasicObjectStore
|
||||
{
|
||||
/// <summary>
|
||||
/// Object store key
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "key")]
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last time it was modified
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "modified")]
|
||||
public DateTime? Modified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MIME type
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "mime")]
|
||||
public string Mime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// File size
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "size")]
|
||||
public decimal? Size { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Summary information of the Object Store
|
||||
/// </summary>
|
||||
public class SummaryObjectStore: BasicObjectStore
|
||||
{
|
||||
/// <summary>
|
||||
/// File or folder name
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if it is a folder, false otherwise
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "isFolder")]
|
||||
public bool IsFolder { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Object Store file properties
|
||||
/// </summary>
|
||||
public class PropertiesObjectStore: BasicObjectStore
|
||||
{
|
||||
/// <summary>
|
||||
/// Date this object was created
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "created")]
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MD5 (hashing algorithm) hash authentication code
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "md5")]
|
||||
public string Md5 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Preview of the Object Store file content
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "preview")]
|
||||
public string Preview { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response received containing a list of stored objects metadata, as well as the total size of all of them.
|
||||
/// </summary>
|
||||
public class ListObjectStoreResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Path to the files in the Object Store
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "path")]
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of objects stored
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "objects")]
|
||||
public List<SummaryObjectStore> Objects { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of all objects stored in bytes
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "objectStorageUsed")]
|
||||
public long ObjectStorageUsed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Size of all the objects stored in human-readable format
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "objectStorageUsedHuman")]
|
||||
public string ObjectStorageUsedHuman { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response received containing the properties of the requested Object Store
|
||||
/// </summary>
|
||||
public class PropertiesObjectStoreResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Object Store properties
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "metadata")]
|
||||
public PropertiesObjectStore Properties { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Optimizer;
|
||||
using QuantConnect.Optimizer.Objectives;
|
||||
using QuantConnect.Util;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Optimization response packet from the QuantConnect.com API.
|
||||
/// </summary>
|
||||
public class Optimization : BaseOptimization
|
||||
{
|
||||
/// <summary>
|
||||
/// Snapshot ID of this optimization
|
||||
/// </summary>
|
||||
public int? SnapshotId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Statistic to be optimized
|
||||
/// </summary>
|
||||
public string OptimizationTarget { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List with grid charts representing the grid layout
|
||||
/// </summary>
|
||||
public List<GridChart> GridLayout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Runtime banner/updating statistics for the optimization
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, string> RuntimeStatistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization constraints
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IReadOnlyList<Constraint> Constraints { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of parallel nodes for optimization
|
||||
/// </summary>
|
||||
public int ParallelNodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization constraints
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public IDictionary<string, OptimizationBacktest> Backtests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization strategy
|
||||
/// </summary>
|
||||
public string Strategy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization requested date and time
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(DateTimeJsonConverter), DateFormat.ISOShort, DateFormat.UI)]
|
||||
public DateTime Requested { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Aggregate diagnostic of the optimization; omitted when no analysis was produced.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
public OptimizationAnalysis Analysis { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wrapper class for Optimizations/Read endpoint JSON response
|
||||
/// </summary>
|
||||
public class OptimizationResponseWrapper : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Optimization object
|
||||
/// </summary>
|
||||
public Optimization Optimization { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collection container for a list of summarized optimizations for a project
|
||||
/// </summary>
|
||||
public class OptimizationList : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of summarized optimization objects
|
||||
/// </summary>
|
||||
public List<OptimizationSummary> Optimizations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The optimization count
|
||||
/// </summary>
|
||||
public int Count => Optimizations?.Count ?? 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using QuantConnect.Optimizer.Parameters;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// OptimizationBacktest object from the QuantConnect.com API.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(OptimizationBacktestJsonConverter))]
|
||||
public class OptimizationBacktest
|
||||
{
|
||||
/// <summary>
|
||||
/// Progress of the backtest as a percentage from 0-1 based on the days lapsed from start-finish.
|
||||
/// </summary>
|
||||
public decimal Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest name
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest host name
|
||||
/// </summary>
|
||||
public string HostName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest id
|
||||
/// </summary>
|
||||
public string BacktestId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Represent a combination as key value of parameters, i.e. order doesn't matter
|
||||
/// </summary>
|
||||
public ParameterSet ParameterSet { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest statistics results
|
||||
/// </summary>
|
||||
public IDictionary<string, string> Statistics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest equity chart series
|
||||
/// </summary>
|
||||
public CandlestickSeries Equity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The exit code of this backtest
|
||||
/// </summary>
|
||||
public int ExitCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Backtest maximum end date
|
||||
/// </summary>
|
||||
public DateTime? OutOfSampleMaxEndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest out of sample day count
|
||||
/// </summary>
|
||||
public int OutOfSampleDays { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest start date
|
||||
/// </summary>
|
||||
public DateTime StartDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The backtest end date
|
||||
/// </summary>
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance
|
||||
/// </summary>
|
||||
/// <param name="parameterSet">The parameter set</param>
|
||||
/// <param name="backtestId">The backtest id if any</param>
|
||||
/// <param name="name">The backtest name</param>
|
||||
public OptimizationBacktest(ParameterSet parameterSet, string backtestId, string name)
|
||||
{
|
||||
ParameterSet = parameterSet;
|
||||
BacktestId = backtestId;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using QuantConnect.Optimizer.Parameters;
|
||||
using QuantConnect.Statistics;
|
||||
using QuantConnect.Util;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Json converter for <see cref="OptimizationBacktest"/> which creates a light weight easy to consume serialized version
|
||||
/// </summary>
|
||||
public class OptimizationBacktestJsonConverter : JsonConverter
|
||||
{
|
||||
private static Dictionary<string, int> StatisticsIndices = new()
|
||||
{
|
||||
{ PerformanceMetrics.Alpha, 0 },
|
||||
{ PerformanceMetrics.AnnualStandardDeviation, 1 },
|
||||
{ PerformanceMetrics.AnnualVariance, 2 },
|
||||
{ PerformanceMetrics.AverageLoss, 3 },
|
||||
{ PerformanceMetrics.AverageWin, 4 },
|
||||
{ PerformanceMetrics.Beta, 5 },
|
||||
{ PerformanceMetrics.CompoundingAnnualReturn, 6 },
|
||||
{ PerformanceMetrics.Drawdown, 7 },
|
||||
{ PerformanceMetrics.EstimatedStrategyCapacity, 8 },
|
||||
{ PerformanceMetrics.Expectancy, 9 },
|
||||
{ PerformanceMetrics.InformationRatio, 10 },
|
||||
{ PerformanceMetrics.LossRate, 11 },
|
||||
{ PerformanceMetrics.NetProfit, 12 },
|
||||
{ PerformanceMetrics.ProbabilisticSharpeRatio, 13 },
|
||||
{ PerformanceMetrics.ProfitLossRatio, 14 },
|
||||
{ PerformanceMetrics.SharpeRatio, 15 },
|
||||
{ PerformanceMetrics.TotalFees, 16 },
|
||||
{ PerformanceMetrics.TotalOrders, 17 },
|
||||
{ PerformanceMetrics.TrackingError, 18 },
|
||||
{ PerformanceMetrics.TreynorRatio, 19 },
|
||||
{ PerformanceMetrics.WinRate, 20 },
|
||||
{ PerformanceMetrics.SortinoRatio, 21 },
|
||||
{ PerformanceMetrics.StartEquity, 22 },
|
||||
{ PerformanceMetrics.EndEquity, 23 },
|
||||
{ PerformanceMetrics.DrawdownRecovery, 24 },
|
||||
};
|
||||
|
||||
private static string[] StatisticNames { get; } = StatisticsIndices
|
||||
.OrderBy(kvp => kvp.Value)
|
||||
.Select(kvp => kvp.Key)
|
||||
.ToArray();
|
||||
|
||||
// Only 21 Lean statistics where supported when the serialized statistics where a json array
|
||||
private static int ArrayStatisticsCount = 21;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
/// </summary>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(OptimizationBacktest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
var optimizationBacktest = value as OptimizationBacktest;
|
||||
if (ReferenceEquals(optimizationBacktest, null)) return;
|
||||
|
||||
writer.WriteStartObject();
|
||||
|
||||
if (!string.IsNullOrEmpty(optimizationBacktest.Name))
|
||||
{
|
||||
writer.WritePropertyName("name");
|
||||
writer.WriteValue(optimizationBacktest.Name);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(optimizationBacktest.BacktestId))
|
||||
{
|
||||
writer.WritePropertyName("id");
|
||||
writer.WriteValue(optimizationBacktest.BacktestId);
|
||||
|
||||
writer.WritePropertyName("progress");
|
||||
writer.WriteValue(optimizationBacktest.Progress);
|
||||
|
||||
writer.WritePropertyName("exitCode");
|
||||
writer.WriteValue(optimizationBacktest.ExitCode);
|
||||
}
|
||||
|
||||
if (optimizationBacktest.StartDate != default)
|
||||
{
|
||||
writer.WritePropertyName("startDate");
|
||||
writer.WriteValue(optimizationBacktest.StartDate.ToStringInvariant(DateFormat.ISOShort));
|
||||
}
|
||||
|
||||
if (optimizationBacktest.EndDate != default)
|
||||
{
|
||||
writer.WritePropertyName("endDate");
|
||||
writer.WriteValue(optimizationBacktest.EndDate.ToStringInvariant(DateFormat.ISOShort));
|
||||
}
|
||||
|
||||
if (optimizationBacktest.OutOfSampleMaxEndDate != null)
|
||||
{
|
||||
writer.WritePropertyName("outOfSampleMaxEndDate");
|
||||
writer.WriteValue(optimizationBacktest.OutOfSampleMaxEndDate.ToStringInvariant(DateFormat.ISOShort));
|
||||
|
||||
writer.WritePropertyName("outOfSampleDays");
|
||||
writer.WriteValue(optimizationBacktest.OutOfSampleDays);
|
||||
}
|
||||
|
||||
if (!optimizationBacktest.Statistics.IsNullOrEmpty())
|
||||
{
|
||||
writer.WritePropertyName("statistics");
|
||||
writer.WriteStartObject();
|
||||
|
||||
var customStatisticsNames = new HashSet<string>();
|
||||
|
||||
foreach (var (name, statisticValue, index) in optimizationBacktest.Statistics
|
||||
.Select(kvp => (Name: kvp.Key, kvp.Value, Index: StatisticsIndices.TryGetValue(kvp.Key, out var index) ? index : int.MaxValue))
|
||||
.OrderBy(t => t.Index)
|
||||
.ThenByDescending(t => t.Name))
|
||||
{
|
||||
var statistic = statisticValue.Replace("%", string.Empty, StringComparison.InvariantCulture);
|
||||
if (Currencies.TryParse(statistic, out var result))
|
||||
{
|
||||
writer.WritePropertyName(index < StatisticsIndices.Count ? index.ToStringInvariant() : name);
|
||||
writer.WriteValue(result);
|
||||
}
|
||||
}
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
||||
if (optimizationBacktest.ParameterSet != null)
|
||||
{
|
||||
writer.WritePropertyName("parameterSet");
|
||||
serializer.Serialize(writer, optimizationBacktest.ParameterSet.Value);
|
||||
}
|
||||
|
||||
if (optimizationBacktest.Equity != null)
|
||||
{
|
||||
writer.WritePropertyName("equity");
|
||||
|
||||
var equity = JsonConvert.SerializeObject(optimizationBacktest.Equity.Values);
|
||||
writer.WriteRawValue(equity);
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <param name="existingValue">The existing value of object being read.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
/// <returns>
|
||||
/// The object value.
|
||||
/// </returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var jObject = JObject.Load(reader);
|
||||
|
||||
var name = jObject["name"].Value<string>();
|
||||
var hostName = jObject["hostName"]?.Value<string>();
|
||||
var backtestId = jObject["id"].Value<string>();
|
||||
var progress = jObject["progress"].Value<decimal>();
|
||||
var exitCode = jObject["exitCode"].Value<int>();
|
||||
|
||||
var outOfSampleDays = jObject["outOfSampleDays"]?.Value<int>() ?? default;
|
||||
var startDate = jObject["startDate"]?.Value<DateTime?>() ?? default;
|
||||
var endDate = jObject["endDate"]?.Value<DateTime?>() ?? default;
|
||||
var outOfSampleMaxEndDate = jObject["outOfSampleMaxEndDate"]?.Value<DateTime>();
|
||||
|
||||
var jStatistics = jObject["statistics"];
|
||||
Dictionary<string, string> statistics = default;
|
||||
if (jStatistics != null)
|
||||
{
|
||||
if (jStatistics.Type == JTokenType.Array)
|
||||
{
|
||||
var statsCount = Math.Min(ArrayStatisticsCount, (jStatistics as JArray).Count);
|
||||
statistics = new Dictionary<string, string>(StatisticsIndices
|
||||
.Where(kvp => kvp.Value < statsCount)
|
||||
.Select(kvp => KeyValuePair.Create(kvp.Key, jStatistics[kvp.Value].Value<string>()))
|
||||
.Where(kvp => kvp.Value != null));
|
||||
}
|
||||
else
|
||||
{
|
||||
statistics = new();
|
||||
foreach (var statistic in jStatistics.Children<JProperty>())
|
||||
{
|
||||
var statisticName = TryConvertToLeanStatisticIndex(statistic.Name, out var index)
|
||||
? StatisticNames[index]
|
||||
: statistic.Name;
|
||||
statistics[statisticName] = statistic.Value.Value<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var parameterSet = serializer.Deserialize<ParameterSet>(jObject["parameterSet"].CreateReader());
|
||||
|
||||
var equity = new CandlestickSeries();
|
||||
if (jObject["equity"] != null)
|
||||
{
|
||||
foreach (var point in JsonConvert.DeserializeObject<List<Candlestick>>(jObject["equity"].ToString()))
|
||||
{
|
||||
equity.AddPoint(point);
|
||||
}
|
||||
}
|
||||
|
||||
var optimizationBacktest = new OptimizationBacktest(parameterSet, backtestId, name)
|
||||
{
|
||||
HostName = hostName,
|
||||
Progress = progress,
|
||||
ExitCode = exitCode,
|
||||
Statistics = statistics,
|
||||
Equity = equity,
|
||||
EndDate = endDate,
|
||||
StartDate = startDate,
|
||||
OutOfSampleDays = outOfSampleDays,
|
||||
OutOfSampleMaxEndDate = outOfSampleMaxEndDate,
|
||||
};
|
||||
|
||||
return optimizationBacktest;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static bool TryConvertToLeanStatisticIndex(string statistic, out int index)
|
||||
{
|
||||
return int.TryParse(statistic, out index) && index >= 0 && index < StatisticsIndices.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using QuantConnect.Api.Serialization;
|
||||
|
||||
// Collection of response objects for QuantConnect Organization/ endpoints
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Response wrapper for Organizations/Read
|
||||
/// </summary>
|
||||
public class OrganizationResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Organization read from the response
|
||||
/// </summary>
|
||||
public Organization Organization { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Object representation of Organization from QuantConnect Api
|
||||
/// </summary>
|
||||
public class Organization: StringRepresentation
|
||||
{
|
||||
/// <summary>
|
||||
/// Data Agreement information
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "data")]
|
||||
public DataAgreement DataAgreement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Organization Product Subscriptions
|
||||
/// </summary>
|
||||
public List<Product> Products { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Organization Credit Balance and Transactions
|
||||
/// </summary>
|
||||
public Credit Credit { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Organization Data Agreement
|
||||
/// </summary>
|
||||
public class DataAgreement
|
||||
{
|
||||
/// <summary>
|
||||
/// Epoch time the Data Agreement was Signed
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "signedTime")]
|
||||
public long? EpochSignedTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DateTime the agreement was signed.
|
||||
/// Uses EpochSignedTime converted to a standard datetime.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DateTime? SignedTime => EpochSignedTime.HasValue ? DateTimeOffset.FromUnixTimeSeconds(EpochSignedTime.Value).DateTime : null;
|
||||
|
||||
/// <summary>
|
||||
/// True/False if it is currently signed
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "current")]
|
||||
public bool Signed { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Organization Credit Object
|
||||
/// </summary>
|
||||
public class Credit
|
||||
{
|
||||
/// <summary>
|
||||
/// QCC Current Balance
|
||||
/// </summary>
|
||||
public decimal Balance { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// QuantConnect Products
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(ProductJsonConverter))]
|
||||
public class Product
|
||||
{
|
||||
/// <summary>
|
||||
/// Product Type
|
||||
/// </summary>
|
||||
public ProductType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of item subscriptions
|
||||
/// Nodes/Data/Seats/etc
|
||||
/// </summary>
|
||||
public List<ProductItem> Items { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// QuantConnect ProductItem
|
||||
/// </summary>
|
||||
public class ProductItem
|
||||
{
|
||||
/// <summary>
|
||||
/// ID for this product
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "productId")]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Quantity for this product
|
||||
/// </summary>
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Product types offered by QuantConnect
|
||||
/// Used by Product class
|
||||
/// </summary>
|
||||
public enum ProductType
|
||||
{
|
||||
/// <summary>
|
||||
/// Professional Seats Subscriptions
|
||||
/// </summary>
|
||||
ProfessionalSeats,
|
||||
|
||||
/// <summary>
|
||||
/// Backtest Nodes Subscriptions
|
||||
/// </summary>
|
||||
BacktestNode,
|
||||
|
||||
/// <summary>
|
||||
/// Research Nodes Subscriptions
|
||||
/// </summary>
|
||||
ResearchNode,
|
||||
|
||||
/// <summary>
|
||||
/// Live Trading Nodes Subscriptions
|
||||
/// </summary>
|
||||
LiveNode,
|
||||
|
||||
/// <summary>
|
||||
/// Support Subscriptions
|
||||
/// </summary>
|
||||
Support,
|
||||
|
||||
/// <summary>
|
||||
/// Data Subscriptions
|
||||
/// </summary>
|
||||
Data,
|
||||
|
||||
/// <summary>
|
||||
/// Modules Subscriptions
|
||||
/// </summary>
|
||||
Modules
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using QuantConnect.Optimizer.Parameters;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Json converter for <see cref="ParameterSet"/> which creates a light weight easy to consume serialized version
|
||||
/// </summary>
|
||||
public class ParameterSetJsonConverter : JsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
/// </summary>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(ParameterSet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a JSON object from a Parameter set
|
||||
/// </summary>
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
var parameterSet = value as ParameterSet;
|
||||
if (ReferenceEquals(parameterSet, null)) return;
|
||||
|
||||
writer.WriteStartObject();
|
||||
|
||||
if (parameterSet.Value != null)
|
||||
{
|
||||
writer.WritePropertyName("parameterSet");
|
||||
serializer.Serialize(writer, parameterSet.Value);
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <param name="existingValue">The existing value of object being read.</param>
|
||||
/// <param name="serializer">The calling serializer.</param>
|
||||
/// <returns>
|
||||
/// The object value.
|
||||
/// </returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.StartArray)
|
||||
{
|
||||
if (JArray.Load(reader).Count == 0)
|
||||
{
|
||||
return new ParameterSet(-1, new Dictionary<string, string>());
|
||||
}
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.StartObject)
|
||||
{
|
||||
var jObject = JObject.Load(reader);
|
||||
|
||||
var value = jObject["parameterSet"] ?? jObject;
|
||||
|
||||
var parameterSet = new ParameterSet(-1, value.ToObject<Dictionary<string, string>>());
|
||||
|
||||
return parameterSet;
|
||||
}
|
||||
|
||||
throw new ArgumentException($"Unexpected Tokentype {reader.TokenType}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
using QuantConnect.Securities;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Class containing the basic portfolio information of a live algorithm
|
||||
/// </summary>
|
||||
public class Portfolio
|
||||
{
|
||||
/// <summary>
|
||||
/// Dictionary of algorithm holdings information
|
||||
/// </summary>
|
||||
public Dictionary<string, Holding> Holdings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary of algorithm cash currencies information
|
||||
/// </summary>
|
||||
public Dictionary<string, Cash> Cash { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response class for reading the portfolio of a live algorithm
|
||||
/// </summary>
|
||||
public class PortfolioResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Object containing the basic portfolio information of a live algorithm
|
||||
/// </summary>
|
||||
public Portfolio Portfolio { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
/*
|
||||
* 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;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Collaborator responses
|
||||
/// </summary>
|
||||
public class Collaborator
|
||||
{
|
||||
/// <summary>
|
||||
/// User ID
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "uid")]
|
||||
public int? Uid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if the user have live control
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "liveControl")]
|
||||
public bool LiveControl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The permission this user is given. Can be "read"
|
||||
/// or "write"
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "permission")]
|
||||
public string Permission { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user public ID
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "publicId")]
|
||||
public string PublicId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The url of the user profile image
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "profileImage")]
|
||||
public string ProfileImage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The registered email of the user
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The display name of the user
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The biography of the user
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "bio")]
|
||||
public string Bio { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if the user is the owner of the project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "owner")]
|
||||
public bool Owner { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Library response
|
||||
/// </summary>
|
||||
public class Library
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Project Id of the library project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "projectId")]
|
||||
public int Projectid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the library project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "libraryName")]
|
||||
public string LibraryName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the library project owner
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "ownerName")]
|
||||
public string OwnerName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if the library project can be accessed
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "access")]
|
||||
public bool Access { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The chart display properties
|
||||
/// </summary>
|
||||
public class GridChart
|
||||
{
|
||||
/// <summary>
|
||||
/// The chart name
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "chartName")]
|
||||
public string ChartName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Width of the chart
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "width")]
|
||||
public int Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Height of the chart
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "height")]
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of rows of the chart
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "row")]
|
||||
public int Row { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of columns of the chart
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "column")]
|
||||
public int Column { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sort of the chart
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "sort")]
|
||||
public int Sort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optionally related definition
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "definition")]
|
||||
public List<string> Definition { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The grid arrangement of charts
|
||||
/// </summary>
|
||||
public class Grid
|
||||
{
|
||||
/// <summary>
|
||||
/// List of chart in the xs (Extra small) position
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "xs")]
|
||||
public List<GridChart> Xs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of chart in the sm (Small) position
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "sm")]
|
||||
public List<GridChart> Sm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of chart in the md (Medium) position
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "md")]
|
||||
public List<GridChart> Md { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of chart in the lg (Large) position
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "lg")]
|
||||
public List<GridChart> Lg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of chart in the xl (Extra large) position
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "xl")]
|
||||
public List<GridChart> Xl { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encryption key details
|
||||
/// </summary>
|
||||
public class EncryptionKey
|
||||
{
|
||||
/// <summary>
|
||||
/// Encryption key id
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the encryption key
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parameter set
|
||||
/// </summary>
|
||||
public class Parameter
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of parameter
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Value of parameter
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "value")]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response from reading a project by id.
|
||||
/// </summary>
|
||||
public class Project : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Project id
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "projectId")]
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date the project was created
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "created")]
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Modified date for the project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "modified")]
|
||||
public DateTime Modified { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Programming language of the project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "language")]
|
||||
public Language Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The projects owner id
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "ownerId")]
|
||||
public int OwnerId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The organization ID
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "organizationId")]
|
||||
public string OrganizationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of collaborators
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "collaborators")]
|
||||
public List<Collaborator> Collaborators { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The version of LEAN this project is running on
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "leanVersionId")]
|
||||
public int LeanVersionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if the project is pinned to the master branch of LEAN
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "leanPinnedToMaster")]
|
||||
public bool LeanPinnedToMaster { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if you are the owner of the project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "owner")]
|
||||
public bool Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The project description
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Channel id
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "channelId")]
|
||||
public string ChannelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optimization parameters
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "parameters")]
|
||||
public List<Parameter> Parameters { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The library projects
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "libraries")]
|
||||
public List<Library> Libraries { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Configuration of the backtest view grid
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "grid")]
|
||||
public Grid Grid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Configuration of the live view grid
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "liveGrid")]
|
||||
public Grid LiveGrid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The equity value of the last paper trading instance
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "paperEquity")]
|
||||
public decimal? PaperEquity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The last live deployment active time
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "lastLiveDeployment")]
|
||||
public DateTime? LastLiveDeployment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The last live wizard content used
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "liveForm")]
|
||||
public object LiveForm { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the project is encrypted
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "encrypted")]
|
||||
public bool? Encrypted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the project is running or not
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "codeRunning")]
|
||||
public bool CodeRunning { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// LEAN environment of the project running on
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "leanEnvironment")]
|
||||
public int LeanEnvironment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Text file with at least 32 characters to be used to encrypt the project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "encryptionKey")]
|
||||
public EncryptionKey EncryptionKey { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API response for version
|
||||
/// </summary>
|
||||
public class Version
|
||||
{
|
||||
/// <summary>
|
||||
/// ID of the LEAN version
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Date when this version was created
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "created")]
|
||||
public DateTime? Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Description of the LEAN version
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Commit Hash in the LEAN repository
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "leanHash")]
|
||||
public string LeanHash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Commit Hash in the LEAN Cloud repository
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "leanCloudHash")]
|
||||
public string LeanCloudHash { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Name of the branch where the commit is
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the branch where the commit is
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "ref")]
|
||||
public string Ref { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the version is available for the public (1) or not (0)
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "public")]
|
||||
public bool Public { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read versions response
|
||||
/// </summary>
|
||||
public class VersionsResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// List of LEAN versions
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "versions")]
|
||||
public List<Version> Versions { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Project list response
|
||||
/// </summary>
|
||||
public class ProjectResponse : VersionsResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// List of projects for the authenticated user
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "projects")]
|
||||
public List<Project> Projects { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// File for a project
|
||||
/// </summary>
|
||||
public class ProjectFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of a project file
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Contents of the project file
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "content")]
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// DateTime project file was modified
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "modified")]
|
||||
public DateTime DateModified{ get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the project file is a library or not
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "isLibrary")]
|
||||
public bool IsLibrary { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the project file is open or not
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "open")]
|
||||
public bool Open { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID of the project
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "projectId")]
|
||||
public int ProjectId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ID of the project file, can be null
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "id")]
|
||||
public int? Id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Response received when creating a file or reading one file or more in a project
|
||||
/// </summary>
|
||||
public class ProjectFilesResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// List of project file information
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "files")]
|
||||
public List<ProjectFile> Files { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Response received when reading or updating some nodes of a project
|
||||
/// </summary>
|
||||
public class ProjectNodesResponse : RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// List of project nodes.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "nodes")]
|
||||
public NodeList Nodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if the node is automatically selected
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "autoSelectNode")]
|
||||
public bool AutoSelectNode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Class for wrapping Read Chart response
|
||||
/// </summary>
|
||||
public class ReadChartResponse: RestResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Chart object from the ReadChart response
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "chart")]
|
||||
public Chart Chart { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.Collections.Generic;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Base API response class for the QuantConnect API.
|
||||
/// </summary>
|
||||
public class RestResponse: StringRepresentation
|
||||
{
|
||||
/// <summary>
|
||||
/// JSON Constructor
|
||||
/// </summary>
|
||||
public RestResponse()
|
||||
{
|
||||
Success = false;
|
||||
Errors = new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicate if the API request was successful.
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of errors with the API call.
|
||||
/// </summary>
|
||||
public List<string> Errors { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace QuantConnect.Api.Serialization
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an implementation of <see cref="JsonConverter"/> that can deserialize <see cref="Product"/>
|
||||
/// </summary>
|
||||
public class ProductJsonConverter : JsonConverter
|
||||
{
|
||||
private Dictionary<string, ProductType> _productTypeMap = new Dictionary<string, ProductType>()
|
||||
{
|
||||
{"Professional Seats", ProductType.ProfessionalSeats},
|
||||
{"Backtest Node", ProductType.BacktestNode},
|
||||
{"Research Node", ProductType.ResearchNode},
|
||||
{"Live Trading Node", ProductType.LiveNode},
|
||||
{"Support", ProductType.Support},
|
||||
{"Data", ProductType.Data},
|
||||
{"Modules", ProductType.Modules}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this <see cref="JsonConverter"/> can write JSON.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this <see cref="JsonConverter"/> can write JSON; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public override bool CanWrite => false;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this instance can convert the specified object type.
|
||||
/// </summary>
|
||||
/// <param name="objectType">Type of the object.</param>
|
||||
/// <returns>
|
||||
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return objectType == typeof(Product);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param><param name="value">The value.</param><param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException("The OrderJsonConverter does not implement a WriteJson method;.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the JSON representation of the object.
|
||||
/// </summary>
|
||||
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param><param name="objectType">Type of the object.</param><param name="existingValue">The existing value of object being read.</param><param name="serializer">The calling serializer.</param>
|
||||
/// <returns>
|
||||
/// The object value.
|
||||
/// </returns>
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var jObject = JObject.Load(reader);
|
||||
|
||||
var result = CreateProductFromJObject(jObject);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an order from a simple JObject
|
||||
/// </summary>
|
||||
/// <param name="jObject"></param>
|
||||
/// <returns>Order Object</returns>
|
||||
public Product CreateProductFromJObject(JObject jObject)
|
||||
{
|
||||
if (jObject == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var productTypeName = jObject["name"].Value<string>();
|
||||
if (!_productTypeMap.ContainsKey(productTypeName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Product
|
||||
{
|
||||
Type = _productTypeMap[productTypeName],
|
||||
Items = jObject["items"].ToObject<List<ProductItem>>()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 Newtonsoft.Json;
|
||||
|
||||
namespace QuantConnect.Api
|
||||
{
|
||||
/// <summary>
|
||||
/// Class to return the string representation of an API response class
|
||||
/// </summary>
|
||||
public class StringRepresentation
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the string representation of this object
|
||||
/// </summary>
|
||||
public override string ToString()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user