/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Python.Runtime;
using QuantConnect.Interfaces;
using QuantConnect.Python;
using QuantConnect.Securities;
namespace QuantConnect.Data.UniverseSelection
{
///
/// Provides an implementation of that wraps a object
///
public class UniversePythonWrapper : Universe
{
private readonly BasePythonWrapper _model;
///
/// Gets the settings used for subscriptions added for this universe
///
public override UniverseSettings UniverseSettings
{
get
{
return _model.GetProperty(nameof(UniverseSettings));
}
set
{
_model.SetProperty(nameof(UniverseSettings), value);
}
}
///
/// Flag indicating if disposal of this universe has been requested
///
public override bool DisposeRequested
{
get
{
return _model.GetProperty(nameof(DisposeRequested));
}
protected set
{
_model.SetProperty(nameof(DisposeRequested), value);
}
}
///
/// Gets the configuration used to get universe data
///
public override SubscriptionDataConfig Configuration
{
get
{
return _model.GetProperty(nameof(Configuration));
}
}
///
/// Gets the internal security collection used to define membership in this universe
///
public override ConcurrentDictionary Securities
{
get
{
return _model.GetProperty>(nameof(Securities));
}
}
///
/// Initializes a new instance of the class
///
public UniversePythonWrapper(PyObject universe) : base(null)
{
_model = new BasePythonWrapper(universe, false);
}
///
/// Performs universe selection using the data specified
///
/// The current utc time
/// The symbols to remain in the universe
/// The data that passes the filter
public override IEnumerable SelectSymbols(DateTime utcTime, BaseDataCollection data)
{
return _model.InvokeMethodAndEnumerate(nameof(SelectSymbols), utcTime, data);
}
///
/// Gets the subscription requests to be added for the specified security
///
/// The security to get subscriptions for
/// The current time in utc. This is the frontier time of the algorithm
/// The max end time
/// Instance which implements interface
/// All subscriptions required by this security
public override IEnumerable GetSubscriptionRequests(Security security, DateTime currentTimeUtc, DateTime maximumEndTimeUtc,
ISubscriptionDataConfigService subscriptionService)
{
var requests = _model.InvokeMethodAndEnumerate(nameof(GetSubscriptionRequests), security, currentTimeUtc,
maximumEndTimeUtc, subscriptionService);
foreach (var subscriptionRequest in requests)
{
yield return new SubscriptionRequest(subscriptionRequest, universe: this);
}
}
}
}