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); }
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); }
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 = }
/// <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)); } }
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); }
protected void PublishOnPositionClosed(cAlgo.API.Position _postion, cAlgo.API.Positions _positions) { }
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)); }