Lean  $LEAN_TAG$
IAlgorithm.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 NodaTime;
18 using QuantConnect.Data;
19 using QuantConnect.Orders;
20 using QuantConnect.Storage;
28 using System.Collections.Generic;
29 using System.Collections.Concurrent;
35 
37 {
38  /// <summary>
39  /// Defines an event fired from within an algorithm instance.
40  /// </summary>
41  /// <typeparam name="T">The event type</typeparam>
42  /// <param name="algorithm">The algorithm that fired the event</param>
43  /// <param name="eventData">The event data</param>
44  public delegate void AlgorithmEvent<in T>(IAlgorithm algorithm, T eventData);
45 
46  /// <summary>
47  /// Interface for QuantConnect algorithm implementations. All algorithms must implement these
48  /// basic members to allow interaction with the Lean Backtesting Engine.
49  /// </summary>
51  {
52  /// <summary>
53  /// Event fired when an algorithm generates a insight
54  /// </summary>
55  event AlgorithmEvent<GeneratedInsightsCollection> InsightsGenerated;
56 
57  /// <summary>
58  /// Gets the time keeper instance
59  /// </summary>
61  {
62  get;
63  }
64 
65  /// <summary>
66  /// Data subscription manager controls the information and subscriptions the algorithms recieves.
67  /// Subscription configurations can be added through the Subscription Manager.
68  /// </summary>
70  {
71  get;
72  }
73 
74  /// <summary>
75  /// The project id associated with this algorithm if any
76  /// </summary>
77  int ProjectId
78  {
79  get;
80  set;
81  }
82 
83  /// <summary>
84  /// Security object collection class stores an array of objects representing representing each security/asset
85  /// we have a subscription for.
86  /// </summary>
87  /// <remarks>It is an IDictionary implementation and can be indexed by symbol</remarks>
89  {
90  get;
91  }
92 
93  /// <summary>
94  /// Gets the collection of universes for the algorithm
95  /// </summary>
97  {
98  get;
99  }
100 
101  /// <summary>
102  /// Security portfolio management class provides wrapper and helper methods for the Security.Holdings class such as
103  /// IsLong, IsShort, TotalProfit
104  /// </summary>
105  /// <remarks>Portfolio is a wrapper and helper class encapsulating the Securities[].Holdings objects</remarks>
107  {
108  get;
109  }
110 
111  /// <summary>
112  /// Security transaction manager class controls the store and processing of orders.
113  /// </summary>
114  /// <remarks>The orders and their associated events are accessible here. When a new OrderEvent is recieved the algorithm portfolio is updated.</remarks>
116  {
117  get;
118  }
119 
120  /// <summary>
121  /// Gets the brokerage model used to emulate a real brokerage
122  /// </summary>
124  {
125  get;
126  }
127 
128  /// <summary>
129  /// Gets the brokerage name.
130  /// </summary>
132  {
133  get;
134  }
135 
136  /// <summary>
137  /// Gets the risk free interest rate model used to get the interest rates
138  /// </summary>
140  {
141  get;
142  }
143 
144  /// <summary>
145  /// Gets the brokerage message handler used to decide what to do
146  /// with each message sent from the brokerage
147  /// </summary>
149  {
150  get;
151  set;
152  }
153 
154  /// <summary>
155  /// Notification manager for storing and processing live event messages
156  /// </summary>
158  {
159  get;
160  }
161 
162  /// <summary>
163  /// Gets schedule manager for adding/removing scheduled events
164  /// </summary>
166  {
167  get;
168  }
169 
170  /// <summary>
171  /// Gets or sets the history provider for the algorithm
172  /// </summary>
174  {
175  get;
176  set;
177  }
178 
179  /// <summary>
180  /// Gets or sets the current status of the algorithm
181  /// </summary>
183  {
184  get;
185  set;
186  }
187 
188  /// <summary>
189  /// Gets whether or not this algorithm is still warming up
190  /// </summary>
191  bool IsWarmingUp
192  {
193  get;
194  }
195 
196  /// <summary>
197  /// Public name for the algorithm.
198  /// </summary>
199  string Name
200  {
201  get;
202  set;
203  }
204 
205  /// <summary>
206  /// A list of tags associated with the algorithm or the backtest, useful for categorization
207  /// </summary>
208  HashSet<string> Tags
209  {
210  get;
211  set;
212  }
213 
214  /// <summary>
215  /// Event fired algorithm's name is changed
216  /// </summary>
217  event AlgorithmEvent<string> NameUpdated;
218 
219  /// <summary>
220  /// Event fired when the tag collection is updated
221  /// </summary>
222  event AlgorithmEvent<HashSet<string>> TagsUpdated;
223 
224  /// <summary>
225  /// Current date/time in the algorithm's local time zone
226  /// </summary>
227  DateTime Time
228  {
229  get;
230  }
231 
232  /// <summary>
233  /// Gets the time zone of the algorithm
234  /// </summary>
235  DateTimeZone TimeZone
236  {
237  get;
238  }
239 
240  /// <summary>
241  /// Current date/time in UTC.
242  /// </summary>
243  DateTime UtcTime
244  {
245  get;
246  }
247 
248  /// <summary>
249  /// Algorithm start date for backtesting, set by the SetStartDate methods.
250  /// </summary>
251  DateTime StartDate
252  {
253  get;
254  }
255 
256  /// <summary>
257  /// Get Requested Backtest End Date
258  /// </summary>
259  DateTime EndDate
260  {
261  get;
262  }
263 
264  /// <summary>
265  /// AlgorithmId for the backtest
266  /// </summary>
267  string AlgorithmId
268  {
269  get;
270  }
271 
272  /// <summary>
273  /// Algorithm is running on a live server.
274  /// </summary>
275  bool LiveMode
276  {
277  get;
278  }
279 
280  /// <summary>
281  /// Algorithm running mode.
282  /// </summary>
284  {
285  get;
286  }
287 
288  /// <summary>
289  /// Deployment target, either local or cloud.
290  /// </summary>
292  {
293  get;
294  }
295 
296  /// <summary>
297  /// Gets the subscription settings to be used when adding securities via universe selection
298  /// </summary>
300  {
301  get;
302  }
303 
304  /// <summary>
305  /// Debug messages from the strategy:
306  /// </summary>
307  ConcurrentQueue<string> DebugMessages
308  {
309  get;
310  }
311 
312  /// <summary>
313  /// Error messages from the strategy:
314  /// </summary>
315  ConcurrentQueue<string> ErrorMessages
316  {
317  get;
318  }
319 
320  /// <summary>
321  /// Log messages from the strategy:
322  /// </summary>
323  ConcurrentQueue<string> LogMessages
324  {
325  get;
326  }
327 
328  /// <summary>
329  /// Gets the run time error from the algorithm, or null if none was encountered.
330  /// </summary>
331  Exception RunTimeError
332  {
333  get;
334  set;
335  }
336 
337  /// <summary>
338  /// Customizable dynamic statistics displayed during live trading:
339  /// </summary>
340  ConcurrentDictionary<string, string> RuntimeStatistics
341  {
342  get;
343  }
344 
345  /// <summary>
346  /// The current algorithm statistics for the running algorithm.
347  /// </summary>
349  {
350  get;
351  }
352 
353  /// <summary>
354  /// Gets the function used to define the benchmark. This function will return
355  /// the value of the benchmark at a requested date/time
356  /// </summary>
358  {
359  get;
360  }
361 
362  /// <summary>
363  /// Gets the Trade Builder to generate trades from executions
364  /// </summary>
366  {
367  get;
368  }
369 
370  /// <summary>
371  /// Gets the user settings for the algorithm
372  /// </summary>
374  {
375  get;
376  }
377 
378  /// <summary>
379  /// Gets the option chain provider, used to get the list of option contracts for an underlying symbol
380  /// </summary>
382  {
383  get;
384  }
385 
386  /// <summary>
387  /// Gets the future chain provider, used to get the list of future contracts for an underlying symbol
388  /// </summary>
390  {
391  get;
392  }
393 
394  /// <summary>
395  /// Gets the insight manager
396  /// </summary>
398  {
399  get;
400  }
401 
402  /// <summary>
403  /// Gets the object store, used for persistence
404  /// </summary>
406 
407  /// <summary>
408  /// Returns the current Slice object
409  /// </summary>
411 
412  /// <summary>
413  /// Initialise the Algorithm and Prepare Required Data:
414  /// </summary>
415  void Initialize();
416 
417  /// <summary>
418  /// Called by setup handlers after Initialize and allows the algorithm a chance to organize
419  /// the data gather in the Initialize method
420  /// </summary>
421  void PostInitialize();
422 
423  /// <summary>
424  /// Called when the algorithm has completed initialization and warm up.
425  /// </summary>
426  void OnWarmupFinished();
427 
428  /// <summary>
429  /// Gets a read-only dictionary with all current parameters
430  /// </summary>
431  IReadOnlyDictionary<string, string> GetParameters();
432 
433  /// <summary>
434  /// Gets the parameter with the specified name. If a parameter with the specified name does not exist,
435  /// the given default value is returned if any, else null
436  /// </summary>
437  /// <param name="name">The name of the parameter to get</param>
438  /// <param name="defaultValue">The default value to return</param>
439  /// <returns>The value of the specified parameter, or defaultValue if not found or null if there's no default value</returns>
440  string GetParameter(string name, string defaultValue = null);
441 
442  /// <summary>
443  /// Gets the parameter with the specified name parsed as an integer. If a parameter with the specified name does not exist,
444  /// or the conversion is not possible, the given default value is returned
445  /// </summary>
446  /// <param name="name">The name of the parameter to get</param>
447  /// <param name="defaultValue">The default value to return</param>
448  /// <returns>The value of the specified parameter, or defaultValue if not found or null if there's no default value</returns>
449  int GetParameter(string name, int defaultValue);
450 
451  /// <summary>
452  /// Gets the parameter with the specified name parsed as a double. If a parameter with the specified name does not exist,
453  /// or the conversion is not possible, the given default value is returned
454  /// </summary>
455  /// <param name="name">The name of the parameter to get</param>
456  /// <param name="defaultValue">The default value to return</param>
457  /// <returns>The value of the specified parameter, or defaultValue if not found or null if there's no default value</returns>
458  double GetParameter(string name, double defaultValue);
459 
460  /// <summary>
461  /// Gets the parameter with the specified name parsed as a decimal. If a parameter with the specified name does not exist,
462  /// or the conversion is not possible, the given default value is returned
463  /// </summary>
464  /// <param name="name">The name of the parameter to get</param>
465  /// <param name="defaultValue">The default value to return</param>
466  /// <returns>The value of the specified parameter, or defaultValue if not found or null if there's no default value</returns>
467  decimal GetParameter(string name, decimal defaultValue);
468 
469  /// <summary>
470  /// Sets the parameters from the dictionary
471  /// </summary>
472  /// <param name="parameters">Dictionary containing the parameter names to values</param>
473  void SetParameters(Dictionary<string, string> parameters);
474 
475  /// <summary>
476  /// Determines if the Symbol is shortable at the brokerage
477  /// </summary>
478  /// <param name="symbol">Symbol to check if shortable</param>
479  /// <param name="shortQuantity">Order's quantity to check if it is currently shortable, taking into account current holdings and open orders</param>
480  /// <param name="updateOrderId">Optionally the id of the order being updated. When updating an order
481  /// we want to ignore it's submitted short quantity and use the new provided quantity to determine if we
482  /// can perform the update</param>
483  /// <returns>True if the symbol can be shorted by the requested quantity</returns>
484  bool Shortable(Symbol symbol, decimal shortQuantity, int? updateOrderId = null);
485 
486  /// <summary>
487  /// Gets the quantity shortable for the given asset
488  /// </summary>
489  /// <returns>
490  /// Quantity shortable for the given asset. Zero if not
491  /// shortable, or a number greater than zero if shortable.
492  /// </returns>
493  long ShortableQuantity(Symbol symbol);
494 
495  /// <summary>
496  /// Sets the brokerage model used to resolve transaction models, settlement models,
497  /// and brokerage specified ordering behaviors.
498  /// </summary>
499  /// <param name="brokerageModel">The brokerage model used to emulate the real
500  /// brokerage</param>
501  void SetBrokerageModel(IBrokerageModel brokerageModel);
502 
503  /// <summary>
504  /// v3.0 Handler for all data types
505  /// </summary>
506  /// <param name="slice">The current slice of data</param>
507  void OnData(Slice slice);
508 
509  /// <summary>
510  /// Used to send data updates to algorithm framework models
511  /// </summary>
512  /// <param name="slice">The current data slice</param>
513  void OnFrameworkData(Slice slice);
514 
515  /// <summary>
516  /// Event handler to be called when there's been a split event
517  /// </summary>
518  /// <param name="splits">The current time slice splits</param>
519  void OnSplits(Splits splits);
520 
521  /// <summary>
522  /// Event handler to be called when there's been a dividend event
523  /// </summary>
524  /// <param name="dividends">The current time slice dividends</param>
525  void OnDividends(Dividends dividends);
526 
527  /// <summary>
528  /// Event handler to be called when there's been a delistings event
529  /// </summary>
530  /// <param name="delistings">The current time slice delistings</param>
531  void OnDelistings(Delistings delistings);
532 
533  /// <summary>
534  /// Event handler to be called when there's been a symbol changed event
535  /// </summary>
536  /// <param name="symbolsChanged">The current time slice symbol changed events</param>
537  void OnSymbolChangedEvents(SymbolChangedEvents symbolsChanged);
538 
539  /// <summary>
540  /// Event fired each time that we add/remove securities from the data feed
541  /// </summary>
542  /// <param name="changes">Security additions/removals for this time step</param>
543  void OnSecuritiesChanged(SecurityChanges changes);
544 
545  /// <summary>
546  /// Used to send security changes to algorithm framework models
547  /// </summary>
548  /// <param name="changes">Security additions/removals for this time step</param>
550 
551  /// <summary>
552  /// Invoked at the end of every time step. This allows the algorithm
553  /// to process events before advancing to the next time step.
554  /// </summary>
555  void OnEndOfTimeStep();
556 
557  /// <summary>
558  /// Send debug message
559  /// </summary>
560  /// <param name="message"></param>
561  void Debug(string message);
562 
563  /// <summary>
564  /// Save entry to the Log
565  /// </summary>
566  /// <param name="message">String message</param>
567  void Log(string message);
568 
569  /// <summary>
570  /// Send an error message for the algorithm
571  /// </summary>
572  /// <param name="message">String message</param>
573  void Error(string message);
574 
575  /// <summary>
576  /// Margin call event handler. This method is called right before the margin call orders are placed in the market.
577  /// </summary>
578  /// <param name="requests">The orders to be executed to bring this algorithm within margin limits</param>
579  void OnMarginCall(List<SubmitOrderRequest> requests);
580 
581  /// <summary>
582  /// Margin call warning event handler. This method is called when Portfolio.MarginRemaining is under 5% of your Portfolio.TotalPortfolioValue
583  /// </summary>
584  void OnMarginCallWarning();
585 
586  /// <summary>
587  /// Call this method at the end of each day of data.
588  /// </summary>
589  /// <remarks>Deprecated because different assets have different market close times,
590  /// and because Python does not support two methods with the same name</remarks>
591  [Obsolete("This method is deprecated. Please use this overload: OnEndOfDay(Symbol symbol)")]
592  void OnEndOfDay();
593 
594  /// <summary>
595  /// Call this method at the end of each day of data.
596  /// </summary>
597  void OnEndOfDay(Symbol symbol);
598 
599  /// <summary>
600  /// Call this event at the end of the algorithm running.
601  /// </summary>
602  void OnEndOfAlgorithm();
603 
604  /// <summary>
605  /// EXPERTS ONLY:: [-!-Async Code-!-]
606  /// New order event handler: on order status changes (filled, partially filled, cancelled etc).
607  /// </summary>
608  /// <param name="newEvent">Event information</param>
609  void OnOrderEvent(OrderEvent newEvent);
610 
611  /// <summary>
612  /// Will submit an order request to the algorithm
613  /// </summary>
614  /// <param name="request">The request to submit</param>
615  /// <remarks>Will run order prechecks, which include making sure the algorithm is not warming up, security is added and has data among others</remarks>
616  /// <returns>The order ticket</returns>
618 
619  /// <summary>
620  /// Option assignment event handler. On an option assignment event for short legs the resulting information is passed to this method.
621  /// </summary>
622  /// <param name="assignmentEvent">Option exercise event details containing details of the assignment</param>
623  /// <remarks>This method can be called asynchronously and so should only be used by seasoned C# experts. Ensure you use proper locks on thread-unsafe objects</remarks>
624  void OnAssignmentOrderEvent(OrderEvent assignmentEvent);
625 
626  /// <summary>
627  /// Brokerage message event handler. This method is called for all types of brokerage messages.
628  /// </summary>
629  void OnBrokerageMessage(BrokerageMessageEvent messageEvent);
630 
631  /// <summary>
632  /// Brokerage disconnected event handler. This method is called when the brokerage connection is lost.
633  /// </summary>
634  void OnBrokerageDisconnect();
635 
636  /// <summary>
637  /// Brokerage reconnected event handler. This method is called when the brokerage connection is restored after a disconnection.
638  /// </summary>
639  void OnBrokerageReconnect();
640 
641  /// <summary>
642  /// Set the DateTime Frontier: This is the master time and is
643  /// </summary>
644  /// <param name="time"></param>
645  void SetDateTime(DateTime time);
646 
647  /// <summary>
648  /// Set the start date for the backtest
649  /// </summary>
650  /// <param name="start">Datetime Start date for backtest</param>
651  /// <remarks>Must be less than end date and within data available</remarks>
652  void SetStartDate(DateTime start);
653 
654  /// <summary>
655  /// Set the end date for a backtest.
656  /// </summary>
657  /// <param name="end">Datetime value for end date</param>
658  /// <remarks>Must be greater than the start date</remarks>
659  void SetEndDate(DateTime end);
660 
661  /// <summary>
662  /// Set the algorithm Id for this backtest or live run. This can be used to identify the order and equity records.
663  /// </summary>
664  /// <param name="algorithmId">unique 32 character identifier for backtest or live server</param>
665  void SetAlgorithmId(string algorithmId);
666 
667  /// <summary>
668  /// Set the algorithm as initialized and locked. No more cash or security changes.
669  /// </summary>
670  void SetLocked();
671 
672  /// <summary>
673  /// Gets whether or not this algorithm has been locked and fully initialized
674  /// </summary>
675  bool GetLocked();
676 
677  /// <summary>
678  /// Add a Chart object to algorithm collection
679  /// </summary>
680  /// <param name="chart">Chart object to add to collection.</param>
681  void AddChart(Chart chart);
682 
683  /// <summary>
684  /// Get the chart updates since the last request:
685  /// </summary>
686  /// <param name="clearChartData"></param>
687  /// <returns>List of Chart Updates</returns>
688  IEnumerable<Chart> GetChartUpdates(bool clearChartData = false);
689 
690  /// <summary>
691  /// Set a required SecurityType-symbol and resolution for algorithm
692  /// </summary>
693  /// <param name="securityType">SecurityType Enum: Equity, Commodity, FOREX or Future</param>
694  /// <param name="symbol">Symbol Representation of the MarketType, e.g. AAPL</param>
695  /// <param name="resolution">Resolution of the MarketType required: MarketData, Second or Minute</param>
696  /// <param name="market">The market the requested security belongs to, such as 'usa' or 'fxcm'</param>
697  /// <param name="fillForward">If true, returns the last available data even if none in that timeslice.</param>
698  /// <param name="leverage">leverage for this security</param>
699  /// <param name="extendedMarketHours">ExtendedMarketHours send in data from 4am - 8pm, not used for FOREX</param>
700  /// <param name="dataMappingMode">The contract mapping mode to use for the security</param>
701  /// <param name="dataNormalizationMode">The price scaling mode to use for the security</param>
702  Security AddSecurity(SecurityType securityType, string symbol, Resolution? resolution, string market, bool fillForward, decimal leverage, bool extendedMarketHours,
703  DataMappingMode? dataMappingMode = null, DataNormalizationMode? dataNormalizationMode = null);
704 
705  /// <summary>
706  /// Set a required SecurityType-symbol and resolution for algorithm
707  /// </summary>
708  /// <param name="symbol">The security Symbol</param>
709  /// <param name="resolution">Resolution of the MarketType required: MarketData, Second or Minute</param>
710  /// <param name="fillForward">If true, returns the last available data even if none in that timeslice.</param>
711  /// <param name="leverage">leverage for this security</param>
712  /// <param name="extendedMarketHours">Use extended market hours data</param>
713  /// <param name="dataMappingMode">The contract mapping mode to use for the security</param>
714  /// <param name="dataNormalizationMode">The price scaling mode to use for the security</param>
715  /// <param name="contractDepthOffset">The continuous contract desired offset from the current front month.
716  /// For example, 0 (default) will use the front month, 1 will use the back month contract</param>
717  /// <returns>The new Security that was added to the algorithm</returns>
718  Security AddSecurity(Symbol symbol, Resolution? resolution = null, bool fillForward = true, decimal leverage = Security.NullLeverage, bool extendedMarketHours = false,
719  DataMappingMode? dataMappingMode = null, DataNormalizationMode? dataNormalizationMode = null, int contractDepthOffset = 0);
720 
721  /// <summary>
722  /// Creates and adds a new single <see cref="Future"/> contract to the algorithm
723  /// </summary>
724  /// <param name="symbol">The futures contract symbol</param>
725  /// <param name="resolution">The <see cref="Resolution"/> of market data, Tick, Second, Minute, Hour, or Daily. Default is <see cref="Resolution.Minute"/></param>
726  /// <param name="fillForward">If true, returns the last available data even if none in that timeslice. Default is <value>true</value></param>
727  /// <param name="leverage">The requested leverage for this equity. Default is set by <see cref="SecurityInitializer"/></param>
728  /// <param name="extendedMarketHours">Show the after market data as well</param>
729  /// <returns>The new <see cref="Future"/> security</returns>
730  Future AddFutureContract(Symbol symbol, Resolution? resolution = null, bool fillForward = true, decimal leverage = 0m, bool extendedMarketHours = false);
731 
732  /// <summary>
733  /// Creates and adds a new single <see cref="Option"/> contract to the algorithm
734  /// </summary>
735  /// <param name="symbol">The option contract symbol</param>
736  /// <param name="resolution">The <see cref="Resolution"/> of market data, Tick, Second, Minute, Hour, or Daily. Default is <see cref="Resolution.Minute"/></param>
737  /// <param name="fillForward">If true, returns the last available data even if none in that timeslice. Default is <value>true</value></param>
738  /// <param name="leverage">The requested leverage for this equity. Default is set by <see cref="SecurityInitializer"/></param>
739  /// <param name="extendedMarketHours">Show the after market data as well</param>
740  /// <returns>The new <see cref="Option"/> security</returns>
741  Option AddOptionContract(Symbol symbol, Resolution? resolution = null, bool fillForward = true, decimal leverage = 0m, bool extendedMarketHours = false);
742 
743  /// <summary>
744  /// Removes the security with the specified symbol. This will cancel all
745  /// open orders and then liquidate any existing holdings
746  /// </summary>
747  /// <param name="symbol">The symbol of the security to be removed</param>
748  bool RemoveSecurity(Symbol symbol);
749 
750  /// <summary>
751  /// Sets the account currency cash symbol this algorithm is to manage, as well as
752  /// the starting cash in this currency if given
753  /// </summary>
754  /// <remarks>Has to be called during <see cref="Initialize"/> before
755  /// calling <see cref="SetCash(decimal)"/> or adding any <see cref="Security"/></remarks>
756  /// <param name="accountCurrency">The account currency cash symbol to set</param>
757  /// <param name="startingCash">The account currency starting cash to set</param>
758  void SetAccountCurrency(string accountCurrency, decimal? startingCash = null);
759 
760  /// <summary>
761  /// Set the starting capital for the strategy
762  /// </summary>
763  /// <param name="startingCash">decimal starting capital, default $100,000</param>
764  void SetCash(decimal startingCash);
765 
766  /// <summary>
767  /// Set the cash for the specified symbol
768  /// </summary>
769  /// <param name="symbol">The cash symbol to set</param>
770  /// <param name="startingCash">Decimal cash value of portfolio</param>
771  /// <param name="conversionRate">The current conversion rate for the</param>
772  void SetCash(string symbol, decimal startingCash, decimal conversionRate = 0);
773 
774  /// <summary>
775  /// Liquidate your portfolio holdings:
776  /// </summary>
777  /// <param name="symbolToLiquidate">Specific asset to liquidate, defaults to all.</param>
778  /// <param name="tag">Custom tag to know who is calling this.</param>
779  /// <returns>list of order ids</returns>
780  List<int> Liquidate(Symbol symbolToLiquidate = null, string tag = "Liquidated");
781 
782  /// <summary>
783  /// Set live mode state of the algorithm run: Public setter for the algorithm property LiveMode.
784  /// </summary>
785  /// <param name="live">Bool live mode flag</param>
786  void SetLiveMode(bool live);
787 
788  /// <summary>
789  /// Sets the algorithm running mode
790  /// </summary>
791  /// <param name="algorithmMode">Algorithm mode</param>
792  void SetAlgorithmMode(AlgorithmMode algorithmMode);
793 
794  /// <summary>
795  /// Sets the algorithm deployment target
796  /// </summary>
797  /// <param name="deploymentTarget">Deployment target</param>
798  void SetDeploymentTarget(DeploymentTarget deploymentTarget);
799 
800  /// <summary>
801  /// Sets <see cref="IsWarmingUp"/> to false to indicate this algorithm has finished its warm up
802  /// </summary>
803  void SetFinishedWarmingUp();
804 
805  /// <summary>
806  /// Set the maximum number of orders the algorithm is allowed to process.
807  /// </summary>
808  /// <param name="max">Maximum order count int</param>
809  void SetMaximumOrders(int max);
810 
811  /// <summary>
812  /// Sets the implementation used to handle messages from the brokerage.
813  /// The default implementation will forward messages to debug or error
814  /// and when a <see cref="BrokerageMessageType.Error"/> occurs, the algorithm
815  /// is stopped.
816  /// </summary>
817  /// <param name="handler">The message handler to use</param>
819 
820  /// <summary>
821  /// Set the historical data provider
822  /// </summary>
823  /// <param name="historyProvider">Historical data provider</param>
824  void SetHistoryProvider(IHistoryProvider historyProvider);
825 
826  /// <summary>
827  /// Get the last known price using the history provider.
828  /// Useful for seeding securities with the correct price
829  /// </summary>
830  /// <param name="security"><see cref="Security"/> object for which to retrieve historical data</param>
831  /// <returns>A single <see cref="BaseData"/> object with the last known price</returns>
833 
834  /// <summary>
835  /// Set the runtime error
836  /// </summary>
837  /// <param name="exception">Represents error that occur during execution</param>
838  void SetRunTimeError(Exception exception);
839 
840  /// <summary>
841  /// Set the state of a live deployment
842  /// </summary>
843  /// <param name="status">Live deployment status</param>
844  void SetStatus(AlgorithmStatus status);
845 
846  /// <summary>
847  /// Set the available <see cref="TickType"/> supported by each <see cref="SecurityType"/> in <see cref="SecurityManager"/>
848  /// </summary>
849  /// <param name="availableDataTypes">>The different <see cref="TickType"/> each <see cref="Security"/> supports</param>
850  void SetAvailableDataTypes(Dictionary<SecurityType, List<TickType>> availableDataTypes);
851 
852  /// <summary>
853  /// Sets the option chain provider, used to get the list of option contracts for an underlying symbol
854  /// </summary>
855  /// <param name="optionChainProvider">The option chain provider</param>
856  void SetOptionChainProvider(IOptionChainProvider optionChainProvider);
857 
858  /// <summary>
859  /// Sets the future chain provider, used to get the list of future contracts for an underlying symbol
860  /// </summary>
861  /// <param name="futureChainProvider">The future chain provider</param>
862  void SetFutureChainProvider(IFutureChainProvider futureChainProvider);
863 
864  /// <summary>
865  /// Sets the current slice
866  /// </summary>
867  /// <param name="slice">The Slice object</param>
868  void SetCurrentSlice(Slice slice);
869 
870  /// <summary>
871  /// Provide the API for the algorithm.
872  /// </summary>
873  /// <param name="api">Initiated API</param>
874  void SetApi(IApi api);
875 
876  /// <summary>
877  /// Sets the object store
878  /// </summary>
879  /// <param name="objectStore">The object store</param>
880  void SetObjectStore(IObjectStore objectStore);
881 
882  /// <summary>
883  /// Converts the string 'ticker' symbol into a full <see cref="Symbol"/> object
884  /// This requires that the string 'ticker' has been added to the algorithm
885  /// </summary>
886  /// <param name="ticker">The ticker symbol. This should be the ticker symbol
887  /// as it was added to the algorithm</param>
888  /// <returns>The symbol object mapped to the specified ticker</returns>
889  Symbol Symbol(string ticker);
890 
891  /// <summary>
892  /// For the given symbol will resolve the ticker it used at the current algorithm date
893  /// </summary>
894  /// <param name="symbol">The symbol to get the ticker for</param>
895  /// <returns>The mapped ticker for a symbol</returns>
896  string Ticker(Symbol symbol);
897 
898  /// <summary>
899  /// Sets the statistics service instance to be used by the algorithm
900  /// </summary>
901  /// <param name="statisticsService">The statistics service instance</param>
902  void SetStatisticsService(IStatisticsService statisticsService);
903 
904  /// <summary>
905  /// Sets name to the currently running backtest
906  /// </summary>
907  /// <param name="name">The name for the backtest</param>
908  void SetName(string name);
909 
910  /// <summary>
911  /// Adds a tag to the algorithm
912  /// </summary>
913  /// <param name="tag">The tag to add</param>
914  void AddTag(string tag);
915 
916  /// <summary>
917  /// Sets the tags for the algorithm
918  /// </summary>
919  /// <param name="tags">The tags</param>
920  void SetTags(HashSet<string> tags);
921  }
922 }