Beispiel #1
0
        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));
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        public decimal GetTotalPercentage(CoinMarketTicker ticker, UserCoin coin)
        {
            if (ticker == null || ticker.Market != UserTickerMarket)
            {
                return(0);
            }

            return((ticker.Last * coin.Quantity) / user.UserSummary.TotalBalance * 100m);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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());
        }
Beispiel #6
0
        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"));
        }