public void SetPrimitiveQuotation(PrimitiveQuotation quotation)
        {
            VmInstrument vmInstrument = this._Instruments.SingleOrDefault(i => i.Id == quotation.InstrumentId);

            if (vmInstrument != null)
            {
                VmInstrumentSourceRelation relation = vmInstrument.SourceRelations.SingleOrDefault(r => r.SourceId == quotation.SourceId);
                if (relation != null)
                {
                    if (relation.SetSourceQuotation(new VmSourceQuotation(quotation)))
                    {
                        for (int i = 0; i < vmInstrument.SourceRelations.Count; i++)
                        {
                            VmInstrumentSourceRelation relation2 = vmInstrument.SourceRelations[i];
                            if (!object.ReferenceEquals(relation2, relation))
                            {
                                relation2.SetSourceQuotation(new VmSourceQuotation(new PrimitiveQuotation()
                                {
                                    Timestamp = quotation.Timestamp
                                }));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public static bool EnsureIsKnownQuotation(this ConfigMetadata metaData, PrimitiveQuotation quotation, out bool inverted)
 {
     inverted = false;
     QuotationSource quotationSource;
     if (metaData.QuotationSources.TryGetValue(quotation.SourceName, out quotationSource))
     {
         quotation.SourceId = quotationSource.Id;
         Dictionary<string, InstrumentSourceRelation> relations;
         if (metaData.InstrumentSourceRelations.TryGetValue(quotationSource.Id, out relations))
         {
             InstrumentSourceRelation relation;
             if (relations.TryGetValue(quotation.Symbol, out relation))
             {
                 quotation.InstrumentId = relation.InstrumentId;
                 inverted = relation.Inverted;
                 return true;
             }
         }
     }
     return false;
 }
 public bool TryGetLastQuotation(int sourceId, int instrumentId, out PrimitiveQuotation primitiveQuotation)
 {
     primitiveQuotation = null;
     if (this._LastReceivedQuotations.ContainsKey(sourceId))
     {
         if (this._LastReceivedQuotations[sourceId].ContainsKey(instrumentId))
         {
             primitiveQuotation = this._LastReceivedQuotations[sourceId][instrumentId].PrimitiveQuotation;
         }
     }
     return primitiveQuotation != null;
 }
 public bool IsNotSame(PrimitiveQuotation quotation)
 {
     PrimitiveQuotation last;
     if (this.TryGetLastQuotation(quotation.SourceId, quotation.InstrumentId, out last))
     {
         return quotation.Timestamp != last.Timestamp || quotation.Bid != last.Bid || quotation.Ask != last.Ask || quotation.Last != last.Last || quotation.High != last.High || quotation.Low != last.Low;
     }
     return true;
 }
 public bool Fix(PrimitiveQuotation primitiveQuotation, out double ask, out double bid)
 {
     bool @fixed = false;
     bool fixAsk = !PrimitiveQuotation.TryGetPriceValue(primitiveQuotation.Ask, out ask);
     bool fixBid = !PrimitiveQuotation.TryGetPriceValue(primitiveQuotation.Bid, out bid);
     if (fixAsk || fixBid)
     {
         PrimitiveQuotation last;
         if (this.TryGetLastQuotation(primitiveQuotation.SourceId, primitiveQuotation.InstrumentId, out last))
         {
             if (fixAsk)
             {
                 primitiveQuotation.Ask = last.Ask;
                 ask = double.Parse(primitiveQuotation.Ask);
             }
             if (fixBid)
             {
                 primitiveQuotation.Bid = last.Bid;
                 bid = double.Parse(primitiveQuotation.Bid);
             }
             @fixed = true;
         }
     }
     return !fixAsk && !fixBid || @fixed;
 }
 public void SetPrimitiveQuotation(PrimitiveQuotation quotation)
 {
     VmInstrument vmInstrument  = this._Instruments.SingleOrDefault(i => i.Id == quotation.InstrumentId);
     if (vmInstrument != null)
     {
         VmInstrumentSourceRelation relation = vmInstrument.SourceRelations.SingleOrDefault(r => r.SourceId == quotation.SourceId);
         if (relation != null)
         {
             if (relation.SetSourceQuotation(new VmSourceQuotation(quotation)))
             {
                 for (int i = 0; i < vmInstrument.SourceRelations.Count; i++)
                 {
                     VmInstrumentSourceRelation relation2 = vmInstrument.SourceRelations[i];
                     if (!object.ReferenceEquals(relation2, relation))
                     {
                         relation2.SetSourceQuotation(new VmSourceQuotation(new PrimitiveQuotation() { Timestamp = quotation.Timestamp }));
                     }
                 }
             }
         }
     }
 }