예제 #1
0
 /// <summary>
 /// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object
 /// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
 /// </summary>
 /// <param name="config">Subscription data config setup object</param>
 /// <param name="line">Line of the source document</param>
 /// <param name="date">Date of the requested data</param>
 /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
 /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
 public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
 {
     try
     {
         // create a new StockDataSource and set the symbol using config.Symbol
         var stocks = new StockDataSource {
             Symbol = config.Symbol
         };
         // break our line into csv pieces
         var csv = line.ToCsv();
         if (isLiveMode)
         {
             // our live mode format does not have a date in the first column, so use date parameter
             stocks.Time = date;
             stocks.Symbols.AddRange(csv);
         }
         else
         {
             // our backtest mode format has the first column as date, parse it
             stocks.Time = DateTime.ParseExact(csv[0], "yyyyMMdd", null);
             // any following comma separated values are symbols, save them off
             stocks.Symbols.AddRange(csv.Skip(1));
         }
         return(stocks);
     }
     // return null if we encounter any errors
     catch { return(null); }
 }
        /// <summary>
        /// Adds a new processing target
        /// </summary>
        /// <param name="target">The target point to add</param>
        public void Add(ProcessingTarget target)
        {
            Targets.Add(target);

            // If live, set up a subscription
            if (Live && !LiveData.ContainsKey(target.Symbol))
            {
                var sourceList = new StockDataSet <StockDataSource>(target.Symbol, DateTime.Now, Session.SourceFile);
                var data       = new StockDataSetDerived <StockDataSink, StockDataSource, StockProcessingState>(sourceList, Session.SinkFile, CreateSink, GetProcessingState);
                var sub        = DataAccessor.Subscribe(target.Symbol, LiveInterval);
                sub.Notify += (DataAccessor.Subscription s) =>
                {
                    LiveData[s.Symbol].Item1.Add(StockDataSource.CreateFromPrice((float)s.Price));
                    LiveProcessingQueue.Add(target);
                };

                LiveData[target.Symbol] = new Tuple <StockDataSetDerived <StockDataSink, StockDataSource, StockProcessingState>, DataAccessor.Subscription>(data, sub);
            }
        }
 /// <summary>
 /// Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object 
 /// each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.
 /// </summary>
 /// <param name="config">Subscription data config setup object</param>
 /// <param name="line">Line of the source document</param>
 /// <param name="date">Date of the requested data</param>
 /// <param name="isLiveMode">true if we're in live mode, false for backtesting mode</param>
 /// <returns>Instance of the T:BaseData object generated by this line of the CSV</returns>
 public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
 {
     try
     {
         // create a new StockDataSource and set the symbol using config.Symbol
         var stocks = new StockDataSource {Symbol = config.Symbol};
         // break our line into csv pieces
         var csv = line.ToCsv();
         if (isLiveMode)
         {
             // our live mode format does not have a date in the first column, so use date parameter
             stocks.Time = date;
             stocks.Symbols.AddRange(csv);
         }
         else
         {
             // our backtest mode format has the first column as date, parse it
             stocks.Time = DateTime.ParseExact(csv[0], "yyyyMMdd", null);
             // any following comma separated values are symbols, save them off
             stocks.Symbols.AddRange(csv.Skip(1));
         }
         return stocks;
     }
     // return null if we encounter any errors
     catch { return null; }
 }