/*
* 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 QuantConnect.Api;
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; }
///
/// 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; }
///
/// String 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; }
///
/// Project the node is being used for
///
[JsonProperty(PropertyName = "projectName")]
public string ProjectName { get; set; }
///
/// Boolean 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; }
}
///
/// Rest api response wrapper for node/read, contains sets of node lists for each
/// target environment. List are composed of objects.
///
public class NodeList : RestResponse
{
///
/// Collection of backtest nodes
///
[JsonProperty(PropertyName = "backtest")]
public List BacktestNodes;
///
/// Collection of research nodes
///
[JsonProperty(PropertyName = "research")]
public List ResearchNodes;
///
/// Collection of live nodes
///
[JsonProperty(PropertyName = "live")]
public List LiveNodes;
}
///
/// 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;
///
/// Size of RAM in GB of the Node
///
public int Memory;
///
/// Target environment for the node
///
public NodeType Target;
///
/// 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; }
}
}