/*
* 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 QuantConnect.Data;
using System;
using System.Collections.Generic;
using System.IO;
using ProtoBuf;
using QuantConnect.Data.Market;
namespace QuantConnect.Data.Custom.IconicTypes
{
///
/// Data source that is unlinked (no mapping) and takes any ticker when calling AddData
///
[ProtoContract(SkipConstructor = true)]
public class UnlinkedDataTradeBar : TradeBar
{
///
/// If true, we accept any ticker from the AddData call
///
public static bool AnyTicker { get; set; }
///
/// Creates a new instance of an UnlinkedTradeBar
///
public UnlinkedDataTradeBar()
{
DataType = MarketDataType.Base;
Period = TimeSpan.FromDays(1);
}
///
/// Get Source for Custom Data File
/// >> What source file location would you prefer for each type of usage:
///
/// Configuration object
/// Date of this source request if source spread across multiple files
/// true if we're in live mode, false for backtesting mode
/// String source location of the file
public override SubscriptionDataSource GetSource(SubscriptionDataConfig config, DateTime date, bool isLiveMode)
{
return new SubscriptionDataSource(
Path.Combine(
"TestData",
"unlinkedtradebar",
AnyTicker ? "data.csv" : $"{config.Symbol.Value.ToLowerInvariant()}.csv"
),
SubscriptionTransportMedium.LocalFile,
FileFormat.Csv);
}
///
/// Fetch the data from the storage and feed it line by line into the engine.
///
/// Symbols, Resolution, DataType,
/// Line from the data file requested
/// Date of this reader request
/// true if we're in live mode, false for backtesting mode
/// Enumerable iterator for returning each line of the required data.
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
return new UnlinkedDataTradeBar
{
Open = 1m,
High = 2m,
Low = 1m,
Close = 1.5m,
Volume = 0m,
Symbol = config.Symbol,
EndTime = date
};
}
///
/// Indicates whether the data source is sparse.
/// If false, it will disable missing file logging.
///
/// true
public override bool IsSparseData()
{
return true;
}
///
/// Indicates whether the data source can undergo
/// rename events/is tied to equities.
///
/// true
public override bool RequiresMapping()
{
return false;
}
///
/// Set the data time zone to UTC
///
/// Time zone as UTC
public override DateTimeZone DataTimeZone()
{
return TimeZones.Utc;
}
///
/// Sets the default resolution to Second
///
/// Resolution.Second
public override Resolution DefaultResolution()
{
return Resolution.Daily;
}
///
/// Gets a list of all the supported Resolutions
///
/// All resolutions
public override List SupportedResolutions()
{
return DailyResolution;
}
}
}