Lean  $LEAN_TAG$
LiveAlgorithmSettings.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14 */
15 
16 using System;
17 using System.Collections.Generic;
18 using System.Linq;
19 using Newtonsoft.Json;
21 
22 namespace QuantConnect.Api
23 {
24  /// <summary>
25  /// Helper class to put BaseLiveAlgorithmSettings in proper format.
26  /// </summary>
28  {
29  /// <summary>
30  /// Constructor for LiveAlgorithmApiSettingsWrapper
31  /// </summary>
32  /// <param name="projectId">Id of project from QuantConnect</param>
33  /// <param name="compileId">Id of compilation of project from QuantConnect</param>
34  /// <param name="nodeId">Server type to run live Algorithm</param>
35  /// <param name="settings">Dictionary with brokerage specific settings. Each brokerage requires certain specific credentials
36  /// in order to process the given orders. Each key in this dictionary represents a required field/credential
37  /// to provide to the brokerage API and its value represents the value of that field. For example: "brokerageSettings: {
38  /// "id": "Binance", "binance-api-secret": "123ABC", "binance-api-key": "ABC123"}. It is worth saying,
39  /// that this dictionary must always contain an entry whose key is "id" and its value is the name of the brokerage
40  /// (see <see cref="Brokerages.BrokerageName"/>)</param>
41  /// <param name="version">The version identifier</param>
42  /// <param name="dataProviders">Dictionary with data providers credentials. Each data provider requires certain credentials
43  /// in order to retrieve data from their API. Each key in this dictionary describes a data provider name
44  /// and its corresponding value is another dictionary with the required key-value pairs of credential
45  /// names and values. For example: "dataProviders: {InteractiveBrokersBrokerage : { "id": 12345, "environement" : "paper",
46  /// "username": "testUsername", "password": "testPassword"}}"</param>
47  /// <param name="parameters">Dictionary to specify the parameters for the live algorithm</param>
48  /// <param name="notification">Dictionary with the lists of events and targets</param>
50  int projectId,
51  string compileId,
52  string nodeId,
53  Dictionary<string, object> settings,
54  string version = "-1",
55  Dictionary<string, object> dataProviders = null,
56  Dictionary<string, string> parameters = null,
57  Dictionary<string, List<string>> notification = null)
58  {
59  VersionId = version;
60  ProjectId = projectId;
61  CompileId = compileId;
62  NodeId = nodeId;
63  Brokerage = settings;
64 
65  var quantConnectDataProvider = new Dictionary<string, string>
66  {
67  { "id", "QuantConnectBrokerage" },
68  };
69 
70  DataProviders = dataProviders ?? new Dictionary<string, object>()
71  {
72  { "QuantConnectBrokerage", quantConnectDataProvider },
73  };
74  Signature = CompileId.Split("-").LastOrDefault();
75  Parameters = parameters ?? new Dictionary<string, string>();
76  Notification = notification ?? new Dictionary<string, List<string>>();
77  AutomaticRedeploy = false;
78  }
79 
80  /// <summary>
81  /// -1 is master
82  /// </summary>
83  [JsonProperty(PropertyName = "versionId")]
84  public string VersionId { get; set; }
85 
86  /// <summary>
87  /// Project id for the live instance
88  /// </summary>
89  [JsonProperty(PropertyName = "projectId")]
90  public int ProjectId { get; private set; }
91 
92  /// <summary>
93  /// Compile Id for the live algorithm
94  /// </summary>
95  [JsonProperty(PropertyName = "compileId")]
96  public string CompileId { get; private set; }
97 
98  /// <summary>
99  /// Id of the node being used to run live algorithm
100  /// </summary>
101  [JsonProperty(PropertyName = "nodeId")]
102  public string NodeId { get; private set; }
103 
104  /// <summary>
105  /// Signature of the live algorithm
106  /// </summary>
107  [JsonProperty(PropertyName = "signature")]
108  public string Signature { get; private set; }
109 
110  /// <summary>
111  /// True to enable Automatic Re-Deploy of the live algorithm,
112  /// false otherwise
113  /// </summary>
114  [JsonProperty(PropertyName = "automaticRedeploy")]
115  public bool AutomaticRedeploy { get; private set; }
116 
117  /// <summary>
118  /// The API expects the settings as part of a brokerage object
119  /// </summary>
120  [JsonProperty(PropertyName = "brokerage")]
121  public Dictionary<string, object> Brokerage { get; private set; }
122 
123  /// <summary>
124  /// Dictionary with the data providers and their corresponding credentials
125  /// </summary>
126  [JsonProperty(PropertyName = "dataProviders")]
127  public Dictionary<string, object> DataProviders { get; private set; }
128 
129  /// <summary>
130  /// Dictionary with the parameters to be used in the live algorithm
131  /// </summary>
132  [JsonProperty(PropertyName = "parameters")]
133  public Dictionary<string, string> Parameters { get; private set; }
134 
135  /// <summary>
136  /// Dictionary with the lists of events and targets
137  /// </summary>
138  [JsonProperty(PropertyName = "notification")]
139  public Dictionary<string, List<string>> Notification { get; private set; }
140  }
141 }