Beispiel #1
0
		internal bool Enqueue()
		{
			if (!this.queue.IsFull())
			{
				this.queue.Write(this.obj);
				this.current += 1L;
				if (this.current <= this.index2)
				{
					this.obj = this.series[this.current];
				}
				else
				{
					this.obj = null;
				}
				this.count += 1L;
				if (this.count == (long)this.progressCount)
				{
					this.progressCount += this.progressDelta;
					this.progressPercent++;
					this.queue.Enqueue(new OnSimulatorProgress((long)this.progressCount, this.progressPercent));
				}
				return true;
			}
			return false;
		}
Beispiel #2
0
		protected internal virtual void OnData(DataObject obj)
		{
			Tick tick = (Tick)obj;
			if (this.bar == null)
			{
				this.bar = new Bar();
				this.bar.instrumentId = tick.instrumentId;
				this.bar.type = this.barType;
				this.bar.size = this.barSize;
				this.bar.openDateTime = this.GetBarOpenDateTime(obj);
				this.bar.dateTime = this.GetBarCloseDateTime(obj);
				this.bar.open = tick.price;
				this.bar.high = tick.price;
				this.bar.low = tick.price;
				this.bar.close = tick.price;
				this.bar.volume = (long)tick.size;
			}
			else
			{
				if (tick.price > this.bar.high)
				{
					this.bar.high = tick.price;
				}
				if (tick.price < this.bar.low)
				{
					this.bar.low = tick.price;
				}
				this.bar.close = tick.price;
				this.bar.volume += (long)tick.size;
			}
			this.bar.n += 1L;
		}
Beispiel #3
0
		internal DataSeriesObject(DataSeries series, DateTime dateTime1, DateTime dateTime2, IEventQueue queue)
		{
			this.series = series;
			this.queue = queue;
			if (dateTime1 == DateTime.MinValue || dateTime1 < series.DateTime1)
			{
				this.index1 = 0L;
			}
			else
			{
				this.index1 = series.GetIndex(dateTime1, SearchOption.Next);
			}
			if (dateTime2 == DateTime.MaxValue || dateTime2 > series.DateTime2)
			{
				this.index2 = series.count - 1L;
			}
			else
			{
				this.index2 = series.GetIndex(dateTime2, SearchOption.Prev);
			}
			this.current = this.index1;
			this.obj = series[this.current];
			this.progressDelta = (int)Math.Ceiling((double)this.Count / 100.0);
			this.progressCount = this.progressDelta;
			this.progressPercent = 0;
		}
Beispiel #4
0
 protected internal override void OnData(DataObject obj)
 {
     bool flag = this.bar == null;
     base.OnData(obj);
     if (flag)
     {
         base.AddReminder(this.bar.dateTime);
     }
 }
Beispiel #5
0
 protected internal override void OnData(DataObject obj)
 {
     base.OnData(obj);
     this.bar.dateTime = this.GetBarCloseDateTime(obj);
     if (this.bar.n == this.barSize)
     {
         base.EmitBar();
     }
 }
Beispiel #6
0
 protected override void OnInit(SmartQuant.DataObject dataObject, int decimalPlaces)
 {
     if (dataObject != null)
     {
         Quote quote = (Quote)dataObject;
         this.nudBid.Value     = (Decimal)quote.Bid.Price;
         this.nudBidSize.Value = (Decimal)quote.Bid.Size;
         this.nudAsk.Value     = (Decimal)quote.Ask.Price;
         this.nudAskSize.Value = (Decimal)quote.Ask.Size;
     }
     this.nudBid.DecimalPlaces = decimalPlaces;
     this.nudAsk.DecimalPlaces = decimalPlaces;
 }
Beispiel #7
0
 protected override void OnInit(SmartQuant.DataObject dataObject, int decimalPlaces)
 {
     if (dataObject != null)
     {
         Tick tick = (Tick)dataObject;
         this.nudProvider.Value = (Decimal)tick.ProviderId;
         this.nudPrice.Value    = (Decimal)tick.Price;
         this.nudSize.Value     = (Decimal)tick.Size;
         if ((int)this.tickTypeId == 4)
         {
             this.nudDirection.Value = (Decimal)((Trade)tick).Direction;
         }
     }
     this.nudPrice.DecimalPlaces = decimalPlaces;
 }
Beispiel #8
0
		internal void OnData(DataObject obj)
		{
			if (obj.TypeId != 4)
			{
				return;
			}
			List<BarFactoryItem> list = this.itemLists[((Tick)obj).instrumentId];
			if (list != null)
			{
				foreach (BarFactoryItem current in list)
				{
					current.OnData(obj);
				}
			}
		}
