Exemplo n.º 1
0
 public static bool ParseOpenPosition(cAlgo.API.Position p, out Messaging.Protobuf.Position position, Messaging.Protobuf.Position.Types.StateChange stateChange = Messaging.Protobuf.Position.Types.StateChange.None)
 {
     try
     {
         position = new Messaging.Protobuf.Position()
         {
             Id              = p.Id,
             Label           = p.Label,
             Pips            = p.Pips,
             EntryTime       = p.EntryTime.ToBinary(),
             SymbolCode      = p.SymbolCode,
             StopLossPrice   = (double)p.StopLoss,
             TakeProfitPrice = (double)p.TakeProfit,
             Volume          = p.Volume,
             TradeType       = ParsePositionTradeType(p.TradeType),
             GrossProfit     = p.GrossProfit,
             StateChange     = stateChange
         };
     }
     catch (Exception e)
     {
         Console.WriteLine("FAILED to parse Position: " + e.ToString());
         position = null;
         return(false);
     }
     return(true);
 }
Exemplo n.º 2
0
 public static bool ParseClosedPosition(cAlgo.API.Position _position, double closePrice, DateTime closeTime, out Messaging.Protobuf.Position position)
 {
     if (ParseOpenPosition(_position, out position, Messaging.Protobuf.Position.Types.StateChange.Closed))
     {
         position.ClosePrice = closePrice;
         position.CloseTime  = closeTime.ToBinary();
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
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 =
        }
Exemplo n.º 4
0
        /// <summary>Return the take profit as a signed price value relative to the entry price. 0 means no take profit</summary>
        public static double TakeProfitRel(this  cAlgo.API.Position pos)
        {
            switch (pos.TradeType)
            {
            default: throw new Exception("unknown trade type");

            case TradeType.Buy:  return((pos.TakeProfit ?? pos.EntryPrice) - pos.EntryPrice);

            case TradeType.Sell: return(pos.EntryPrice - (pos.TakeProfit ?? pos.EntryPrice));
            }
        }
Exemplo n.º 5
0
        public static ChangedEnum WhatsChanged(cAlgo.API.Position Position)
        {
            Model.Position LocalPosition = GetByID(Position.Id);


            if (LocalPosition == null)
            {
                return(ChangedEnum.Status);
            }
            // else if (LocalPosition.TakeProfit <> (decimal)Position.TakeProfit  )
            //   return ChangedEnum.TakeProfit

            return(ChangedEnum.Unknown);
        }
Exemplo n.º 6
0
 protected void PublishOnPositionClosed(cAlgo.API.Position _postion, cAlgo.API.Positions _positions)
 {
 }
Exemplo n.º 7
0
        public static bool Update(IAccount Account, cAlgo.API.Position Position, string Status)
        {
            Model.Position LocalPosition = GetByID(Position.Id);

            if (LocalPosition == null)
            {
                LocalPosition = new Model.Position();
            }

            LocalPosition.ID        = Position.Id;
            LocalPosition.AccountID = Account.Number;
            LocalPosition.Symbol    = Position.SymbolCode;
            LocalPosition.TradeType = Position.TradeType.ToString();
            if (Position.Volume != 0)
            {
                LocalPosition.Volume = Position.Volume;
            }
            if (Position.Quantity != 0)
            {
                LocalPosition.Quantity = Position.Quantity;
            }
            if (Position.EntryPrice != 0)
            {
                LocalPosition.EntryPrice = (decimal)Position.EntryPrice;
            }
            if (Position.StopLoss != null)
            {
                LocalPosition.StopLoss = (decimal)Position.StopLoss;
            }
            if (Position.TakeProfit != null)
            {
                LocalPosition.TakeProfit = (decimal)Position.TakeProfit;
            }
            // LocalPosition.ClosedPrice = "";
            if (Position.Swap != 0)
            {
                LocalPosition.Swap = (decimal)Position.Swap;
            }
            LocalPosition.Channel = "";
            if (Position.Label != null)
            {
                LocalPosition.Label = Position.Label;
            }
            if (Position.Comment != null)
            {
                LocalPosition.Comment = Position.Comment;
            }
            LocalPosition.GrossProfit = (decimal)Position.GrossProfit;
            LocalPosition.NetProfit   = (decimal)Position.NetProfit;
            LocalPosition.Pips        = Position.Pips;

            if (Status == "Opened")
            {
                LocalPosition.DateTimeCreatedUTC = DateTime.UtcNow;
            }

            LocalPosition.DateTimeLastModifiedUTC = DateTime.UtcNow;
            LocalPosition.Status = Status;

            return(Save(LocalPosition));
        }