예제 #1
0
        public static POSITION_CLOSED UndecorateClosedPosition(MarketOrder pos)
        {
            // ReSharper disable PossibleInvalidOperationException
            var p = new POSITION_CLOSED
            {
                ID             = pos.ID,
                AccountID      = pos.AccountID,
                Comment        = pos.Comment,
                ExitReason     = (int)pos.ExitReason,
                ExpertComment  = pos.ExpertComment,
                Magic          = pos.Magic,
                PendingOrderID = pos.PendingOrderID,
                PriceBest      = (decimal?)pos.PriceBest,
                PriceWorst     = (decimal?)pos.PriceWorst,
                PriceEnter     = (decimal)pos.PriceEnter,
                ResultBase     = (decimal)pos.ResultBase,
                ResultDepo     = (decimal)pos.ResultDepo,
                ResultPoints   = (decimal)pos.ResultPoints,
                Side           = pos.Side,
                Stoploss       = (decimal?)pos.StopLoss,
                Swap           = (decimal)(pos.Swap ?? 0),
                Symbol         = pos.Symbol,
                Takeprofit     = (decimal?)pos.TakeProfit,
                TimeEnter      = pos.TimeEnter,
                Volume         = pos.Volume,
                PriceExit      = (decimal)pos.PriceExit.Value,
                TimeExit       = pos.TimeExit.Value
            };

            // ReSharper restore PossibleInvalidOperationException
            return(p);
        }
예제 #2
0
        public static MarketOrder DecorateOrder(POSITION_CLOSED pos)
        {
            var mo = new MarketOrder
            {
                AccountID      = pos.AccountID,
                Comment        = pos.Comment,
                ExpertComment  = pos.ExpertComment,
                ID             = pos.ID,
                Magic          = pos.Magic,
                PendingOrderID = pos.PendingOrderID,
                PriceBest      = (float?)pos.PriceBest,
                PriceEnter     = (float)pos.PriceEnter,
                PriceWorst     = (float?)pos.PriceWorst,
                PriceExit      = (float?)pos.PriceExit,
                TimeExit       = pos.TimeExit,
                Side           = pos.Side,
                State          = PositionState.Closed,
                StopLoss       = (float?)(pos.Stoploss == 0 ? null : pos.Stoploss),
                TakeProfit     = (float?)(pos.Takeprofit == 0 ? null : pos.Takeprofit),
                Swap           = (float?)pos.Swap,
                Symbol         = pos.Symbol,
                TimeEnter      = pos.TimeEnter,
                Volume         = pos.Volume,
                ResultDepo     = (float)pos.ResultDepo,
                ResultPoints   = (float)pos.ResultPoints,
                ResultBase     = (float)pos.ResultBase,
                ExitReason     = (PositionExitReason)pos.ExitReason
            };

            return(mo);
        }
예제 #3
0
 private static decimal AmendDeal(POSITION_CLOSED deal, TradeSharpConnection conn, decimal deltaAmount)
 {
     // "поправить" сделку
     deal.Side = - deal.Side;
     deal.ResultDepo = - deal.ResultDepo;
     var bc = conn.BALANCE_CHANGE.FirstOrDefault(b => b.Position == deal.ID);
     if (bc != null)
     {
         bc.ChangeType = (int) BalanceChangeType.Profit;
         var trans = conn.TRANSFER.FirstOrDefault(t => t.BalanceChange == bc.ID);
         deltaAmount += (bc.Amount*2);
         if (trans != null)
         {
             trans.Amount = -trans.Amount;
             trans.TargetAmount = -trans.TargetAmount;
         }
     }
     return deltaAmount;
 }
예제 #4
0
 private bool ModifyClosedPosition(MarketOrder order, TradeSharpConnection ctx, POSITION_CLOSED pos,
     out string errorString)
 {
     errorString = string.Empty;
     if (order.IsClosed)
     {
         var opened = new POSITION
         {
             AccountID = pos.AccountID,
             ID = pos.ID,
             Comment = order.Comment,
             Magic = order.Magic,
             ExpertComment = order.ExpertComment,
             PendingOrderID = order.PendingOrderID,
             PriceBest = (decimal?)order.PriceBest,
             PriceEnter = (decimal)order.PriceEnter,
             PriceWorst = (decimal?)order.PriceWorst,
             Side = order.Side,
             Stoploss = (decimal?)order.StopLoss,
             Symbol = order.Symbol,
             Takeprofit = (decimal?)order.TakeProfit,
             TimeEnter = order.TimeEnter,
             Volume = order.Volume,
             State = (int) order.State,
             MasterOrder = order.MasterOrder
         };
         ctx.POSITION_CLOSED.Remove(pos);
         ctx.POSITION.Add(opened);
         ctx.SaveChanges();
         Logger.InfoFormat("Closed order {0} {1} {2} {3} was reopened",
             pos.ID, pos.Side > 0 ? "BUY" : "SELL", pos.Volume, pos.Symbol);
         return true;
     }
     pos.Comment = order.Comment;
     pos.Magic = order.Magic;
     pos.ExpertComment = order.ExpertComment;
     pos.PendingOrderID = order.PendingOrderID;
     pos.PriceBest = (decimal?)order.PriceBest;
     pos.PriceEnter = (decimal)order.PriceEnter;
     pos.PriceWorst = (decimal?)order.PriceWorst;
     pos.Side = order.Side;
     pos.Stoploss = (decimal?)order.StopLoss;
     pos.Symbol = order.Symbol;
     pos.Takeprofit = (decimal?)order.TakeProfit;
     if (order.TimeEnter != default(DateTime))
         pos.TimeEnter = order.TimeEnter;
     pos.Volume = order.Volume;
     pos.ExitReason = (int) order.ExitReason;
     pos.PriceExit = (decimal) (order.PriceExit ?? 0);
     pos.PriceWorst = (decimal?) order.PriceWorst;
     pos.ResultBase = (decimal)order.ResultBase;
     pos.ResultDepo = (decimal)order.ResultDepo;
     pos.ResultPoints = (decimal)order.ResultPoints;
     pos.TimeExit = order.TimeExit ?? default(DateTime);
     pos.Swap = (decimal) (order.Swap ?? 0);
     Logger.InfoFormat("Closed order {0} {1} {2} {3} was modified",
             pos.ID, pos.Side > 0 ? "BUY" : "SELL", pos.Volume, pos.Symbol);
     ctx.SaveChanges();
     return true;
 }