Beispiel #9
0
		public void AddObject(DataObject obj)
		{
			if (this.count == this.size)
			{
				Console.WriteLine("DataKey::Add Can not add object. Buffer is full.");
				return;
			}
			if (this.objects == null)
			{
				this.objects = new DataObject[this.size];
			}
			if (this.count == 0)
			{
				this.objects[this.count++] = obj;
				this.dateTime1 = obj.dateTime;
				this.dateTime2 = obj.dateTime;
			}
			else
			{
				if (obj.dateTime >= this.objects[this.count - 1].dateTime)
				{
					this.objects[this.count++] = obj;
					this.dateTime2 = obj.dateTime;
				}
				else
				{
					int num = this.count;
					while (true)
					{
						this.objects[num] = this.objects[num - 1];
						if (obj.dateTime >= this.objects[num].dateTime || num == 1)
						{
							break;
						}
						num--;
					}
					this.objects[num - 1] = obj;
					if (num == 1)
					{
						this.dateTime1 = obj.dateTime;
					}
					this.count++;
				}
			}
			this.index2 += 1L;
			this.changed = true;
		}
        internal bool Enqueue()
        {
            if (eventQueue.IsFull())
            {
                return false;
            }
            DataObject data = null;
            while (dataQueue.IsEmpty())
            {
                if (obj != null)
                {
                    data = obj;
                    obj = null;
                    break;
                }
                if (current > index2)
                {
                    endOfSeries = true;
                    return false;
                }
                obj = series[current];

                //-----------------------
                // DataProcessor其实只是Bar处理,由于读到的行情全是Tick,所以这部分可忽视
                //obj = processor.OnData(this);
                // 这地方居然会导致OnTrade两次
                //Emit(obj);
                //-----------------------

                current += 1L;
                count += 1L;
            }
            if (data == null)
                data = (DataObject)dataQueue.Read();
            eventQueue.Write(data);
            if (count == progressCount)
            {
                progressCount += progressDelta;
                progressPercent++;
                eventQueue.Enqueue(new OnSimulatorProgress(progressCount, progressPercent));
            }
            return true;
        }
Beispiel #11
0
 protected override void OnInit(SmartQuant.DataObject dataObject, int decimalPlaces)
 {
     if (dataObject != null)
     {
         Bar bar = (Bar)dataObject;
         this.dtpDateTime.Value   = bar.OpenDateTime;
         this.dtpEnd.Value        = bar.CloseDateTime;
         this.nudOpen.Value       = (Decimal)bar.Open;
         this.nudHigh.Value       = (Decimal)bar.High;
         this.nudLow.Value        = (Decimal)bar.Low;
         this.nudClose.Value      = (Decimal)bar.Close;
         this.nudVolume.Value     = (Decimal)bar.Volume;
         this.nudOpenInt.Value    = (Decimal)bar.OpenInt;
         this.dtpDateTime.Enabled = false;
         this.dtpEnd.Enabled      = false;
     }
     else
     {
         DateTime now = DateTime.Now;
         this.dtpDateTime.Value   = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
         this.dtpDateTime.Enabled = true;
         if (this.barType == BarType.Time)
         {
             this.dtpEnd.Value   = this.dtpDateTime.Value.AddSeconds((double)this.barSize);
             this.dtpEnd.Enabled = false;
         }
         else
         {
             this.dtpEnd.Value   = this.dtpDateTime.Value;
             this.dtpEnd.Enabled = true;
         }
     }
     this.tbxBarType.Text        = string.Format("{0} {1}", (object)this.barType, (object)this.barSize);
     this.nudOpen.DecimalPlaces  = decimalPlaces;
     this.nudHigh.DecimalPlaces  = decimalPlaces;
     this.nudLow.DecimalPlaces   = decimalPlaces;
     this.nudClose.DecimalPlaces = decimalPlaces;
 }
Beispiel #12
0
		public virtual void Save(Instrument instrument, DataObject obj)
		{
		}
Beispiel #13
0
 public void Log(DataObject data, Group group)
 {
     this.strategy.Log(data, group);
 }
Beispiel #14
0
 public void Respond(DataObject data, int commandId)
 {
 }
Beispiel #15
0
		public void UpdateObject(int index, DataObject obj)
		{
			this.objects[index] = obj;
			this.changed = true;
		}
