Beispiel #1
0
        private async void UpdateView(object state)
        {
            if (PoloniexClient != null)
            {
                if (semaphoreSlim != null)
                {
                    await semaphoreSlim.WaitAsync();

                    try
                    {
                        MarketService.Instance().MarketList = await PoloniexClient.Markets.GetSummaryAsync();

                        WalletService.Instance().WalletList = await PoloniexClient.Wallet.GetBalancesAsync();

                        try
                        {
                            FachadaWSSGSService.Instance().getUltimoValorVOResponse = await FachadaWSSGS.getUltimoValorVOAsync(10813);
                        }
                        catch
                        {
                        }

                        await ucHeader.LoadLoanOffersAsync(PoloniexClient);
                    }
                    finally
                    {
                        if (semaphoreSlim != null)
                        {
                            semaphoreSlim.Release();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public async Task LoadLoanOffersAsync(PoloniexClient PoloniexClient)
        {
            await Task.Run(async() =>
            {
                PublicLoanOffersData lendings = null;
                LendingOffer firstLoanOffer   = null;

                try
                {
                    lendings       = await PoloniexClient.Lendings.GetLoanOffersAsync("BTC");
                    firstLoanOffer = lendings.offers.OrderBy(x => x.rate).First();

                    if (MarketService.Instance().MarketList != null)
                    {
                        if (MarketService.Instance().MarketList.Any())
                        {
                            double ethPriceLast = MarketService.Instance().MarketList.First(x => x.Key.ToString().ToUpper().Equals("BTC_ETH")).Value.PriceLast;
                            double btcPriceLast = MarketService.Instance().MarketList.First(x => x.Key.ToString().ToUpper().Equals("USDT_BTC")).Value.PriceLast;

                            firstLoanOffer.ethExchangeValue = ethPriceLast;
                            firstLoanOffer.btcExchangeValue = btcPriceLast;


                            string dolarValor = FachadaWSSGSService.Instance().getUltimoValorVOResponse.getUltimoValorVOReturn.ultimoValor.svalor;

                            string eth     = string.Concat("BTC/ETH: ", firstLoanOffer.ethExchangeValue.ToString("0.00000000"));
                            string btc     = string.Concat("USDT/BTC: ", firstLoanOffer.btcExchangeValue.ToString("0.000000"));
                            string loan    = string.Concat("BTC Loan Rate: ", firstLoanOffer.rate.ToString("0.00000%"));
                            string dolar   = string.Concat("USD: ", double.Parse(dolarValor.Replace(".", ",")).ToString("C2"));
                            string btcReal = string.Concat("BTC: ", (firstLoanOffer.btcExchangeValue * double.Parse(dolarValor.Replace(".", ","))).ToString("C2"));

                            txtDisplay.Dispatcher.Invoke(DispatcherPriority.Background, (ThreadStart) delegate {
                                animation          = new DoubleAnimation((Application.Current.MainWindow.Width - 202), 0, TimeSpan.FromSeconds(10));
                                txtDisplay.Content = string.Concat(btc, "     ", eth, "     ", loan, "     ", dolar, "     ", btcReal);
                            });
                        }
                    }
                }
                finally
                {
                    lendings       = null;
                    firstLoanOffer = null;
                }
            });
        }
Beispiel #3
0
        private void LoadSummary()
        {
            try
            {
                if (WalletService.Instance().WalletList != null)
                {
                    if (WalletService.Instance().WalletList.Any())
                    {
                        double totalBTC = 0.0;

                        double btcTheterPriceLast = MarketService.Instance().MarketList.First(x => x.Key.ToString().ToUpper().Equals("USDT_BTC")).Value.PriceLast;

                        double valorDolarCompraBC = double.Parse(FachadaWSSGSService.Instance().getUltimoValorVOResponse.getUltimoValorVOReturn.ultimoValor.svalor.Replace(".", ","));

                        CurrencyPair currencyPair = CurrencyPair.Parse("BTC_ETH");

                        this.Dispatcher.Invoke(DispatcherPriority.Render, (ThreadStart)async delegate
                        {
                            dtgAccount.Items.Clear();


                            if (WalletService.Instance().WalletList != null)
                            {
                                foreach (var balance in WalletService.Instance().WalletList.Where(x => x.Value.btcValue > 0).ToList().OrderBy(x => x.Key).OrderByDescending(x => x.Value.btcValue))
                                {
                                    totalBTC = totalBTC + balance.Value.btcValue;

                                    if (balance.Value.btcValue > 0 && btcTheterPriceLast > 0 && valorDolarCompraBC > 0)
                                    {
                                        balance.Value.brzValue = Math.Round(Math.Round((btcTheterPriceLast * balance.Value.btcValue), 2) * valorDolarCompraBC, 2);

                                        balance.Value.marketValue = 0;

                                        if (MarketService.Instance().MarketList.Keys.Any(x => x.Equals(CurrencyPair.Parse("BTC_" + balance.Key))))
                                        {
                                            currencyPair = CurrencyPair.Parse(string.Concat("BTC_", balance.Key));

                                            var marketValue = MarketService.Instance().MarketList.First(x => x.Key.Equals(currencyPair)).Value.PriceLast;

                                            balance.Value.marketValue = marketValue;
                                        }

                                        else if (MarketService.Instance().MarketList.Keys.Any(x => x.Equals(CurrencyPair.Parse("XMR_" + balance.Key))))
                                        {
                                            currencyPair = CurrencyPair.Parse(string.Concat("XMR_", balance.Key));

                                            xmrBtcValue               = MarketService.Instance().MarketList.First(x => x.Key.Equals(CurrencyPair.Parse("BTC_XMR"))).Value.PriceLast;
                                            var marketValue           = MarketService.Instance().MarketList.First(x => x.Key.Equals(currencyPair)).Value.PriceLast;
                                            balance.Value.marketValue = marketValue * xmrBtcValue;
                                        }

                                        //else if (MarketService.Instance().MarketAsync.Keys.Where(x => x.BaseCurrency.Equals("USDT")).Contains(CurrencyPair.Parse("USDT_" + balance.Key)))
                                        else
                                        {
                                            currencyPair = CurrencyPair.Parse(string.Concat("USDT_", balance.Key));

                                            var usdtBtcValue          = MarketService.Instance().MarketList.First(x => x.Key.Equals(CurrencyPair.Parse("USDT_BTC"))).Value.PriceLast;
                                            var marketValue           = MarketService.Instance().MarketList.First(x => x.Key.Equals(currencyPair)).Value.PriceLast;
                                            balance.Value.marketValue = marketValue * usdtBtcValue;
                                        }

                                        dtgAccount.Items.Add(balance);
                                    }
                                }
                            }

                            var totalUSD     = Math.Round((btcTheterPriceLast * totalBTC), 2);
                            txtTotalBTC.Text = totalBTC.ToString("0.00000000");
                            txtTotalUSD.Text = totalUSD.ToString("000.00000000");
                            txtTotalBRL.Text = Math.Round(Math.Round(totalUSD * valorDolarCompraBC, 2), 2).ToString("C2").Replace("R$ ", "");

                            var calcTotalOpenOrders = await CalcTotalOpenOrders();
                            var totalOpenOrdersUSD  = Math.Round((btcTheterPriceLast * calcTotalOpenOrders), 2);

                            txtTotalOrders.Text      = (calcTotalOpenOrders).ToString("0.00000000");
                            txtTotalOrdersReais.Text = Math.Round(Math.Round(totalOpenOrdersUSD * valorDolarCompraBC, 2), 2).ToString("C2").Replace("R$ ", "");
                        });
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }