Beispiel #1
0
 private QuotationCommand Merge(ArrayList quotationCommands)
 {
     if (quotationCommands == null || quotationCommands.Count == 0)
     {
         return(null);
     }
     else if (quotationCommands.Count == 1)
     {
         return((QuotationCommand)quotationCommands[0]);
     }
     else
     {
         QuotationCommand lastQuotationCommand = (QuotationCommand)(quotationCommands[quotationCommands.Count - 1]);
         QuotationCommand mergingCommand       = new QuotationCommand(lastQuotationCommand.Sequence);
         mergingCommand.Merge(quotationCommands);
         return(mergingCommand);
     }
 }
Beispiel #2
0
        private void WriteForQuotation()
        {
            Token       token;
            TraderState state = SessionManager.Default.GetTokenAndState(this._Id, out token);

            if (state == null || token == null)
            {
                Write();
                return;
            }
            this._QuotationQueue.Clear();
            this._QuotationQueue.Add(this._CurrentCommand.Quotation.QuotationCommand);
            while (this._Queue.Count > 0)
            {
                CommandForClient item = this._Queue.Peek();
                if (item.CommandType != DataType.Quotation)
                {
                    break;
                }
                item = this._Queue.Dequeue();
                this._QuotationQueue.Add(item.Quotation.QuotationCommand);
            }
            byte[] content;
            if (this._QuotationQueue.Count == 1)
            {
                content = this._CurrentCommand.Quotation.GetPriceInBytes(token, state);
            }
            else
            {
                QuotationCommand command = new QuotationCommand();
                command.Merge(this._QuotationQueue);
                content = QuotationTranslator.GetPriceInBytes(token, state, command, this._QuotationQueue[0].Sequence, this._QuotationQueue[this._QuotationQueue.Count - 1].Sequence);
            }
            if (content == null)
            {
                Write();
                return;
            }
            this._CurrentPacket = SerializeManager.Default.SerializePrice(content);
            this.BeginWrite(this._CurrentPacket, 0, this._CurrentPacket.Length);
        }
Beispiel #3
0
 private void Process()
 {
     while (true)
     {
         if (this._IsStoped)
         {
             break;
         }
         if (this._IsSendPriceImmediately)
         {
             WaitHandle.WaitAny(this._Events);
             QuotationCommand quotation;
             while (this._Queue.TryDequeue(out quotation))
             {
                 CommandManager.Default.AddQuotation(quotation);
             }
         }
         else
         {
             Thread.Sleep(_ProcessPeriodMilliseconds);
             var qotation = new QuotationCommand();
             lock (this._Lock)
             {
                 if (this._QuotationQueue.Count == 0)
                 {
                     continue;
                 }
                 qotation.Merge(this._QuotationQueue);
                 this._QuotationQueue.Clear();
             }
             if (qotation.OverridedQs == null || qotation.OverridedQs.Length == 0)
             {
                 continue;
             }
             CommandManager.Default.AddQuotation(qotation);
         }
     }
 }
 private void Process()
 {
     while (true)
     {
         if (this._IsStoped)
         {
             break;
         }
         if (this._IsSendPriceImmediately)
         {
             WaitHandle.WaitAny(this._Events);
             QuotationCommand quotation;
             while (this._Queue.TryDequeue(out quotation))
             {
                 CommandManager.Default.AddQuotation(quotation);
             }
         }
         else
         {
             Thread.Sleep(_ProcessPeriodMilliseconds);
             var qotation = new QuotationCommand();
             lock (this._Lock)
             {
                 if (this._QuotationQueue.Count == 0)
                 {
                     continue;
                 }
                 qotation.Merge(this._QuotationQueue);
                 this._QuotationQueue.Clear();
             }
             if (qotation.OverridedQs == null || qotation.OverridedQs.Length == 0)
             {
                 continue;
             }
             CommandManager.Default.AddQuotation(qotation);
         }
     }
 }
 private QuotationCommand Merge(ArrayList quotationCommands)
 {
     if (quotationCommands == null || quotationCommands.Count == 0)
     {
         return null;
     }
     else if (quotationCommands.Count == 1)
     {
         return (QuotationCommand)quotationCommands[0];
     }
     else
     {
         QuotationCommand lastQuotationCommand = (QuotationCommand)(quotationCommands[quotationCommands.Count - 1]);
         QuotationCommand mergingCommand = new QuotationCommand(lastQuotationCommand.Sequence);
         mergingCommand.Merge(quotationCommands);
         return mergingCommand;
     }
 }
Beispiel #6
0
 private void WriteForQuotation()
 {
     Token token;
     TraderState state = SessionManager.Default.GetTokenAndState(this._Id, out token);
     if (state == null || token == null)
     {
         Write();
         return;
     }
     this._QuotationQueue.Clear();
     this._QuotationQueue.Add(this._CurrentCommand.Quotation.QuotationCommand);
     while (this._Queue.Count > 0)
     {
         CommandForClient item = this._Queue.Peek();
         if (item.CommandType != DataType.Quotation)
         {
             break;
         }
         item = this._Queue.Dequeue();
         this._QuotationQueue.Add(item.Quotation.QuotationCommand);
     }
     byte[] content;
     if (this._QuotationQueue.Count == 1)
     {
         content = this._CurrentCommand.Quotation.GetPriceInBytes(token, state);
     }
     else
     {
         QuotationCommand command = new QuotationCommand();
         command.Merge(this._QuotationQueue);
         content = QuotationTranslator.GetPriceInBytes(token, state, command, this._QuotationQueue[0].Sequence, this._QuotationQueue[this._QuotationQueue.Count - 1].Sequence);
     }
     if (content == null)
     {
         Write();
         return;
     }
     this._CurrentPacket = SerializeManager.Default.SerializePrice(content);
     this.BeginWrite(this._CurrentPacket, 0, this._CurrentPacket.Length);
 }