Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
        }