public async Task <IActionResult> MarkCoin([FromBody] UserCoinDto userCoinDto) { var user = _applicationRepository.Find(new User(), userCoinDto.UserId); if (user == null) { return(BadRequest("Can not find user")); } UserCoin userCoin = await _applicationRepository.FindCoinById(user, userCoinDto.CoinId); if (userCoin == null) { userCoin = new UserCoin { User = user, CoinId = userCoinDto.CoinId }; //Mark as favorite _applicationRepository.Add(userCoin); } else { //Unmark from favorites _applicationRepository.Delete(userCoin); } await _applicationRepository.SaveAll(); return(Ok(userCoin)); }
public void SetPositions(string exchange, IList <ProxyPositionData> positions) { var pos = user.UserPositions.GetOrAddEmpty(exchange); pos.Clear(); foreach (var position in positions) { var userCoinKey = UserCoinKey.Get(position.Coin, position.Exchange); var userCoin = user.UserCoins.Get(userCoinKey); var coinTicker = GetTicker(position.Coin, position.Exchange)?.Last ?? 0m; var balance = position.Quantity * coinTicker; if (userCoin != null) { userCoin.MergePosition(balance, position.Available, position.Pending, position.BuyPrice); } else { userCoin = new UserCoin(position.Coin, position.Exchange, balance, position.Available, position.Pending, position.BuyPrice, null); user.UserCoins.TryAdd(userCoin.UniqueName, userCoin); } pos.Add(userCoin); } }
public decimal GetTotalPercentage(CoinMarketTicker ticker, UserCoin coin) { if (ticker == null || ticker.Market != UserTickerMarket) { return(0); } return((ticker.Last * coin.Quantity) / user.UserSummary.TotalBalance * 100m); }
public decimal GetProfitPercentage(CoinMarketTicker ticker, UserCoin coin) { if (ticker == null || coin.BuyPrice == 0 || ticker.Market != UserTickerMarket) { return(0); } return((ticker.Last - coin.BuyPrice) / coin.BuyPrice * 100m); }
public ActionResult RemoveFromWatchList(int id) { var userID = User.Identity.GetUserId(); var UserCoin = new UserCoin { UserID = userID, CoinID = id }; _context.UserCoins.Remove(UserCoin); _context.SaveChanges(); return(View()); }
public ActionResult AddToWatchList(int id) { var userID = User.Identity.GetUserId(); var UserCoin = new UserCoin { UserID = userID, CoinID = id }; _context.UserCoins.Add(UserCoin); _context.SaveChanges(); return(RedirectToAction("ViewMarket", "Market")); }