Beispiel #16
0
		public void Add(DataObject obj)
		{
			if (obj.dateTime.Ticks == 0L)
			{
				Console.WriteLine("DataSeries::Add Error: can not add object with DateTime = 0");
				return;
			}
			if (!this.isOpenWrite)
			{
				this.OpenWrite();
			}
			this.count += 1L;
			if (this.count == 1L)
			{
				this.dateTime1 = obj.dateTime;
				this.dateTime2 = obj.dateTime;
			}
			else
			{
				if (obj.dateTime < this.dateTime2)
				{
					this.Insert(obj);
					return;
				}
				this.dateTime2 = obj.DateTime;
			}
			this.writeKey.AddObject(obj);
			if (this.writeKey.count == this.writeKey.size)
			{
				this.WriteKey(this.writeKey);
				if (!this.cacheObjects && this.writeKey != this.readKey && this.writeKey != this.insertKey && this.writeKey != this.deleteKey)
				{
					this.writeKey.objects = null;
				}
				this.writeKey = new DataKey(this.file, null, this.writeKey.position, -1L);
				this.writeKey.number = this.buffer_count;
				this.writeKey.index1 = this.count;
				this.writeKey.index2 = this.count;
				this.writeKey.changed = true;
				this.buffer_count++;
				this.cache[this.writeKey.number] = this.writeKey;
			}
			else
			{
				this.changed = true;
			}
			this.file.isModified = true;
		}
Beispiel #17
0
 public void Log(DataObject data, Group group)
 {
     this.framework.eventServer.OnLog(new GroupEvent(data, group));
 }
Beispiel #18
0
 protected override DateTime GetBarOpenDateTime(DataObject obj)
 {
     long num = (long)obj.dateTime.TimeOfDay.TotalSeconds / this.barSize * this.barSize;
     return obj.dateTime.Date.AddSeconds((double)num);
 }
Beispiel #19
0
 protected override DateTime GetBarCloseDateTime(DataObject obj)
 {
     return(this.GetBarOpenDateTime(obj).AddSeconds((double)this.barSize));
 }
Beispiel #20
0
 public void Add(DataObject obj)
 {
     throw new NotImplementedException();
 }
Beispiel #21
0
 protected override DateTime GetBarCloseDateTime(DataObject obj)
 {
     return this.GetBarOpenDateTime(obj).AddSeconds((double)this.barSize);
 }
Beispiel #22
0
 public void OnData(DataObject data)
 {
     this.OnEvent(data);
 }
Beispiel #23
0
		protected virtual DateTime GetBarCloseDateTime(DataObject obj)
		{
			return obj.dateTime;
		}
 protected virtual DataObject OnData(DataObject obj)
 {
     throw new NotImplementedException();
 }
Beispiel #25
0
 public void Log(DataObject data, int groupId)
 {
     this.strategy.Log(data, groupId);
 }
Beispiel #26
0
 protected virtual DataObject OnData(DataObject obj)
 {
     throw new NotImplementedException();
 }
Beispiel #27
0
        protected override DateTime GetBarOpenDateTime(DataObject obj)
        {
            long num = (long)obj.dateTime.TimeOfDay.TotalSeconds / this.barSize * this.barSize;

            return(obj.dateTime.Date.AddSeconds((double)num));
        }
Beispiel #28
0
 protected void Emit(DataObject obj)
 {
     throw new NotImplementedException();
 }
Beispiel #29
0
		public void Update(long index, DataObject obj)
		{
			DataObject dataObject = this.Get(index);
			if (dataObject.dateTime != obj.dateTime)
			{
				Console.WriteLine("DataSeries::Update Can not update object with different datetime");
				return;
			}
			bool flag = this.readKey.changed;
			this.readKey.UpdateObject((int)(index - this.readKey.index1), obj);
			if (!flag)
			{
				this.WriteKey(this.readKey);
			}
			this.file.isModified = true;
		}
 protected void Emit(DataObject obj)
 {
     if (!this.dataQueue.IsFull())
     {
         this.dataQueue.Write(obj);
     }
     else
     {
         Console.WriteLine("DataProcessor::Emit Can not write data object. Data queue is full. Data queue size = " + this.dataQueue.Size);
     }
 }
