コード例 #1
0
 public int GetTotalSellVolume()
 {
     if (SellOrders.Count <= 0)
     {
         return(0);
     }
     return(SellOrders.Select(order => order.Volume).Sum());
 }
コード例 #2
0
 public List <Order> CloneSellOrders()
 {
     return(SellOrders.Select(order => order.Clone()).ToList());
 }
コード例 #3
0
        public void UpdateWithExcel(List <Order> excelOrders, PositionInfo positionInfo, string symbol)
        {
            WriteToLogDB("UpdateWithExcel", "Started", symbol);
            // Updating CurrentState's Position
            if (!AvgPrice.Equals(positionInfo.AvgPrice))
            {
                WriteToLogDB("UpdateWithExcel", "Changing AvgPrice from " + AvgPrice + " to " + positionInfo.AvgPrice, symbol);
                AvgPrice = positionInfo.AvgPrice;
            }
            int sideCoeff = (positionInfo.Side == "Long" ? 1 : -1);

            /*if (Planned != (int)positionInfo.Planned * sideCoeff)
             * {
             *  WriteToLogDB("UpdateWithExcel", "Changing Planned from " + Planned + " to " + (int)positionInfo.Planned, symbol);
             *  //Planned = ((int)positionInfo.Planned) * sideCoeff;
             * } */
            int newPosition = ((int)positionInfo.Quantity) * sideCoeff;

            if (Position != newPosition)
            {
                WriteToLogDB("UpdateWithExcel", "Changing Position from " + Position + " to " + newPosition, symbol);
                Position = newPosition;
            }

            // Updating buy and sell orders

            List <int>    indexesToDeleteFromCurrentState = new List <int>();
            List <string> orderIds = BuyOrders.Select(order => order.OrderId).ToList();
            List <int>    cookies  = BuyOrders.Select(order => order.Cookie).ToList();

            orderIds.AddRange(SellOrders.Select(order => order.OrderId).ToList());
            cookies.AddRange(SellOrders.Select(order => order.Cookie).ToList());

            BuyOrders.Clear();
            BuyOrders = excelOrders.Where(order => order.Action == ActionEnum.BUY).ToList();
            SellOrders.Clear();
            SellOrders = excelOrders.Where(order => order.Action == ActionEnum.SELL).ToList();
            WriteToLogDB("UpdateWithExcel", "Buy and Sell orders from Current State Cleared. Updating from Excel", symbol);
            for (int i = 0; i < BuyOrders.Count; i++)
            {
                int index = orderIds.IndexOf(BuyOrders[i].OrderId);
                if (index >= 0)
                {
                    BuyOrders[i].Cookie = cookies[index];
                }
                else
                {
                    WriteToLogDB("UpdateWithExcel", BuyOrders[i].OrderId + " not found. Order added to CurrentState from Excel", symbol);
                }
            }
            for (int i = 0; i < SellOrders.Count; i++)
            {
                int index = orderIds.IndexOf(SellOrders[i].OrderId);
                if (index >= 0)
                {
                    SellOrders[i].Cookie = cookies[index];
                }
                else
                {
                    WriteToLogDB("UpdateWithExcel", SellOrders[i].OrderId + " not found. Order added to CurrentState from Excel", symbol);
                }
            }
            WriteToLogDB("UpdateWithExcel", "Finished", symbol);
        }