コード例 #1
0
 // TODO: Right now called when a new trade is added in the deposit. Should support more cases.
 public DepositViewModel Refresh(DepositViewModel depositVm, TradeViewModel tradeVm)
 {
     var deposit = _viewModelToModelMapper.MapToDeposit(depositVm, true);
     var trade = _viewModelToModelMapper.MapToTrade(tradeVm);
     var depositInfoDTO = _depositService.Refresh(deposit, trade);
     return _modelToViewModelMapper.MapToDepositViewModel(depositInfoDTO);
 }
コード例 #2
0
        public void Create(TradeViewModel tradeVm)
        {
            Guard.AgainstNull(() => tradeVm);

            var trade = _viewModelToModelMapper.MapToTrade(tradeVm);
            _tradeService.CreateTrade(trade);
            tradeVm.Id = trade.Id;
        }
コード例 #3
0
        public TradeInfoDto GetTradeInfo(TradeViewModel tradeVm, DepositViewModel depositVm)
        {
            Guard.AgainstNull(() => tradeVm, () => depositVm);

            var isBuy = tradeVm.IsBuy == true;
            var price = tradeVm.Price ?? 0;
            var quantity = tradeVm.Quantity ?? 0;
            var stockId = tradeVm.Stock.Id;
            var deposit = _viewModelToModelMapper.MapToDeposit(depositVm);

            return _tradeService.CalculateTradeInfo(isBuy, price, quantity, stockId, deposit);
        }
コード例 #4
0
        public void RefreshDepositTradeAdded(DepositViewModel depositVm, TradeViewModel tradeVm)
        {
            var refreshedDepositVm = _depositGateway.Refresh(depositVm, tradeVm);
            var refreshedTradeVm = refreshedDepositVm.Trades.Single(p => p.Id == tradeVm.Id);

            depositVm.SellableStockIds = refreshedDepositVm.SellableStockIds;
            depositVm.Trades.Add(refreshedTradeVm);

            var refreshedPosition = refreshedDepositVm.StockPositions.Single(p => p.Stock.Id == refreshedTradeVm.Stock.Id);
            depositVm.StockPositions.Single(p => p.Stock.Id == refreshedTradeVm.Stock.Id).Quantity = refreshedPosition.Quantity;

            // Add new trade to the collection of stocks.
            var stock = Stocks.Single(p => p.Id == refreshedTradeVm.Stock.Id);
            stock.Trades.Add(refreshedTradeVm);
        }
コード例 #5
0
        private Trade GetTrade(TradeViewModel tradeVm)
        {
            Stock stock = GetStock(tradeVm.Stock);
            Deposit deposit = GetDeposit(tradeVm.Deposit);

            return new Trade(
                tradeVm.Id,
                tradeVm.IsBuy.Value,
                tradeVm.Quantity.Value,
                tradeVm.Price.Value,
                tradeVm.Commission.Value,
                tradeVm.TradeDate.Value,
                tradeVm.Deposit.Id,
                tradeVm.Stock.Id,
                deposit, 
                stock);
        }
コード例 #6
0
 public Trade MapToTrade(TradeViewModel tradeVm)
 {
     var trade = GetTrade(tradeVm);
     return trade;
 }