Beispiel #31
0
		private void Insert(DataObject obj)
		{
			if (obj.dateTime >= this.writeKey.dateTime1 && obj.dateTime <= this.writeKey.dateTime2)
			{
				this.writeKey.AddObject(obj);
				if (this.writeKey.count == this.writeKey.size)
				{
					this.WriteKey(this.writeKey);
					this.writeKey = new DataKey(this.file, null, this.writeKey.position, -1L);
					this.writeKey.number = this.buffer_count;
					this.writeKey.index1 = this.count;
					this.writeKey.index2 = this.count;
					this.writeKey.changed = true;
					this.buffer_count++;
					this.cache[this.writeKey.number] = this.writeKey;
				}
				else
				{
					this.changed = true;
				}
				this.file.isModified = true;
				return;
			}
			DataKey dataKey = this.GetKey(obj.dateTime, this.insertKey);
			if (this.insertKey == null)
			{
				this.insertKey = dataKey;
			}
			else
			{
				if (this.insertKey != dataKey)
				{
					if (this.insertKey.changed)
					{
						this.WriteKey(this.insertKey);
					}
					if (!this.cacheObjects && this.insertKey != this.readKey && this.insertKey != this.writeKey && this.insertKey != this.deleteKey)
					{
						this.insertKey.objects = null;
					}
					this.insertKey = dataKey;
				}
			}
			this.insertKey.GetObjects();
			if (this.insertKey.count < this.insertKey.size)
			{
				this.insertKey.AddObject(obj);
				if (this.insertKey.count == this.insertKey.size)
				{
					this.WriteKey(this.insertKey);
				}
			}
			else
			{
				dataKey = new DataKey(this.file, null, -1L, -1L);
				int index = this.insertKey.GetIndex(obj.dateTime, SearchOption.Next);
				for (int i = index; i < this.insertKey.count; i++)
				{
					dataKey.AddObject(this.insertKey.objects[i]);
					this.insertKey.objects[i] = null;
				}
				this.insertKey.count = index;
				this.insertKey.index2 = this.insertKey.index1 + (long)this.insertKey.count - 1L;
				if (this.insertKey.count != 0)
				{
					this.insertKey.dateTime2 = this.insertKey.objects[this.insertKey.count - 1].dateTime;
				}
				this.insertKey.AddObject(obj);
				this.InsertKey(dataKey, this.insertKey);
			}
			if (this.readKey != null && this.readKey.number > this.insertKey.number)
			{
				this.readKey.index1 += 1L;
				this.readKey.index2 += 1L;
			}
			if (this.writeKey != null && this.writeKey.number > this.insertKey.number)
			{
				this.writeKey.index1 += 1L;
				this.writeKey.index2 += 1L;
			}
			if (this.deleteKey != null && this.deleteKey.number > this.insertKey.number)
			{
				this.deleteKey.index1 += 1L;
				this.deleteKey.index2 += 1L;
			}
			this.insertKey.changed = true;
			this.changed = true;
			this.file.isModified = true;
		}
Beispiel #32
0
 public void Update(long index, DataObject obj)
 {
     throw new NotImplementedException();
 }
Beispiel #33
0
 public void Log(DataObject data, int groupId)
 {
     this.framework.eventServer.OnLog(new GroupEvent(data, this.framework.groupManager.Groups[groupId]));
 }
Beispiel #34
0
		public virtual DataObject Filter(DataObject obj)
		{
			return obj;
		}
Beispiel #35
0
 public void Respond(DataObject data)
 {
     this.Respond(data, -1);
 }
Beispiel #36
0
 public void Save(Instrument instrument, DataObject obj)
 {
     this.server.Save(instrument, obj);
 }
Beispiel #37
0
 protected internal void EmitData(DataObject data)
 {
     this.dataQueue.Enqueue(data);
 }
 protected void Emit(DataObject obj)
 {
     throw new NotImplementedException();
 }
Beispiel #39
0
		public void OnData(DataObject data)
		{
			this.OnEvent(data);
		}
Beispiel #40
0
		public void Save(Instrument instrument, DataObject obj)
		{
			this.server.Save(instrument, obj);
		}
Beispiel #41
0
		public void Save(int instrumentId, DataObject obj)
		{
			Instrument byId = this.framework.InstrumentManager.GetById(instrumentId);
			this.server.Save(byId, obj);
		}
Beispiel #42
0
        public void Save(int instrumentId, DataObject obj)
        {
            Instrument byId = this.framework.InstrumentManager.GetById(instrumentId);

            this.server.Save(byId, obj);
        }
Beispiel #43
0
 public DataObject(DataObject obj)
 {
     this.dateTime = obj.dateTime;
 }
Beispiel #44
0
 public virtual DataObject Filter(DataObject obj)
 {
     return(obj);
 }