Esempio n. 1
0
 public void StartProcessing()
 {
     try
     {
         using (StreamReader sr = new StreamReader(this._inputFilePath))
         {
             string line;
             while ((line = sr.ReadLine()) != null)
             {
                 string[]     values = line.Split(',');
                 RawTradeData data   = new RawTradeData
                 {
                     TimeStamp = Convert.ToUInt64(values[0]),
                     Symbol    = values[1],
                     Quantity  = Convert.ToUInt32(values[2]),
                     Price     = Convert.ToUInt32(values[3])
                 };
                 ProcessRawTradeData(data);
             }
         }
     }
     catch
     {
         // log exceptions
         throw;
     }
 }
Esempio n. 2
0
 public void ProcessRawTradeData(RawTradeData raw)
 {
     if (this._summary.Any(d => d.Symbol == raw.Symbol))
     {
         this.AddDataToExistingSymbol(raw);
     }
     else
     {
         this.AddNewSymbol(raw);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// add new symbol.
 /// </summary>
 /// <param name="raw">
 /// The raw trade data
 /// </param>
 private void AddNewSymbol(RawTradeData raw)
 {
     this._summary.Add(new TradeSummary
     {
         Symbol        = raw.Symbol,
         MaxPrice      = raw.Price,
         LastTimeStamp = raw.TimeStamp,
         MaxTimeGap    = 0,
         Volume        = raw.Quantity,
         TotalAmount   = raw.Price * raw.Quantity
     });
 }
Esempio n. 4
0
        /// <summary>
        /// add data to existing symbol.
        /// </summary>
        /// <param name="raw">
        /// The raw trade data
        /// </param>
        private void AddDataToExistingSymbol(RawTradeData raw)
        {
            TradeSummary updateSummary = this._summary.FirstOrDefault(x => x.Symbol == raw.Symbol);

            updateSummary.MaxTimeGap = raw.TimeStamp - updateSummary.LastTimeStamp > updateSummary.MaxTimeGap
                                           ? raw.TimeStamp - updateSummary.LastTimeStamp
                                           : updateSummary.MaxTimeGap;
            updateSummary.LastTimeStamp = raw.TimeStamp;
            updateSummary.MaxPrice      = raw.Price > updateSummary.MaxPrice ? raw.Price : updateSummary.MaxPrice;
            updateSummary.TotalAmount   = updateSummary.TotalAmount + raw.Price * raw.Quantity;
            updateSummary.Volume        = updateSummary.Volume + raw.Quantity;
        }