コード例 #1
0
        public override async Task ExecuteAsync(object parameter)
        {
            try
            {
                ForexDTO fxTransaction = new ForexDTO
                {
                    TradeDate    = _addFXTradeWindowVM.TradeDate,
                    SettleDate   = _addFXTradeWindowVM.SettleDate,
                    Price        = _addFXTradeWindowVM.Price,
                    BuyAmount    = _addFXTradeWindowVM.BuyAmount,
                    SellAmount   = _addFXTradeWindowVM.SellAmount,
                    SellCurrency = _addFXTradeWindowVM.SellCurrency,
                    BuyCurrency  = _addFXTradeWindowVM.BuyCurrency,
                    Custodian    = _addFXTradeWindowVM.Custodian,
                    FundId       = _addFXTradeWindowVM.FundId
                };

                await _transactionService.CreateFXTransaction(fxTransaction);

                _addFXTradeWindowVM.CloseAction();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
コード例 #2
0
        public async Task <TransactionsBO> CreateFXTransaction(ForexDTO fxTransaction)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                SecuritiesDIM fxSecurity = context.Securities.AsNoTracking().Where(s => s.Symbol == fxTransaction.Symbol).FirstOrDefault();
                AssetClassDIM assetClass = context.AssetClasses.AsNoTracking().Where(a => a.Name == "FXForward").FirstOrDefault();
                CustodiansDIM custodian  = context.Custodians.AsNoTracking().Where(c => c.Name == fxTransaction.Custodian).FirstOrDefault();
                IEnumerable <TransactionTypeDIM> transactionTypes = context.TransactionTypes;
                List <CurrenciesDIM>             currencies       = context.Currencies.AsNoTracking().ToList();

                CurrenciesDIM buyCurrency  = context.Currencies.AsNoTracking().Where(c => c.Symbol == fxTransaction.BuyCurrency).First();
                CurrenciesDIM sellCurrency = context.Currencies.AsNoTracking().Where(c => c.Symbol == fxTransaction.SellCurrency).First();
                if (fxSecurity == null)
                {
                    fxSecurity = new SecuritiesDIM
                    {
                        AssetClassId = assetClass.AssetClassId,
                        CurrencyId   = buyCurrency.CurrencyId,
                        SecurityName = fxTransaction.Name,
                        Symbol       = fxTransaction.Symbol
                    };
                    context.Securities.Add(fxSecurity);
                }
                // Created LinkedTransactions Here
                LinkedTradesBO linkReference  = new LinkedTradesBO();
                TransactionsBO refTransaction = new TransactionsBO
                {
                    Security          = fxSecurity,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = 0,
                    Price             = fxTransaction.Price,
                    Quantity          = fxTransaction.BuyAmount,
                    CurrencyId        = buyCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXTrade").First().TransactionTypeId,
                    Comment           = "",
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.TradeDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                TransactionsBO refTransactionCollapse = new TransactionsBO
                {
                    Security          = fxSecurity,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = 0,
                    Price             = fxTransaction.Price,
                    Quantity          = fxTransaction.BuyAmount * -1,
                    CurrencyId        = buyCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXTradeCollapse").First().TransactionTypeId,
                    Comment           = "",
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.SettleDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                EntityEntry <TransactionsBO> res = await context.Transactions.AddAsync(refTransaction);

                context.Transactions.Add(refTransactionCollapse);

                SecuritiesDIM fxBuySecurity  = context.Securities.AsNoTracking().Where(s => s.Symbol == $"{fxTransaction.BuyCurrency}c").FirstOrDefault();
                SecuritiesDIM fxSellSecurity = context.Securities.AsNoTracking().Where(s => s.Symbol == $"{fxTransaction.SellCurrency}c").FirstOrDefault();

                TransactionsBO fxBuyLegCash = new TransactionsBO
                {
                    SecurityId        = fxBuySecurity.SecurityId,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = fxTransaction.BuyAmount,
                    Price             = 1,
                    Quantity          = fxTransaction.BuyAmount,
                    CurrencyId        = buyCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXBuy").First().TransactionTypeId,
                    Comment           = fxTransaction.Description,
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.SettleDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                TransactionsBO fxSellLegCash = new TransactionsBO
                {
                    SecurityId        = fxSellSecurity.SecurityId,
                    FundId            = fxTransaction.FundId,
                    isActive          = true,
                    isLocked          = false,
                    TradeAmount       = fxTransaction.SellAmount,
                    Price             = 1,
                    Quantity          = fxTransaction.SellAmount,
                    CurrencyId        = sellCurrency.CurrencyId,
                    TransactionTypeId = transactionTypes.Where(tt => tt.TypeName == "FXSell").First().TransactionTypeId,
                    Comment           = fxTransaction.Description,
                    CustodianId       = custodian.CustodianId,
                    Fees = 0,
                    isCashTransaction = false,
                    TradeDate         = fxTransaction.SettleDate,
                    SettleDate        = fxTransaction.SettleDate,
                    CreatedDate       = DateTime.Now,
                    LastModified      = DateTime.Now,
                    LinkedTrades      = linkReference
                };
                context.Transactions.Add(fxBuyLegCash);
                context.Transactions.Add(fxSellLegCash);

                await context.SaveChangesAsync();

                return(refTransaction);
            }
        }