Lean
$LEAN_TAG$
DefaultSymbolGenerator.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
QuantConnect
.
Securities
;
20
21
namespace
QuantConnect.ToolBox.RandomDataGenerator
22
{
23
/// <summary>
24
/// Generates a new random <see cref="Symbol"/> object of the specified security type.
25
/// All returned symbols have a matching entry in the Symbol properties database.
26
/// </summary>
27
/// <remarks>
28
/// A valid implementation will keep track of generated Symbol objects to ensure duplicates
29
/// are not generated.
30
/// </remarks>
31
public
class
DefaultSymbolGenerator
:
BaseSymbolGenerator
32
{
33
private
readonly
string
_market;
34
private
readonly
SecurityType
_securityType;
35
36
/// <summary>
37
/// Creates <see cref="DefaultSymbolGenerator"/> instance
38
/// </summary>
39
/// <param name="settings">random data generation run settings</param>
40
/// <param name="random">produces random values for use in random data generation</param>
41
public
DefaultSymbolGenerator
(
RandomDataGeneratorSettings
settings,
IRandomValueGenerator
random)
42
: base(settings, random)
43
{
44
_market = settings.Market;
45
_securityType = settings.SecurityType;
46
}
47
48
/// <summary>
49
/// Generates a single-item list at a time using base random implementation
50
/// </summary>
51
/// <returns></returns>
52
protected
override
IEnumerable<Symbol>
GenerateAsset
(
string
ticker =
null
)
53
{
54
yield
return
NextSymbol
(
Settings
.SecurityType,
Settings
.Market, ticker);
55
}
56
57
/// <summary>
58
/// Returns the number of symbols with the specified parameters can be generated.
59
/// Returns int.MaxValue if there is no limit for the given parameters.
60
/// </summary>
61
/// <returns>The number of available symbols for the given parameters, or int.MaxValue if no limit</returns>
62
public
override
int
GetAvailableSymbolCount
()
63
{
64
// check the Symbol properties database to determine how many symbols we can generate
65
// if there is a wildcard entry, we can generate as many symbols as we want
66
// if there is no wildcard entry, we can only generate as many symbols as there are entries
67
return
SymbolPropertiesDatabase
.
ContainsKey
(_market,
SecurityDatabaseKey
.
Wildcard
, _securityType)
68
?
int
.MaxValue
69
:
SymbolPropertiesDatabase
.
GetSymbolPropertiesList
(_market, _securityType).Count();
70
}
71
}
72
}
ToolBox
RandomDataGenerator
DefaultSymbolGenerator.cs
Generated by
1.8.17