Lean  $LEAN_TAG$
BaseContract.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 QuantConnect.Python;
17 using System;
18 
20 {
21  /// <summary>
22  /// Defines a base for a single contract, like an option or future contract
23  /// </summary>
24  public abstract class BaseContract : ISymbolProvider
25  {
26  /// <summary>
27  /// Gets the contract's symbol
28  /// </summary>
29  [PandasIgnore]
30  public Symbol Symbol
31  {
32  get; set;
33  }
34 
35  /// <summary>
36  /// The security identifier of the symbol
37  /// </summary>
38  [PandasIgnore]
40 
41  /// <summary>
42  /// Gets the underlying security's symbol
43  /// </summary>
45 
46  /// <summary>
47  /// Gets the expiration date
48  /// </summary>
49  public DateTime Expiry => Symbol.ID.Date;
50 
51  /// <summary>
52  /// Gets the local date time this contract's data was last updated
53  /// </summary>
54  [PandasIgnore]
55  public DateTime Time
56  {
57  get; set;
58  }
59 
60  /// <summary>
61  /// Gets the open interest
62  /// </summary>
63  public virtual decimal OpenInterest { get; set; }
64 
65  /// <summary>
66  /// Gets the last price this contract traded at
67  /// </summary>
68  public virtual decimal LastPrice { get; set; }
69 
70  /// <summary>
71  /// Gets the last volume this contract traded at
72  /// </summary>
73  public virtual long Volume { get; set; }
74 
75  /// <summary>
76  /// Gets the current bid price
77  /// </summary>
78  public virtual decimal BidPrice { get; set; }
79 
80  /// <summary>
81  /// Get the current bid size
82  /// </summary>
83  public virtual long BidSize { get; set; }
84 
85  /// <summary>
86  /// Gets the ask price
87  /// </summary>
88  public virtual decimal AskPrice { get; set; }
89 
90  /// <summary>
91  /// Gets the current ask size
92  /// </summary>
93  public virtual long AskSize { get; set; }
94 
95  /// <summary>
96  /// Initializes a new instance of the <see cref="BaseContract"/> class
97  /// </summary>
98  /// <param name="symbol">The contract symbol</param>
99  protected BaseContract(Symbol symbol)
100  {
101  Symbol = symbol;
102  }
103 
104  /// <summary>
105  /// Returns a string that represents the current object.
106  /// </summary>
107  /// <returns>
108  /// A string that represents the current object.
109  /// </returns>
110  public override string ToString() => Symbol.Value;
111 
112  /// <summary>
113  /// Updates the contract with the new data, which can be a <see cref="Tick"/> or <see cref="TradeBar"/> or <see cref="QuoteBar"/>
114  /// </summary>
115  internal abstract void Update(BaseData data);
116  }
117 }