public async Task GetMultipleBalancesUDTValue_BTC_BNB()
        {
            // Arrange
            var exchangeApi     = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.Standard);
            var exchangeService = new WpfExchangeService(exchangeApi);
            var symbolsCache    = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            await symbolsCache.GetSymbols(new[] { "BNBBTC" });

            var balances = new List <Core.Model.AccountBalance>
            {
                new Core.Model.AccountBalance {
                    Asset = "BTC", Free = 0.00396715m
                },
                new Core.Model.AccountBalance {
                    Asset = "BNB", Free = 0.94444141m
                }
            };

            var accountInfo = new Core.Model.AccountInfo();

            accountInfo.Balances.AddRange(balances);

            var account = new Account(accountInfo);

            // Act
            symbolsCache.ValueAccount(account);

            // Assert
            Assert.AreEqual(account.USDTValue, 50.51m);
            Assert.AreEqual(account.BTCValue, 0.00534226m);
        }
        public async Task GetSingleBalanceUDTValue_BNB()
        {
            // Arrange
            var exchangeApi     = ExchangeServiceHelper.GetExchangeService(ExchangeServiceType.Standard);
            var exchangeService = new WpfExchangeService(exchangeApi);
            var symbolsCache    = SymbolsCacheHelper.GetSymbolsCache(exchangeService);
            await symbolsCache.GetSymbols(new[] { "BNBBTC" });

            var balances = new List <Core.Model.AccountBalance>
            {
                new Core.Model.AccountBalance {
                    Asset = "BNB", Free = 1.88373641m
                }
            };

            var accountInfo = new Core.Model.AccountInfo();

            accountInfo.Balances.AddRange(balances);

            var account = new Account(accountInfo);

            // Act
            symbolsCache.ValueAccount(account);

            // Assert
            Assert.AreEqual(account.USDTValue, 25.93m);
            Assert.AreEqual(account.BTCValue, 0.00274272m);
        }
Exemple #3
0
        private static Core.Model.AccountInfo GetAccountInfo(AccountInfo a)
        {
            var accountInfo = new Core.Model.AccountInfo
            {
                Exchange    = Exchange.Binance,
                Commissions = new Core.Model.AccountCommissions {
                    Buyer = a.Commissions.Buyer, Maker = a.Commissions.Maker, Seller = a.Commissions.Seller, Taker = a.Commissions.Taker
                },
                Status = new Core.Model.AccountStatus {
                    CanDeposit = a.Status.CanDeposit, CanTrade = a.Status.CanTrade, CanWithdraw = a.Status.CanWithdraw
                },
                Time = a.Time
            };

            var balances = a.Balances.Where(b => b.Free > 0 || b.Locked > 0);

            foreach (var balance in balances)
            {
                accountInfo.Balances.Add(new Core.Model.AccountBalance {
                    Asset = balance.Asset, Free = balance.Free, Locked = balance.Locked
                });
            }

            return(accountInfo);
        }
Exemple #4
0
        private void AccountInfoUpdate(Core.Model.AccountInfo e)
        {
            Action <Core.Model.AccountInfo> action = aie =>
            {
                lock (balancesLock)
                {
                    if (!aie.Balances.Any())
                    {
                        Account.Balances.Clear();
                        return;
                    }

                    Func <AccountBalance, Core.Model.AccountBalance, AccountBalance> f = ((ab, nb) =>
                    {
                        ab.Free = nb.Free;
                        ab.Locked = nb.Locked;
                        return(ab);
                    });

                    var balances = (from ab in Account.Balances
                                    join nb in aie.Balances on ab.Asset equals nb.Asset
                                    select f(ab, nb)).ToList();

                    var remove = Account.Balances.Where(ab => !aie.Balances.Any(nb => nb.Asset.Equals(ab.Asset, StringComparison.Ordinal))).ToList();
                    foreach (var ob in remove)
                    {
                        Account.Balances.Remove(ob);
                    }

                    var add = aie.Balances.Where(nb => !Account.Balances.Any(ab => ab.Asset.Equals(nb.Asset, StringComparison.Ordinal))).ToList();
                    foreach (var nb in add)
                    {
                        Account.Balances.Add(new AccountBalance {
                            Asset = nb.Asset, Free = nb.Free, Locked = nb.Locked
                        });
                    }
                }
            };

            if (Dispatcher == null)
            {
                action(e);
            }
            else
            {
                Dispatcher.Invoke(action, e);
            }

            AccountNotification(new AccountEventArgs {
                Value = Account, AccountEventType = AccountEventType.UpdateOrders
            });
        }
Exemple #5
0
        public void CreateAccountInstance_Pass()
        {
            // Arrange
            var accountInfo = new Core.Model.AccountInfo {
                User = user
            };

            accountInfo.Balances.AddRange(balances);

            // Act
            var account = new Account(accountInfo);

            // Assert
            Assert.IsTrue(account.ApiKey.Equals(apiKey));
            Assert.IsTrue(account.Balances.Count.Equals(1));
            Assert.IsNotNull(account.Balances.Single(b => b.Asset.Equals("TRX")));
            Assert.IsTrue(string.IsNullOrWhiteSpace(account.ApiSecret));
        }
Exemple #6
0
        public Account(Core.Model.AccountInfo accountInfo)
        {
            AccountInfo = accountInfo;

            if (!string.IsNullOrWhiteSpace(AccountInfo?.User?.ApiSecret))
            {
                apiSecret = secretText;
            }

            Balances = new ObservableCollection <AccountBalance>();

            foreach (var balance in AccountInfo.Balances)
            {
                Balances.Add(new AccountBalance {
                    Asset = balance.Asset, Free = balance.Free, Locked = balance.Locked
                });
            }

            OnPropertyChanged(nameof(ApiKey));
            OnPropertyChanged(nameof(Balances));
        }