예제 #5
0
 private bool ModifyOpenedPosition(MarketOrder order, TradeSharpConnection ctx, POSITION pos, 
     out string errorString)
 {
     errorString = string.Empty;
     if (order.IsClosed)
     {
         var closed = new POSITION_CLOSED
         {
             AccountID = pos.AccountID,
             ID = pos.ID,
             Comment = order.Comment,
             ExitReason = (int) order.ExitReason,
             Magic = order.Magic,
             ExpertComment = order.ExpertComment,
             PendingOrderID = order.PendingOrderID,
             PriceBest = (decimal?) order.PriceBest,
             PriceEnter = (decimal) order.PriceEnter,
             PriceExit = (decimal) (order.PriceExit ?? 0),
             PriceWorst = (decimal?) order.PriceWorst,
             ResultBase = (decimal) order.ResultBase,
             ResultDepo = (decimal) order.ResultDepo,
             ResultPoints = (decimal) order.ResultPoints,
             Side = order.Side,
             Stoploss = (decimal?) order.StopLoss,
             Swap = (decimal) (order.Swap ?? 0),
             Symbol = order.Symbol,
             Takeprofit = (decimal?) order.TakeProfit,
             TimeEnter = order.TimeEnter,
             TimeExit = order.TimeExit ?? default(DateTime),
             Volume = order.Volume
         };
         ctx.POSITION.Remove(pos);
         ctx.POSITION_CLOSED.Add(closed);
         return true;
     }
     pos.Comment = order.Comment;
     pos.Magic = order.Magic;
     pos.ExpertComment = order.ExpertComment;
     pos.PendingOrderID = order.PendingOrderID;
     pos.PriceBest = (decimal?) order.PriceBest;
     pos.PriceEnter = (decimal) order.PriceEnter;
     pos.PriceWorst = (decimal?) order.PriceWorst;
     pos.Side = order.Side;
     pos.Stoploss = (decimal?) order.StopLoss;
     pos.Symbol = order.Symbol;
     pos.Takeprofit = (decimal?) order.TakeProfit;
     pos.TimeEnter = order.TimeEnter;
     pos.Volume = order.Volume;
     pos.State = (int) order.State;
     pos.MasterOrder = order.MasterOrder;
     ctx.SaveChanges();
     return true;
 }
예제 #6
0
 public static POSITION_CLOSED UndecorateClosedPosition(MarketOrder pos)
 {
     // ReSharper disable PossibleInvalidOperationException
     var p = new POSITION_CLOSED
     {
         ID = pos.ID,
         AccountID = pos.AccountID,
         Comment = pos.Comment,
         ExitReason = (int)pos.ExitReason,
         ExpertComment = pos.ExpertComment,
         Magic = pos.Magic,
         PendingOrderID = pos.PendingOrderID,
         PriceBest = (decimal?)pos.PriceBest,
         PriceWorst = (decimal?)pos.PriceWorst,
         PriceEnter = (decimal)pos.PriceEnter,
         ResultBase = (decimal)pos.ResultBase,
         ResultDepo = (decimal)pos.ResultDepo,
         ResultPoints = (decimal)pos.ResultPoints,
         Side = pos.Side,
         Stoploss = (decimal?)pos.StopLoss,
         Swap = (decimal)(pos.Swap ?? 0),
         Symbol = pos.Symbol,
         Takeprofit = (decimal?)pos.TakeProfit,
         TimeEnter = pos.TimeEnter,
         Volume = pos.Volume,
         PriceExit = (decimal)pos.PriceExit.Value,
         TimeExit = pos.TimeExit.Value
     };
     // ReSharper restore PossibleInvalidOperationException
     return p;
 }
예제 #7
0
 public static MarketOrder DecorateOrder(POSITION_CLOSED pos)
 {
     var mo = new MarketOrder
     {
         AccountID = pos.AccountID,
         Comment = pos.Comment,
         ExpertComment = pos.ExpertComment,
         ID = pos.ID,
         Magic = pos.Magic,
         PendingOrderID = pos.PendingOrderID,
         PriceBest = (float?)pos.PriceBest,
         PriceEnter = (float)pos.PriceEnter,
         PriceWorst = (float?)pos.PriceWorst,
         PriceExit = (float?)pos.PriceExit,
         TimeExit = pos.TimeExit,
         Side = pos.Side,
         State = PositionState.Closed,
         StopLoss = (float?)(pos.Stoploss == 0 ? null : pos.Stoploss),
         TakeProfit = (float?)(pos.Takeprofit == 0 ? null : pos.Takeprofit),
         Swap = (float?)pos.Swap,
         Symbol = pos.Symbol,
         TimeEnter = pos.TimeEnter,
         Volume = pos.Volume,
         ResultDepo = (float)pos.ResultDepo,
         ResultPoints = (float)pos.ResultPoints,
         ResultBase = (float)pos.ResultBase,
         ExitReason = (PositionExitReason)pos.ExitReason
     };
     return mo;
 }