public void FilterByContract(string contract)
        {
            if (TradeTreeView == null)
            {
                return;
            }

            ICollectionView view = CollectionViewSource.GetDefaultView(TradeTreeView.ItemsSource);

            view.Filter = delegate(object o)
            {
                if (contract == null)
                {
                    return(true);
                }

                TradeVM tvm = o as TradeVM;

                if (tvm.Contract.Contains(contract))
                {
                    return(true);
                }

                return(false);
            };
        }
Esempio n. 2
0
        public IActionResult SaveTrades(string symbol)
        {
            List <Trade> trades = GetTrades(symbol);

            // save the quote if the quote has not already been saved in the database

            foreach (Trade trade in trades)
            {
                //Database will give PK constraint violation error when trying to insert record with existing PK.
                //So add company only if it doesnt exist, check existence using symbol (PK)
                if (dbContext.Trades.Where(c => c.TradeId.Equals(trade.TradeId)).Count() == 0)
                {
                    dbContext.Trades.Add(trade);
                }
            }

            // persist the data
            dbContext.SaveChanges();

            // populate the models to render in the view
            ViewBag.dbSuccessChart = 1;
            TradeVM tradeViewModel = getTradeVM(trades);

            return(View("Trade", tradeViewModel));
        }
        public void FilterByStatus(IEnumerable <OrderOpenCloseType> statuses)
        {
            if (TradeTreeView == null)
            {
                return;
            }

            ICollectionView view = _viewSource.View;

            view.Filter = delegate(object o)
            {
                if (statuses == null)
                {
                    return(true);
                }

                TradeVM tvm = o as TradeVM;

                if (statuses.Contains(tvm.OpenClose))
                {
                    return(true);
                }

                return(false);
            };
        }
        public void FilterByPortfolio(string portfolio)
        {
            if (TradeTreeView == null)
            {
                return;
            }

            ICollectionView view = CollectionViewSource.GetDefaultView(TradeTreeView.ItemsSource);

            view.Filter = delegate(object o)
            {
                if (portfolio == null)
                {
                    return(true);
                }

                TradeVM tvm = o as TradeVM;

                if (tvm.Portfolio.Contains(portfolio))
                {
                    return(true);
                }

                return(false);
            };
        }
Esempio n. 5
0
        public ActionResult TradePlayers(TradeVM newvm)
        {
            var teamManager   = new TeamManager();
            var playerManager = new PlayerManager();

            newvm.Team1 = teamManager.GetTeamById(newvm.Team1.Id);
            newvm.Team2 = teamManager.GetTeamById(newvm.Team2.Id);
            newvm.Team1.Players.Clear();
            newvm.Team2.Players.Clear();

            if (newvm.Team1PlayersToAdd != null && newvm.Team1PlayersToAdd.Count > 0)
            {
                foreach (var playerid in newvm.Team1PlayersToAdd)
                {
                    newvm.Team1.Players.RemoveAll(p => p.Id == playerid);
                    newvm.Team2.Players.Add(playerManager.GetPlayerById(playerid));
                    var player = playerManager.GetPlayerById(playerid);
                    player.TeamId = newvm.Team2.Id;
                }
            }
            if (newvm.Team2PlayersToAdd != null && newvm.Team2PlayersToAdd.Count > 0)
            {
                foreach (var playerid in newvm.Team2PlayersToAdd)
                {
                    newvm.Team2.Players.RemoveAll(p => p.Id == playerid);
                    newvm.Team1.Players.Add(playerManager.GetPlayerById(playerid));
                    var player = playerManager.GetPlayerById(playerid);
                    player.TeamId = newvm.Team1.Id;
                }
            }

            return(RedirectToAction("Teams"));
        }
