/* * 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.Linq; using Newtonsoft.Json; using System.Collections.Generic; using System.Text.RegularExpressions; // Collection of response objects for Quantconnect Data/ endpoints namespace QuantConnect.Api { /// /// Data/Read response wrapper, contains link to requested data /// public class DataLink : RestResponse { /// /// Url to the data requested /// public string Link { get; set; } /// /// Remaining QCC balance on account after this transaction /// public double Balance { get; set; } /// /// QCC Cost for this data link /// public double Cost { get; set; } } /// /// Data/List response wrapper for available data /// public class DataList : RestResponse { /// /// List of all available data from this request /// [JsonProperty(PropertyName = "objects")] public List AvailableData { get; set; } } /// /// Data/Prices response wrapper for prices by vendor /// public class DataPricesList : RestResponse { /// /// Collection of prices objects /// public List Prices { get; set; } /// /// The Agreement URL for this Organization /// [JsonProperty(PropertyName = "agreement")] public string AgreementUrl { get; set; } /// /// Get the price in QCC for a given data file /// /// Lean data path of the file /// QCC price for data, -1 if no entry found public int GetPrice(string path) { if (path == null) { return -1; } var entry = Prices.FirstOrDefault(x => x.RegEx.IsMatch(path)); return entry?.Price ?? -1; } } /// /// Prices entry for Data/Prices response /// public class PriceEntry { private Regex _regex; /// /// Vendor for this price /// [JsonProperty(PropertyName = "vendorName")] public string Vendor { get; set; } /// /// Regex for this data price entry /// Trims regex open, close, and multiline flag /// because it won't match otherwise /// public Regex RegEx { get { if (_regex == null && RawRegEx != null) { _regex = new Regex(RawRegEx.TrimStart('/').TrimEnd('m').TrimEnd('/'), RegexOptions.Compiled); } return _regex; } } /// /// RegEx directly from response /// [JsonProperty(PropertyName = "regex")] public string RawRegEx { get; set; } /// /// The price for this entry in QCC /// public int? Price { get; set; } /// /// The type associated to this price entry if any /// public string Type { get; set; } /// /// True if the user is subscribed /// public bool? Subscribed { get; set; } /// /// The associated product id /// public int ProductId { get; set; } /// /// The associated data paths /// public HashSet Paths { get; set; } } }