public OriginQuotation(Instrument instrument, CollectorQuotation cq)
        {
            this.modifyState = ModifyState.Added;
            this.instrument = instrument;
            this.timestamp = cq.Timestamp;
            this.ask = Price.CreateInstance(cq.Ask, instrument.NumeratorUnit, instrument.Denominator);
            this.bid = Price.CreateInstance(cq.Bid, instrument.NumeratorUnit, instrument.Denominator);

            this.high = Price.CreateInstance(cq.High, instrument.NumeratorUnit, instrument.Denominator);
            this.low = Price.CreateInstance(cq.Low, instrument.NumeratorUnit, instrument.Denominator);

            this.volume = cq.Volume;
            this.totalVolume = cq.TotalVolume;

            this.origin = instrument.CalculateOrigin(this.ask, this.bid, instrument.OriginQReceived != null);

            //Special handle, it's not so strict
            //NOTE: Has problem for session clear !
            if (this.origin == null && instrument.OriginQReceived != null)
            {
                if (this.ask == null) this.ask = this.instrument.OriginQReceived.ask;
                if (this.bid == null) this.bid = this.instrument.OriginQReceived.bid;
                this.origin = instrument.CalculateOrigin(this.ask, this.bid, false);
            }

            this.FilterErrorHighLow(instrument, false);
        }
示例#2
0
        public CollectorQuotation ConvertQuotation(CollectorQuotation collectorQuotation1, CollectorQuotation collectorQuotation2)
        {
            if (collectorQuotation1 == null || collectorQuotation2 == null) return null;

            string bid = null, ask = null, high = null, low = null;

            switch (this.priceConvertFomulaType)
            {
                case PriceConvertFomulaType.Multiply:
                    bid = OriginInstrument.Multiply(collectorQuotation1.Bid, collectorQuotation2.Bid, this.priceConvertFactor);
                    ask = OriginInstrument.Multiply(collectorQuotation1.Ask, collectorQuotation2.Ask, this.priceConvertFactor);
                    high = OriginInstrument.Multiply(collectorQuotation1.High, collectorQuotation2.High, this.priceConvertFactor);
                    low = OriginInstrument.Multiply(collectorQuotation1.Low, collectorQuotation2.Low, this.priceConvertFactor);
                    break;
                case PriceConvertFomulaType.Divide:
                    bid = OriginInstrument.Divide(collectorQuotation1.Bid, collectorQuotation2.Ask, this.priceConvertFactor);
                    ask = OriginInstrument.Divide(collectorQuotation1.Ask, collectorQuotation2.Bid, this.priceConvertFactor);
                    high = OriginInstrument.Divide(collectorQuotation1.High, collectorQuotation2.Low, this.priceConvertFactor);
                    low = OriginInstrument.Divide(collectorQuotation1.Low, collectorQuotation2.High, this.priceConvertFactor);
                    break;
            }

            if (bid == null && ask == null && high == null && low == null)
            {
                return null;
            }
            else
            {
                DateTime timestamp = collectorQuotation1.Timestamp > collectorQuotation2.Timestamp ? collectorQuotation1.Timestamp : collectorQuotation2.Timestamp;
                return new CollectorQuotation(this.originCode, timestamp, ask, bid, high, low);
            }
        }
 public static CollectorQuotation CreateInstance(GeneralQuotation quotation)
 {
     CollectorQuotation cq = null;
     try
     {
         cq = new CollectorQuotation(quotation);
     }
     catch (Exception e)
     {
         AppDebug.LogEvent("CollectorQuotation", string.Format("CreateInstance'{0}',{1}", quotation, e.ToString()), EventLogEntryType.Error);
     }
     return cq;
 }