Esempio n. 6
0
        // GET: Trades
        public ActionResult Index()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account"));
            }

            List <Trade>   tList   = new List <Trade>();
            List <TradeVM> tVMList = new List <TradeVM>();

            tList = db.Trades.ToList();
            foreach (Trade tr in tList)
            {
                TradeVM  trVM = new TradeVM();
                AltCoin  a    = db.AltCoins.FirstOrDefault(x => x.AltCoinID == tr.CoinID);
                Exchange e    = db.Exchanges.FirstOrDefault(y => y.ExchangeID == tr.ExchangeID);

                trVM.TradeID          = tr.TradeID;
                trVM.CoinName         = a.CoinName;
                trVM.TradeDate        = tr.TradeDate;
                trVM.ExchangeName     = e.ExchangeName;
                trVM.AmountTraded     = tr.AmountTraded;
                trVM.BoughtYes        = tr.BoughtYes;
                trVM.PriceBTC         = tr.PriceBTC;
                trVM.PriceUSD         = tr.PriceUSD;
                trVM.CommissionAmount = tr.Commission;
                a = db.AltCoins.FirstOrDefault(x => x.AltCoinID == tr.CommissionCoinID);
                trVM.CommissionCoin = a.CoinName;

                tVMList.Add(trVM);
            }

            return(View(tVMList));
        }
        public bool saveTrade(TradeVM tradeVm, string tradePics)
        {
            bool flag = false;

            using (var tran = new TransactionScope())
            {
                using (var ctx = new ShtxSms2008Entities())
                {
                    try
                    {
                        Supply supply = new Supply();
                        supply.buissnes     = tradeVm.Buissnes; //所属行业
                        supply.Product      = tradeVm.Product;  //名称
                        supply.Quantity     = tradeVm.Quantity;
                        supply.Price        = tradeVm.Price;
                        supply.Contact      = tradeVm.Contact;
                        supply.Mobile       = tradeVm.ContactTel;
                        supply.Description  = tradeVm.Description;
                        supply.DocumentType = tradeVm.DocumentType;
                        supply.provinceName = tradeVm.Province;
                        supply.cityName     = tradeVm.City;
                        supply.Creater      = tradeVm.Mobile;
                        supply.CreateDate   = DateTime.Now;

                        ctx.Supplies.Add(supply);

                        if (!string.IsNullOrWhiteSpace(tradePics))
                        {
                            string[] pics = tradePics.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var pic in pics)
                            {
                                Image image = new Image();
                                image.SupplyID = supply.ID;
                                image.Name     = pic;
                                var path    = Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "upload");
                                var picPath = Path.Combine(path, pic);
                                var path1   = Path.GetFileNameWithoutExtension(picPath) + "-1" + Path.GetExtension(picPath);

                                System.Drawing.Image imgOutput  = System.Drawing.Bitmap.FromFile(picPath);
                                System.Drawing.Image imgOutput2 = imgOutput.GetThumbnailImage(60, 60, null, IntPtr.Zero);
                                imgOutput2.Save(path1);

                                ctx.Images.Add(image);
                            }
                        }

                        ctx.SaveChanges();

                        tran.Complete();
                        flag = true;
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(flag);
        }
Esempio n. 8
0
        /*----------------------------------------------------------------------------------------------------*/
        /*---------------------------------Largest Trades API!!!----------------------------------------------*/

        public IActionResult Trade(string symbol)
        {
            //Set ViewBag variable first
            ViewBag.dbSuccessChart = 0;
            List <Trade> trades = new List <Trade>();

            if (symbol != null)
            {
                trades = GetTrades(symbol);
            }

            TradeVM tradeViewModel = getTradeVM(trades);

            return(View(tradeViewModel));
        }
Esempio n. 9
0
        public ActionResult GetTeamsToTrade(GetTeamsForTradeVM vm)
        {
            var teamManager   = new TeamManager();
            var playerManager = new PlayerManager();
            var newvm         = new TradeVM();

            newvm.Team1 = teamManager.GetTeamById(vm.Team1ID);
            newvm.Team2 = teamManager.GetTeamById(vm.Team2ID);
            var team1players = playerManager.GetAllPlayers().FindAll(p => p.TeamId == newvm.Team1.Id);
            var team2players = playerManager.GetAllPlayers().FindAll(p => p.TeamId == newvm.Team2.Id);

            newvm.SetTeam1List(team1players);
            newvm.SetTeam2List(team2players);
            return(View("TradePlayers", newvm));
        }
Esempio n. 10
0
/*-----------------------------------------------------------Largest Trade API Endpoint---------------------------------------------------------------------*/
/*--------------------------------------------------------------Trade Action Method------------------------------------------------------------------------*/
        public IActionResult Trade(string symbol)

        {
            //ViewBag Intialization

            ViewBag.dbSuccessChart = 0;

            List <Trade> Largesttrades = new List <Trade>();

            if (symbol != null)
            {
                Largesttrades = GetTrades(symbol);
            }

            TradeVM LargestTradeReturn = getTradeVM(Largesttrades);

            return(View(LargestTradeReturn));
        }
Esempio n. 11
0
        private TradeVM GetTradeEntry()
        {
            try
            {
                TradeVM trade = new TradeVM()
                {
                    TickerId  = ((Ticker)cmbTicker.SelectedItem).Id,
                    Ticker    = (Ticker)cmbTicker.SelectedItem,
                    TradeDate = dtTradeDate.Value.Date,
                    TradeType = cmbTradeType.SelectedValue.ToString(),
                    Quantity  = int.Parse(txtQuantity.Text),
                    UnitPrice = decimal.Parse(txtUnitPrice.Text),
                };

                trade.OtherCostperUnit          = rCostPerUnit.Checked && txtCost.Text != "" ? decimal.Parse(txtCost.Text) : (decimal?)null;
                trade.TotalOtherCost            = rCostPerTrade.Checked && txtCost.Text != "" ? decimal.Parse(txtCost.Text) : (decimal?)null;
                trade.TransactionAmount         = trade.Quantity * trade.UnitPrice;
                trade.TransactionAmountWithCost = trade.TransactionAmount;
                if (trade.OtherCostperUnit != null && trade.OtherCostperUnit > 0)
                {
                    trade.TotalOtherCost            = trade.OtherCostperUnit * trade.Quantity;
                    trade.TransactionAmountWithCost = trade.TransactionAmount + (trade.OtherCostperUnit * trade.Quantity) ?? trade.TransactionAmount;
                }
                else if (trade.TotalOtherCost != null && trade.TotalOtherCost > 0)
                {
                    trade.OtherCostperUnit          = trade.OtherCostperUnit / trade.Quantity;
                    trade.TransactionAmountWithCost = trade.TransactionAmount + trade.TotalOtherCost ?? trade.TransactionAmount;
                }
                trade.UnitPriceWithCost = trade.TransactionAmountWithCost / trade.Quantity;

                return(trade);
            }
            catch (Exception ex)
            {
                Utils.Logger.Log(ex);
            }
            return(null);
        }
        public void Filter(string tabTitle, string exchange, string underlying, string contract, string portfolio)
        {
            if (TradeTreeView == null)
            {
                return;
            }

            // AnchorablePane.SelectedContent.Title = tabTitle;
            FilterSettingsWin.FilterTabTitle   = tabTitle;
            FilterSettingsWin.FilterExchange   = exchange;
            FilterSettingsWin.FilterUnderlying = underlying;
            FilterSettingsWin.FilterContract   = contract;
            FilterSettingsWin.FilterPortfolio  = portfolio;

            ICollectionView view = _viewSource.View;

            view.Filter = delegate(object o)
            {
                if (contract == null)
                {
                    return(true);
                }

                TradeVM tvm = o as TradeVM;

                if (tvm.Exchange.ContainsAny(exchange) &&
                    tvm.Contract.ContainsAny(contract) &&
                    tvm.Contract.ContainsAny(underlying) &&
                    tvm.Portfolio.ContainsAny(portfolio))
                {
                    return(true);
                }

                return(false);
            };
        }
        public List <TradeVM> GetMoreTradesById(int id, int documentType, string searchKey, string area, string business, string action)
        {
            var list = new List <TradeVM>();

            using (var ctx = new ShtxSms2008Entities())
            {
                List <Supply> supplies = new List <Supply>();
                var           query    = ctx.Supplies.AsQueryable();
                query = query.Where(o => o.isChecked.Value && o.DocumentType == documentType);
                if (searchKey.Trim() != "")
                {
                    query = query.Where(o => o.Product.Contains(searchKey));
                }
                if (area != "地区")
                {
                    query = query.Where(o => o.provinceName == area);
                }
                if (business != "分类")
                {
                    query = query.Where(o => o.buissnes == business);
                }
                if (action.ToLower() == "down")
                {
                    if (id == 0)
                    {
                        query = query.OrderByDescending(o => o.ID).Take(30);
                    }
                    else
                    {
                        query = query.Where(o => o.ID > id).OrderByDescending(o => o.ID).Take(30);
                    }
                }
                else
                {
                    if (id == 0)
                    {
                        query = query.OrderByDescending(o => o.ID).Take(30);
                    }
                    else
                    {
                        query = query.Where(o => o.ID < id).OrderByDescending(o => o.ID).Take(30);
                    }
                }
                supplies = query.ToList();
                foreach (var supply in supplies)
                {
                    TradeVM vm = new TradeVM();
                    vm.Id          = supply.ID;
                    vm.Buissnes    = supply.buissnes;
                    vm.City        = supply.cityName;
                    vm.Product     = supply.Product;
                    vm.Quantity    = supply.Quantity;
                    vm.Price       = supply.Price;
                    vm.Contact     = supply.Contact;
                    vm.ContactTel  = supply.Mobile;
                    vm.Description = supply.Description;
                    vm.Province    = supply.provinceName;
                    vm.Description = supply.Description;
                    vm.Date        = supply.CreateDate.ToString("MM-dd");
                    var picNames = ctx.Images.Where(o => o.SupplyID == supply.ID).Select(o => o.Name).ToList();
                    vm.Pics = picNames;
                    list.Add(vm);
                }
            }

            return(list);
        }
        public async Task <AccountStatementVM> GetTradeHistory(int year = 0, int month = 0, int day = 0, string stock = null)
        {
            var stock_negotiations = await _mediator.Send(new GetCollectionRequest <StockTransaction>());

            stock_negotiations = stock_negotiations.Where(x => x.When > DateTime.Parse("2019/09/01"));

            if (!String.IsNullOrEmpty(stock))
            {
                stock_negotiations = stock_negotiations.Where(p => p.Stock.Symbol == stock);
            }

            if (year > 0)
            {
                stock_negotiations = stock_negotiations.Where(p => p.When.Year == year);

                if (month > 0)
                {
                    stock_negotiations = stock_negotiations.Where(p => p.When.Month == month);

                    if (day > 0)
                    {
                        stock_negotiations = stock_negotiations.Where(p => p.When.Day == day);
                    }
                }
            }

            var vm = new AccountStatementVM()
            {
                TradeStatements = new List <TradeStatementVM>()
            };

            TradeStatementVM tradeStatementVM = new TradeStatementVM()
            {
                Trades = new List <TradeVM>()
            };

            var stocks_trade = stock_negotiations.Select(x => x.Stock.Symbol).Distinct();

            foreach (var stock_trade in stocks_trade)
            {
                var buys = stock_negotiations
                           .Where(x => x.Stock.Symbol == stock_trade && x.TradeType == TradeTypeEnum.BUY)
                           .OrderBy(x => x.When)
                           .ToList();

                var sells = stock_negotiations
                            .Where(x => x.Stock.Symbol == stock_trade && x.TradeType == TradeTypeEnum.SELL)
                            .OrderBy(x => x.When)
                            .ToList();

                foreach (var sell in sells)
                {
                    var trade             = buys.Where(x => x.When < sell.When).ToList();
                    var trade_amount      = sell.Amount - trade.Sum(x => x.Amount) < 1 ? sell.Amount : sell.Amount - trade.Sum(x => x.Amount);
                    var buy_price         = (decimal)trade_amount * (trade.Sum(x => x.Price * (decimal)x.Amount) / (decimal)trade_amount);
                    var sold_price        = (decimal)sell.Amount * sell.Price;
                    var stock_description = trade.FirstOrDefault().Stock.Name;
                    var remaining_amount  = trade.Sum(x => x.Amount) - sell.Amount;

                    var tradeVM = new TradeVM()
                    {
                        TransactionsBuy = trade.ToVM(),
                        TransactionSell = sell.ToVM(),
                        RemainingAmount = remaining_amount,
                        Description     = stock_description,
                        Amount          = sell.Amount,
                        GainOrLoss      = sold_price - buy_price,
                        Symbol          = stock_trade,
                        When            = sell.When,
                        Buy             = trade.Sum(x => x.Price * (decimal)x.Amount) / (decimal)trade_amount,
                        Sell            = sell.Price,
                        TotalBuy        = buy_price,
                        TotalSell       = sold_price,
                        TotalCost       = sell.Price * (decimal)sell.Amount
                    };

                    tradeStatementVM.Trades.Add(tradeVM);
                    tradeStatementVM.Month       = tradeVM.When.Month;
                    tradeStatementVM.Year        = tradeVM.When.Year;
                    tradeStatementVM.GainOrLoss += tradeVM.GainOrLoss;
                    tradeStatementVM.TotalCost  += tradeVM.TotalCost;
                }

                if (!vm.TradeStatements.Any(x => x.Month == tradeStatementVM.Month && x.Year == tradeStatementVM.Year))
                {
                    vm.TradeStatements.Add(tradeStatementVM);
                }
            }

            vm.TotalCost  = vm.TradeStatements.Sum(x => x.TotalCost);
            vm.MustPayTax = vm.TotalCost > 20000m;
            vm.GainOrLoss = vm.TradeStatements.Sum(x => x.GainOrLoss);

            return(vm);
        }