示例#1
0
        public static bool ParseOpenPositions(cAlgo.API.Positions _positions, out Messaging.Protobuf.Positions positions, string openedPositionLabel = "")
        {
            try
            {
                int index = 0;
                positions = new Messaging.Protobuf.Positions();

                foreach (cAlgo.API.Position p in _positions)
                {
                    if (!ParseOpenPosition(p, out Messaging.Protobuf.Position position, Messaging.Protobuf.Position.Types.StateChange.None))
                    {
                        continue;
                    }

                    //Update StateChage if this is a newly opened position
                    if (position.Label == openedPositionLabel)
                    {
                        position.StateChange = Messaging.Protobuf.Position.Types.StateChange.Opened;
                    }

                    positions.Position[index] = position;
                    index++;
                }
                positions.Count = index;
            }
            catch (Exception e)
            {
                Console.WriteLine("FAILED to parse Positions: " + e.ToString());
                positions = null;
                return(false);
            }
            return(true);
        }
示例#2
0
        protected void PublishOnPositionOpened(cAlgo.API.Position _postion, cAlgo.API.Positions _positions)
        {
            //Create position

            //Create the positions object

            //Messaging.Protobuf.Positions positions = new Messaging.Protobuf.Positions()
            //{
            //    Count = _positions.Count,
            //    Position =
        }
示例#3
0
        public static void UpdatePositions(IAccount Account, cAlgo.API.Positions Positions)
        {
            // Check for any open Positions that are no longer open in cTrader...
            List <Model.Position> CurrentOpenPositions = Business.Positions.GetByAccountID(Account.Number, "Opened");

            foreach (Model.Position LocalPosition in CurrentOpenPositions)
            {
                bool ClosedExternally = true;
                foreach (cAlgo.API.Position AlgoP in Positions)
                {
                    if (LocalPosition.ID == AlgoP.Id)
                    {
                        ClosedExternally = false;
                    }
                }

                if (ClosedExternally)
                {
                    LocalPosition.Status = "Closed";
                    Business.Positions.Save(LocalPosition);
                    //AB: SEND TO SERVICE BUS to CLOSE Positions...
                }
            }



            // For each Open Position, update the SL/TP etc and add it if its not in the Database...
            foreach (cAlgo.API.Position AlgoP in Positions)
            {
                Model.Position LocalPosition = Business.Positions.GetByID(AlgoP.Id);

                // find any changes to syn out to shadows...
                //if (AlgoP.TakeProfit <> LocalPosition.TakeProfit | AlgoP.StopLoss  <> LocalPosition.StopLoss )

                //Update Postions...
                Update(Account, AlgoP, "Opened");
            }
        }
示例#4
0
 protected void PublishOnPositionClosed(cAlgo.API.Position _postion, cAlgo.API.Positions _positions)
 {
 }