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