private static byte[] GetDataIn4BitFormat(TraderState state, QuotationCommand command, int?beginSequence = null, int?endSequence = null)
        {
            var    stringBuilder = new StringBuilder(CAPACITY);
            string seqenceStr    = string.Format("{0}{1}{2}", (beginSequence ?? command.Sequence), _SequenceSeparator, (endSequence ?? command.Sequence));

            stringBuilder.Append(seqenceStr);
            stringBuilder.Append(_StartSeparator);
            OverridedQuotation[] overridedQuotations = command.OverridedQs;
            if (overridedQuotations != null && overridedQuotations.Length > 0)
            {
                for (int i = 0; i < overridedQuotations.Length; i++)
                {
                    OverridedQuotation overridedQuotation = overridedQuotations[i];
                    if (!state.InstrumentsView.ContainsKey(overridedQuotation.InstrumentID))
                    {
                        continue;
                    }
                    if (overridedQuotation.QuotePolicyID != state.InstrumentsView[overridedQuotation.InstrumentID])
                    {
                        continue;
                    }
                    if (i != 0)
                    {
                        stringBuilder.Append(_OutterSeparator);
                    }
                    AppendQuotationParts(stringBuilder, overridedQuotation);
                }
            }
            stringBuilder.Append(_StartSeparator);
            return(Quotation4BitEncoder.Encode(stringBuilder.ToString()));
        }
Exemple #2
0
 private void Initialize(OverridedQuotation quotation)
 {
     this.Ask           = quotation.Ask;
     this.Bid           = quotation.Bid;
     this.DealerID      = quotation.DealerID;
     this.High          = quotation.High;
     this.InstrumentID  = quotation.InstrumentID;
     this.Low           = quotation.Low;
     this.Origin        = quotation.Origin;
     this.QuotePolicyID = quotation.QuotePolicyID;
     this.Timestamp     = quotation.Timestamp;
     this.TotalVolume   = quotation.TotalVolume;
     this.Volume        = quotation.Volume;
 }
 private static void AppendQuotationParts(StringBuilder stringBuilder, OverridedQuotation overridedQuotation)
 {
     string[] parts =
     {
         GuidMapping.Get(overridedQuotation.InstrumentID).ToString(), overridedQuotation.Ask, overridedQuotation.Bid,                                                     overridedQuotation.High,
         overridedQuotation.Low,                                      string.Empty,           ((long)(overridedQuotation.Timestamp - OrginTime).TotalSeconds).ToString(),
         overridedQuotation.Volume,                                   overridedQuotation.TotalVolume
     };
     for (int i = 0; i < parts.Length; i++)
     {
         stringBuilder.Append(parts[i]);
         if (i != parts.Length - 1)
         {
             stringBuilder.Append(_InnerSeparator);
         }
     }
 }
 public static Quotation4Bit TryAddQuotation(OverridedQuotation[] overridedQuotations, TraderState state, long sequence)
 {
     Quotation4Bit quotation;
     long filterSign = state.SignMapping;
     if (_Dict.TryGetValue(filterSign, out quotation))
     {
         return quotation;
     }
     quotation = Quotation4BitPool.Default.Pop();
     if (quotation == null)
     {
         quotation = new Quotation4Bit(overridedQuotations, state);
     }
     else
     {
        quotation.Initialize(overridedQuotations, state);
     }
     quotation.Sequence = sequence;
     if (_Dict.TryAdd(filterSign, quotation))
     {
         return quotation;
     }
     return quotation;
 }
        internal void Merge(Token token, OverridedQuotation overridedQuotation, OriginQuotation originQuotation)
        {
            if (this.High.IsEmpty || decimal.Parse(overridedQuotation.Bid) >= decimal.Parse(this.High.OverridedQuotation.Bid))
            {
                if (!this.High.IsEmpty && this.Low.IsEmpty)
                {
                    this.Low.OverridedQuotation = this.High.OverridedQuotation;
                    this.Low.OriginQuotation    = this.High.OriginQuotation;
                    this.Low.Token = this.High.Token;
                }

                this.High.OverridedQuotation = overridedQuotation;
                this.High.OriginQuotation    = originQuotation;
                this.High.Token = token;
                if (!this.Last.IsEmpty && overridedQuotation.Timestamp >= this.Last.OverridedQuotation.Timestamp)
                {
                    this.Last.Clear();
                }
            }
            else if (this.Low.IsEmpty || decimal.Parse(overridedQuotation.Bid) <= decimal.Parse(this.Low.OverridedQuotation.Bid))
            {
                this.Low.OverridedQuotation = overridedQuotation;
                this.Low.OriginQuotation    = originQuotation;
                this.Low.Token = token;
                if (!this.Last.IsEmpty && overridedQuotation.Timestamp >= this.Last.OverridedQuotation.Timestamp)
                {
                    this.Last.Clear();
                }
            }
            else if (this.Last.IsEmpty || overridedQuotation.Timestamp >= this.Last.OverridedQuotation.Timestamp)
            {
                this.Last.OverridedQuotation = overridedQuotation;
                this.Last.OriginQuotation    = originQuotation;
                this.Last.Token = token;
            }
        }
 private static void AppendQuotationParts(StringBuilder stringBuilder, OverridedQuotation overridedQuotation)
 {
     string[] parts = {
      GuidMapping.Get(overridedQuotation.InstrumentID).ToString(), overridedQuotation.Ask,overridedQuotation.Bid,overridedQuotation.High,
      overridedQuotation.Low,string.Empty,((long)(overridedQuotation.Timestamp - OrginTime).TotalSeconds).ToString(),
      overridedQuotation.Volume,overridedQuotation.TotalVolume };
     for (int i = 0; i < parts.Length; i++)
     {
         stringBuilder.Append(parts[i]);
         if (i != parts.Length - 1)
         {
             stringBuilder.Append(_InnerSeparator);
         }
     }
 }
 private Quotation4Bit(OverridedQuotation[] overridedQuotations,TraderState state)
 {
     this.OverridedQuotations = overridedQuotations;
     this.State = state;
     this.Price = null;
 }
 public void Initialize(OverridedQuotation[] overridedQuotations, TraderState state)
 {
     this.OverridedQuotations = overridedQuotations;
     this.State = state;
     this.Price = null;
 }
 internal void Broadcast(Common.Token token, OriginQuotation[] originQs, OverridedQuotation[] overridedQs)
 {
 }
Exemple #10
0
 public void Reset(OverridedQuotation quotation)
 {
     this.Initialize(quotation);
 }
Exemple #11
0
 public OverridedQ(OverridedQuotation quotation)
 {
     this.Initialize(quotation);
 }