public bool CancelOrder(string orderId, string clientId)
 {
     logger.Debug($"PlaceOrder received: clientId = {clientId}, orderId = {orderId}");
     lock (syncRoot)
     {
         try
         {
             if (!LoggedIn(clientId))
             {
                 return(false);
             }
             if (orderIdToClientIdMap.TryGetValue(orderId, out string clientIdInMap) && clientIdInMap.Equals(clientId))
             {
                 var order = new LimitOrder();
                 order.SetOrderId(orderId);
                 Orderbook.RemoveOrderByOrderId(order);
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception ex)
         {
             logger.Error(ex);
             return(false);
         }
     }
 }
        public bool PlaceOrder(LimitOrder order, string clientId)
        {
            logger.Debug($"PlaceOrder received: clientId = {clientId}, order = {order}");
            lock (syncRoot)
            {
                try
                {
                    if (!LoggedIn(clientId))
                    {
                        return(false);
                    }
                    if (order.LimitPrice <= 0)
                    {
                        return(false);
                    }
                    if (order.Quantity <= 0)
                    {
                        return(false);
                    }

                    //No OrderId means this is a new order. OrderId should be assigned by OrderManager only.
                    if (string.IsNullOrEmpty(order.OrderId))
                    {
                        var newOrderId = orderIdProvider.GetNextOrderId();
                        if (orderIdToClientIdMap.TryAdd(newOrderId, clientId))
                        {
                            order.SetOrderId(newOrderId);
                            Orderbook.PlaceOrder(order);
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else //Update order
                    {
                        if (orderIdToClientIdMap.TryGetValue(order.OrderId, out string clientOrderId))
                        {
                            Orderbook.PlaceOrder(order);
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                    return(false);
                }
            }
        }