internal static void Log(MessageType type, string message) { const string logSource = "YahooDataSource"; if (IsLoggable(type)) { switch (type) { case MessageType.Error: DataSourceBase.DotNetLog(logSource, "Error", message); break; case MessageType.Warning: DataSourceBase.DotNetLog(logSource, "Warning", message); break; case MessageType.Info: DataSourceBase.DotNetLog(logSource, "Info", message); break; case MessageType.Trace: DataSourceBase.DotNetLog(logSource, "Trace", message); break; } } }
/// <summary> /// Get and build historical data for a ticker /// </summary> /// <param name="tickerData"></param> /// <remarks> /// Place short term resource allocation (e.g. local DB connection setup, etc.) here. /// Load and populate all quotation data to tickerData.Quotes using the Merge method. /// See .NET for AmiBroker's Help on QuotationList class. /// </remarks> public override void Ticker_GetQuotes(TickerData tickerData) { // get the path to data file directory string dataDirectory = AppDomain.CurrentDomain.BaseDirectory; dataDirectory = Directory.GetParent(dataDirectory).FullName; // ...\AmiBroker\.NET for AmiBroker dataDirectory = Path.Combine(dataDirectory, @"Samples\Ascii"); // ...\AmiBroker\.NET for AmiBroker\Samples\Ascii // get the data file path to load for the ticker // --- replace it with your custom logic to build data file path using the ticker's name // --- E.g.: // --- string dataFilePath = Path.Combine(dataDirectory, tickerData.Ticker + ".csv"); string dataFilePath = Path.Combine(dataDirectory, "demodata_hist.csv"); try { // open data file of the ticker for reading using (FileStream fileStream = File.Open(dataFilePath, FileMode.Open, FileAccess.Read)) { using (StreamReader streamReader = new StreamReader(fileStream)) { // skip the first line (header row) // --- remove next line if your data files have no header row --- streamReader.ReadLine(); // clear previously stored quotes in the plugin tickerData.Quotes.Clear(); // read until the end of the file while (!streamReader.EndOfStream) { // read a line (quotation record) from the file string line = streamReader.ReadLine(); // convert the line to quotation object Quotation quote = GetQuote(line); // Merge method builds bars according to database's timebase tickerData.Quotes.Merge(quote); } } } } catch (Exception ex) { pluginStatus.Status = StatusCode.SevereError; pluginStatus.Color = System.Drawing.Color.Red; pluginStatus.ShortMessage = "Error"; pluginStatus.LongMessage = ex.ToString(); DataSourceBase.DotNetLog("Sample - Csv/text file", "Error", ex.ToString()); } }
internal static void LogMessage(MessageType type, string message) { switch (type) { case MessageType.Error: DataSourceBase.DotNetLog(logSource, "Error", message); break; case MessageType.Warning: DataSourceBase.DotNetLog(logSource, "Warning", message); break; case MessageType.Info: DataSourceBase.DotNetLog(logSource, "Info", message); break; case MessageType.Trace: DataSourceBase.DotNetLog(logSource, "Trace", message); break; } }