Beispiel #1
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 #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var parts = value?.ToString().Split('_');

            return(UserCoinKey.Get(parts?[0], parts?[1]));
        }