Ejemplo n.º 1
0
 public enumStatus UpdatePosition(Position pos)
 {
     try
     {
         lock (syncRoot)
         {
             if (!Positions.ContainsKey(pos.UserId))
             {
                 ServerLog.LogError("Error, can't locate the User in the positions table: {0}", pos.ToString());
                 return(enumStatus.Successful);
             }
             int index = Positions[pos.UserId].IndexOf(Positions[pos.UserId].Where(p => p.Symbol.Equals(pos.Symbol)).FirstOrDefault());
             if (pos.Quantity > 0)
             {
                 Positions[pos.UserId][index] = pos;
             }
             if (pos.Quantity == 0)
             {
                 Positions[pos.UserId].RemoveAt(index);
             }
             if (pos.Quantity < 0)
             {
                 ServerLog.LogError("Error, the position can't be negative: {0}", pos.ToString());
                 return(enumStatus.Error);
             }
         }
         return(enumStatus.Successful);
     }
     catch (Exception ex)
     {
         ServerLog.LogException(ex, string.Format("Update Position: {0}", pos.ToString()));
         return(enumStatus.BalanceAdjustFailed);
     }
 }
Ejemplo n.º 2
0
        public enumStatus UpdateOrder(Order order)
        {
            string jsonDoc = order.ToString();

            try
            {
                lock (syncRoot)
                {
                    if (!Orders.ContainsKey(order.Id))
                    {
                        ServerLog.LogError("Update Order, invalid Order Id: {0}", order.Id);
                        return(enumStatus.Error);
                    }
                    if (!Users.ContainsKey(order.UserID) || !OrderTable.ContainsKey(order.UserID))
                    {
                        ServerLog.LogError("Update Order, invalid User Id {0} in the order: {1}", order.UserID, order);
                        return(enumStatus.Error);
                    }
                    int i = OrderTable[order.UserID].Select(a => a.Id).ToList().IndexOf(order.Id);
                    if (i >= 0)
                    {
                        OrderTable[order.UserID][i] = order;
                    }
                    Orders[order.Id] = jsonDoc;
                }
                return(enumStatus.Successful);
            }
            catch (Exception ex)
            {
                ServerLog.LogException(ex, string.Format("Update Order: {0}", order.ToString()));
                return(enumStatus.Error);
            }
        }