예제 #1
0
파일: Core.cs 프로젝트: zilveer/Exchange-7
        private async Task InboundMessageProcessor()
        {
            try
            {
                while (await _inboundChannelReader.WaitToReadAsync())
                {
                    while (_inboundChannelReader.TryRead(out Message message))
                    {
                        try
                        {
                            switch (message.MessageType)
                            {
                            case MessageType.NewOrderRequest:
                                _matchingEngine.AddOrder((OrderWrapper)message.Object);
                                break;

                            case MessageType.CancelRequest:
                                _matchingEngine.CancelOrder(((CancelRequest)message.Object).OrderId);
                                break;

                            case MessageType.BookRequest:
                                var bytes = BookSerializer.Serialize(_matchingEngine.Book, ((BookRequest)message.Object).LevelCount, _matchingEngine.MarketPrice, _timeProvider.GetSecondsFromEpoch());
                                _outboundChannelWritter.TryWrite(bytes);
                                //TODO
                                break;

                            default:
                                //TODO
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            //TODO
                            throw;
                        }
                    }
                }
                _outboundChannelWritter.Complete();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                //TODO
                throw;
            }
        }
예제 #2
0
    static void Main(String[] args)
    {
        /* Enter your code here. Read input using Console.ReadLine. Print output using Console.WriteLine. Your class should be named Solution */
        var engine = new MatchingEngine();

        /*var argsList = new List<string>();
         *
         * while (true)
         * {
         * var arg = Console.ReadLine();
         *
         * if (arg == null)
         *    break;
         *
         * argsList.Add(arg);
         * }*/

        foreach (var str in args)
        {
            var order = ProcessInputLine(str);

            if (order == null)
            {
                engine.PrintStatus();
            }
            else if (order.TradeStatus == TradeStatus.Active)
            {
                engine.AddOrder(order);
                engine.Trade();
            }
            else if (order.TradeStatus == TradeStatus.Modify)
            {
                engine.ModifyOrder(order);
                engine.Trade();
            }
            else if (order.TradeStatus == TradeStatus.Cancelled)
            {
                engine.CancelOrder(order);
            }
            else if (order.OperationType == OperationType.None)
            {
                continue;
            }
        }
    }