/* * 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 { /// /// 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. /// public class Node { /// /// The nodes cpu clock speed in GHz. /// [JsonProperty(PropertyName = "speed")] public decimal Speed { get; set; } /// /// The monthly and yearly prices of the node in US dollars, /// see for type. /// [JsonProperty(PropertyName = "price")] public NodePrices Prices { get; set; } /// /// CPU core count of node. /// [JsonProperty(PropertyName = "cpu")] public int CpuCount { get; set; } /// /// Indicate if the node has GPU (1) or not (0) /// [JsonProperty(PropertyName = "hasGpu")] public int HasGPU { get; set; } /// /// Size of RAM in Gigabytes. /// [JsonProperty(PropertyName = "ram")] public decimal Ram { get; set; } /// /// Name of the node. /// [JsonProperty(PropertyName = "name")] public string Name { get; set; } /// /// Node type identifier for configuration. /// [JsonProperty(PropertyName = "sku")] public string SKU { get; set; } /// /// Description of the node. /// [JsonProperty(PropertyName = "description")] public string Description { get; set; } /// /// User currently using the node. /// [JsonProperty(PropertyName = "usedBy")] public string UsedBy { get; set; } /// /// URL of the user using the node /// [JsonProperty(PropertyName = "userProfile")] public string UserProfile { get; set; } /// /// Project the node is being used for. /// [JsonProperty(PropertyName = "projectName")] public string ProjectName { get; set; } /// /// Id of the project the node is being used for. /// [JsonProperty(PropertyName = "projectId")] public int? ProjectId { get; set; } /// /// Indicates if the node is currently busy. /// [JsonProperty(PropertyName = "busy")] public bool Busy { get; set; } /// /// Full ID of node. /// [JsonProperty(PropertyName = "id")] public string Id { get; set; } /// /// Maximum number of assets recommended for this node. /// [JsonProperty(PropertyName = "assets")] public int Assets { get; set; } /// /// Node host. /// [JsonProperty(PropertyName = "host")] public string Host { get; set; } /// /// Indicate if this is the active node. The project will use this node if it's not busy. /// [JsonProperty(PropertyName = "active")] public bool Active { get; set; } } /// /// Collection of objects for each target environment. /// public class NodeList : RestResponse { /// /// Collection of backtest nodes /// [JsonProperty(PropertyName = "backtest")] public List BacktestNodes { get; set; } /// /// Collection of research nodes /// [JsonProperty(PropertyName = "research")] public List ResearchNodes { get; set; } /// /// Collection of live nodes /// [JsonProperty(PropertyName = "live")] public List LiveNodes { get; set; } } /// /// Rest api response wrapper for node/create, reads in the nodes information into a /// node object /// public class CreatedNode : RestResponse { /// /// The created node from node/create /// [JsonProperty("node")] public Node Node { get; set; } } /// /// 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) /// public class SKU { /// /// The number of CPU cores in the node /// public int Cores { get; set; } /// /// Size of RAM in GB of the Node /// public int Memory { get; set; } /// /// Target environment for the node /// public NodeType Target { get; set; } /// /// Constructs a SKU object out of the provided node configuration /// /// Number of cores /// Size of RAM in GBs /// Target Environment Live/Backtest/Research public SKU(int cores, int memory, NodeType target) { Cores = cores; Memory = memory; Target = target; } /// /// Generates the SKU string for API calls based on the specifications of the node /// /// String representation of the SKU 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; } } /// /// NodeTypes enum for all possible options of target environments /// Used in conjuction with SKU class as a NodeType is a required parameter for SKU /// public enum NodeType { /// A node for running backtests Backtest, //0 /// A node for running research Research, //1 /// A node for live trading Live //2 } /// /// Class for deserializing node prices from node object /// public class NodePrices { /// /// The monthly price of the node in US dollars /// [JsonProperty(PropertyName = "monthly")] public int Monthly { get; set; } /// /// The yearly prices of the node in US dollars /// [JsonProperty(PropertyName = "yearly")] public int Yearly { get; set; } } /// /// Supported optimization nodes /// public static class OptimizationNodes { /// /// 2 CPUs 8 GB ram /// public static string O2_8 => "O2-8"; /// /// 4 CPUs 12 GB ram /// public static string O4_12 => "O4-12"; /// /// 8 CPUs 16 GB ram /// public static string O8_16 => "O8-16"; } }