/*
* 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 NodaTime;
using Python.Runtime;
using QuantConnect.Data;
using QuantConnect.Interfaces;
using QuantConnect.Packets;
using System;
using System.Collections.Generic;
using System.Linq;
namespace QuantConnect.Python.Wrappers
{
///
/// Wrapper for an instance created in Python.
/// All calls to python should be inside a "using (Py.GIL()) {/* Your code here */}" block.
///
public class HistoryProviderPythonWrapper : IHistoryProvider
{
private IHistoryProvider _historyProvider;
///
/// constructor.
/// Wraps the object.
///
/// object to be wrapped
public HistoryProviderPythonWrapper(IHistoryProvider historyProvider)
{
_historyProvider = historyProvider;
}
///
/// Wrapper for in Python
///
public int DataPointCount
{
get
{
using (Py.GIL())
{
return _historyProvider.DataPointCount;
}
}
}
///
/// Wrapper for in Python
///
/// The historical data requests
/// The time zone used when time stamping the slice instances
/// An enumerable of the slices of data covering the span specified in each request
public IEnumerable GetHistory(IEnumerable requests, DateTimeZone sliceTimeZone)
{
using (Py.GIL())
{
return _historyProvider.GetHistory(requests, sliceTimeZone).ToList();
}
}
///
/// Wrapper for in Python
///
/// The job
/// Cache system for the history request
/// Provider used to get a map file resolver to handle equity mapping
/// Provider used to get factor files to handle equity price scaling
/// Provider used to get data when it is not present on disk
/// Function used to send status updates
public void Initialize(AlgorithmNodePacket job, IDataProvider dataProvider, IDataCacheProvider dataCacheProvider, IMapFileProvider mapFileProvider, IFactorFileProvider factorFileProvider, Action statusUpdate)
{
using (Py.GIL())
{
_historyProvider.Initialize(job, dataProvider, dataCacheProvider, mapFileProvider, factorFileProvider, statusUpdate);
}
}
}
}