public MainWindowViewModel() { var passwordDlg = new PasswordDialog(); if (passwordDlg.ShowDialog() == true) { var password1 = passwordDlg.PasswordPwBox1.Password; var password2 = passwordDlg.PasswordPwBox2.Password; KeyStore.LogIn(password1, password2); KeyStore.GetApiKeys(); var apiUrl = KeyStore.InfuraMainnetKey; httpClient = new HttpClient(); Infura = new NodeModel(string.IsNullOrEmpty(KeyStore.InfuraMainnetKey) ? new EthereumNodeService("Infura", $"https://mainnet.infura.io", httpClient) : new EthereumNodeService("Infura", apiUrl, httpClient)); var client = new HttpClient(); WhaleAlert = new WhaleAlertModel(client, KeyStore.WhaleAlertKey); } //Infura = new NodeModel(new EthereumNodeService("Infura", "https://mainnet.infura.io")); //Local = new NodeModel(new EthereumNodeService("Local", "http://localhost:8545"), true, true); //Local = new NodeModel(new EthereumNodeService(new Web3("http://localhost:8546"))); }
static void Main(string[] args) { Console.WriteLine("Enter password1:"); var password1 = Console.ReadLine(); Console.WriteLine("Enter password2:"); var password2 = Console.ReadLine(); var keyStore = new MongoAtlasStore(); keyStore.LogIn(password1.Trim(), password2.Trim()); keyStore.GetApiKeys(); var cmcConn = new CMCConnection(new System.Net.Http.HttpClient()); var quotesTask = CryptoCurrencysRequest.GetQuotes(cmcConn, keyStore.CoinMarketCapApiKey, "BTC,ETH,EOS,USDT,BNB,ADA,MKR,USDC,TUSD,REP,PAX,DAI"); quotesTask.Wait(); var quote = quotesTask.Result; var cryptoQuote = CryptoCurrencies.FromJson(quote); decimal ethUsd = 0.00M; if (cryptoQuote.Data.ContainsKey("ETH")) { Datum data = null; if (cryptoQuote.Data.TryGetValue("ETH", out data)) { ethUsd = (decimal)data.Quote.Usd.Price; } } decimal btcUsd = 0.00M; if (cryptoQuote.Data.ContainsKey("BTC")) { Datum data = null; if (cryptoQuote.Data.TryGetValue("BTC", out data)) { btcUsd = (decimal)data.Quote.Usd.Price; } } StringBuilder quotes = new StringBuilder(); foreach (var data in cryptoQuote.Data) { quotes.Append($"{data.Key} = ${data.Value.Quote.Usd.Price}\n"); } Console.WriteLine(quotes); #region BTC //var btcAddrStr = File.ReadAllText(@"c:\Apps\Test\btc.txt").Trim(); //var btcAddresses = btcAddrStr.Split('|'); //IBlockchain btcBC = new BitcoinBlockchain(); //foreach (var btcAddress in btcAddresses) //{ // if (!string.IsNullOrEmpty(btcAddress.Trim())) // { // var addr = btcAddress.Split(','); // var balTask = btcBC.GetBalance(addr[0]); // balTask.Wait(); // Console.WriteLine($"{addr[1]} Balance = BTC:{balTask.Result}, ${balTask.Result * btcUsd}\n"); // } //} #endregion #region ETH //var addressStr = File.ReadAllText(@"c:\Apps\Test\eth.txt").Trim(); //var addresses = addressStr.Split('|'); //IBlockchain ethBC = new EtheriumBlockchain(); //foreach (var address in addresses) //{ // if (!string.IsNullOrEmpty(address.Trim())) // { // var addr = address.Split(','); // var balTask = ethBC.GetBalance(addr[0]); // balTask.Wait(); // Console.WriteLine($"{addr[1]} Balance = ETH:{balTask.Result}, ${balTask.Result * ethUsd}\n"); // } //} #endregion Console.ReadLine(); }
private async Task Refresh() { IsBusy = true; if (string.IsNullOrEmpty(keyStore.CoinMarketCapApiKey) || string.IsNullOrEmpty(keyStore.NomicsApiKey)) { if (string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Password2)) { RawData = "Password not set."; } else { keyStore = new MongoAtlasStore(); keyStore.LogIn(Password, Password2); keyStore.GetApiKeys(); } } string cmcMarketCap = null; if (!string.IsNullOrEmpty(keyStore.CoinMarketCapApiKey)) { cmcMarketCap = await GlobalMetricsRequest.GetGlobalMetrics(this.cmcConn, keyStore.CoinMarketCapApiKey).ConfigureAwait(false); } string nomicsMarketCap = null; string nomicsGlobalVol = null; if (!string.IsNullOrEmpty(keyStore.NomicsApiKey)) { nomicsMarketCap = await MarketHistoryRequest.GetMarketCapHistory(this.nomicsConn, keyStore.NomicsApiKey).ConfigureAwait(false); nomicsGlobalVol = await MarketHistoryRequest.GetGlobalVolumeHistory(this.nomicsConn, keyStore.NomicsApiKey).ConfigureAwait(false); } if (!string.IsNullOrEmpty(cmcMarketCap)) { if (cmcMarketCap == "Unauthorized") { RawData = cmcMarketCap; } else { SetPropertiesFromCMCGlobalMetrics(GlobalMetrics.FromJson(cmcMarketCap)); } } if (!string.IsNullOrEmpty(nomicsMarketCap)) { if (nomicsMarketCap == "Unauthorized") { RawData = nomicsMarketCap; } else { SetPropertiesFromNomicsMarketCapHistory(MarketCapHistory.FromJson(nomicsMarketCap)); } } if (!string.IsNullOrEmpty(nomicsGlobalVol)) { if (nomicsGlobalVol == "Unauthorized") { RawData = nomicsGlobalVol; } else { SetPropertiesFromNomicsMarketVolHistory(GlobalVolHistory.FromJson(nomicsGlobalVol)); } } IsBusy = false; }