Exemplo n.º 1
0
        private async void CloneOrder(int size)
        {
            if (SelectedOrder == null)
            {
                return;
            }

            if (size <= 0)
            {
                return;
            }

            var res = await DialogService.ShowMessageAsync(Parent,
                                                           "Virtual Order Creation",
                                                           string.Format("Are you sure you want to create virtual orders for {0} shares?", size),
                                                           MessageDialogStyle.AffirmativeAndNegative);

            if (res != MessageDialogResult.Affirmative)
            {
                return;
            }

            var originalOrder = SelectedOrder;

            var cloneBuy  = (Order)originalOrder.Clone();
            var cloneSell = (Order)originalOrder.Clone();

            cloneBuy.Quantity         = size;
            cloneSell.Quantity        = -size;
            cloneBuy.Taxes            = 0;
            cloneSell.Taxes           = 0;
            cloneBuy.Commission       = 0;
            cloneSell.Commission      = 0;
            cloneBuy.Notes            = "";
            cloneSell.Notes           = "";
            cloneBuy.BuySell          = "BUY";
            cloneSell.BuySell         = "SELL";
            cloneBuy.Trade            = null;
            cloneSell.Trade           = null;
            cloneBuy.FIFORealizedPnL  = 0;
            cloneSell.FIFORealizedPnL = 0;
            cloneBuy.IBOrderID        = null;
            cloneSell.IBOrderID       = null;
            cloneBuy.TradeMoney       = size * originalOrder.Price;
            cloneSell.TradeMoney      = -size * originalOrder.Price;
            cloneBuy.Proceeds         = -size * originalOrder.Price;
            cloneSell.Proceeds        = size * originalOrder.Price;
            cloneBuy.CostBasis        = size * originalOrder.Price;
            cloneSell.CostBasis       = -size * originalOrder.Price;
            cloneBuy.NetCash          = -size * originalOrder.Price;
            cloneSell.NetCash         = size * originalOrder.Price;
            cloneBuy.MTMPnL           = size * (originalOrder.Price - originalOrder.ClosePrice);
            cloneSell.MTMPnL          = -size * (originalOrder.Price - originalOrder.ClosePrice);

            Context.Orders.Add(cloneBuy);
            Context.Orders.Add(cloneSell);

            Context.SaveChanges();

            OrdersSource.View.Refresh();
        }