public ActionResult Buy(BuyModel model) { if (model.Quantity < 1) { TempData["BuyException"] = "Buying 0 stocks... Please try again"; return(RedirectToAction("ConfirmBuy", new { symbol = model.Symbol })); } decimal transactionCost = (decimal)TransactionCost.BuyCost * (model.Quantity * model.PurchasePrice); string[] temp = model.Symbol.Split(','); SailiRepository repository = new SailiRepository(); Buy buy = new Buy(); buy.TradeDate = DateTime.Now; buy.TickerSymbol = temp[0]; buy.Quantity = model.Quantity; buy.PurchasePrice = model.PurchasePrice; buy.TransactionAmount = model.Quantity * model.PurchasePrice + transactionCost; buy.TransactionCost = transactionCost; buy = repository.Finalizebuy(buy, User.Identity.GetUserId()); Owner owner = repository.GetOwner(User.Identity.GetUserId()); TraderAccount trader = repository.GetTrader(owner.OwnerID); return(RedirectToAction("Details", "TraderAccount", new { TradingAccountID = trader.TradingAccountID })); }
public PurchaseDTO Pay(int clientId, int purchaseId) { ClientService.CheckCredentials(clientId); Purchase purchase = PurchaseService.FindEntity(purchaseId); if (purchase.PayingTime != null) { throw new AppException("Already payed", 400); } decimal amount = purchase.Amount; ClientAccount source = ClientService.GetAccount(clientId); if (amount > source.Balance) { throw new AppException("Not enough money", 400); } TraderAccount target = TraderService.GetAccount(purchase.CommercialLink.TraderId); PaymentMonitor.Remove(purchaseId); source.Balance -= amount; target.Balance += amount; purchase.PayingTime = DateTime.Now; ClientAccountService.Update(source); TraderAccountService.Update(target); purchase = PurchaseService.Update(purchase); return(PurchaseService.EntityToDTO(purchase)); }
public ActionResult Create(string OwnerID) { if (OwnerID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var owner = DefaultConnection.Owners.Find(OwnerID); if (!owner.UserID.Equals(User.Identity.GetUserId())) { DataSerializer <string> .SecurityPriorityNumberOne(User.Identity.GetUserId()); return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } encryptionServices = new EncryptionServices(); TraderAccount model = new TraderAccount(); model.OwnerID = OwnerID; model = encryptionServices.EncryptTraderAccount(model); DefaultConnection.TraderAccounts.Add(new TraderAccount() { TradingAccountID = model.TradingAccountID, OwnerID = model.OwnerID, CreationDate = DateTime.Now, Balance = 1000000 }); DefaultConnection.SaveChanges(); return(RedirectToAction("Details", new { TradingAccountID = model.TradingAccountID.ToString() })); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Email,Credits")] TraderAccount traderAccount) { if (id != traderAccount.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(traderAccount); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TraderAccountExists(traderAccount.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(traderAccount)); }
private void StartGetData() { ServerLog.ClearList(); for (int i = 0; i < SiArray.Count; i++) { if (!RunningST.ContainsKey(SiArray[i].Market)) { string market = SiArray[i].Market; string dllname = TradeSDK.getDllName(market); Assembly assembly = Assembly.Load(TradeSDK.getSDK(dllname)); Type ClassTradeAPI = assembly.GetType(string.Format("{0}.TradeAPI", dllname.Substring(0, dllname.Length - 4))); Object ObjectTradeAPI = assembly.CreateInstance(ClassTradeAPI.FullName, true, BindingFlags.CreateInstance, null, new object[] { }, null, null); BaseTradeAPI bta = ((BaseTradeAPI)ObjectTradeAPI); RunningST.Add(market, bta); TraderAccount sa = new TraderAccount(bta); bta.queryDataArrival += queryArrival; if (showTradeView) { CurrentBalances.Insert(market); Trader trader = Trader.CreateTrader(sa); traders.Add(market, trader); frm_TradeMonitor tradeform = new frm_TradeMonitor(trader); tradeform.tradePolicyResult_Arrival += PolicyResultArraival; tradeform.tradeFunPolicyResult_Arrival += PolicyFunArraival; tradeform.Left = 0; tradeform.Top = 3 * logform.Height; tradeform.Show(); tradeform.ConnectTrade(); } } foreach (var st in RunningST) { BaseTradeAPI bta = ((BaseTradeAPI)st.Value); if (bta.AbortedWs) { bta.InitWebSocket(); } if (bta.market == SiArray[i].Market) { if (!bta.DicSi.ContainsKey(SiArray[i].Code)) { bta.DicSi.Add(SiArray[i].Code, SiArray[i]); CurrentTicker.Insert(SiArray[i].Market + SiArray[i].Code); } bta.Subscribe(SiArray[i].Code, "marketDepth", SiArray[i].Type); bta.Subscribe(SiArray[i].Code, "trade", SiArray[i].Type); if (showTradeView) { bta.Subscribe(SiArray[i].Code, "order", SiArray[i].Type); bta.Subscribe(SiArray[i].Code, "account", SiArray[i].Type); if (SiArray[i].Type != "spot") { bta.Subscribe(SiArray[i].Code, "position", SiArray[i].Type); } } } } } }
public ActionResult Create(TraderAccount model) { try { return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> Create([Bind("Id,Email,Credits")] TraderAccount traderAccount) { if (ModelState.IsValid) { _context.Add(traderAccount); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(traderAccount)); }
public ActionResult Sell(Sell model) { try { Buy buy = DefaultConnection.Buys.Find(model.BuyID); Portfolio portfolio = DefaultConnection.Portfolios.Find(buy.PortfolioId); SailiRepository repository = new SailiRepository(); Owner owner = new Owner(); owner = repository.GetOwner(User.Identity.GetUserId()); TraderAccount trader = new TraderAccount(); trader = repository.GetTrader(owner.OwnerID); if (model.Quantity > buy.Quantity) { TempData["SellException"] = "Selling more stocks than what is baught... Please try again"; return(RedirectToAction("ConfirmSell", new { tradingAccountID = portfolio.TradingAccountID, buyID = buy.BuyID })); } decimal transactionCost = (decimal)TransactionCost.SellCost * (model.Quantity * model.SoldPrice); model.PortfolioID = portfolio.PortfolioID; model.TradeDate = DateTime.Now; model.BuyID = buy.BuyID; model.TransactionCost = transactionCost; model.TransactionAmount = model.Quantity * model.SoldPrice - transactionCost; trader.Balance = trader.Balance + model.TransactionAmount; buy.Quantity = buy.Quantity - model.Quantity; TryUpdateModel(buy); DefaultConnection.Entry(buy).State = EntityState.Modified; DefaultConnection.SaveChanges(); TryUpdateModel(trader); DefaultConnection.Entry(trader).State = EntityState.Modified; DefaultConnection.SaveChanges(); TryUpdateModel(model); DefaultConnection.Sells.Add(model); DefaultConnection.SaveChanges(); return(RedirectToAction("Details", "TraderAccount", new { TradingAccountID = portfolio.TradingAccountID })); } catch { return(View(model)); } }
public ActionResult CheckStatusTrader(string OwnerID) { repository = new SailiRepository(); TraderAccount trader = new TraderAccount(); trader = repository.CheckTradingAccount(OwnerID); if (trader == null) { return(RedirectToAction("Create", new{ OwnerID = OwnerID })); } else { return(RedirectToAction("Details", "TraderAccount", new { TradingAccountID = trader.TradingAccountID.ToString() })); } }
/// <summary> /// 保证金是否足够 /// </summary> /// <param name="a"></param> /// <param name="count"></param> /// <returns></returns> public static bool IsBailSufficient(this TraderAccount a, decimal count) { return(a.BailAccount.Sum >= count * (1 + TraderService.CommissionRatio)); }