public async Task <CoinStats> GetCoinStats(string symbol) { return(await _memoryCache.GetOrCreateAsync(symbol, async x => { var coin = _coinBySymbolLookup[symbol]; var priceHistory = await _coinGeckoClient.GetCoinPriceHistory(coin.Id); var coinStats = new CoinStats(coin, priceHistory); _memoryCache.Set(symbol, coinStats, TimeSpan.FromHours(1)); return coinStats; })); }
public static CoinStats GetCoinStats(string product) { string baseUrl = "https://api.gdax.com/"; HttpWebRequest statsRequest = (HttpWebRequest)WebRequest.Create(baseUrl + "products/" + product + "/stats"); statsRequest.Method = WebRequestMethods.Http.Get; statsRequest.ContentType = "application/json; charset=utf-8"; statsRequest.UserAgent = "Test Blockchain Stats Application"; HttpWebResponse statsResponse = statsRequest.GetResponse() as HttpWebResponse; using (Stream responseStream = statsResponse.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream, Encoding.UTF8); CoinStats stats = JsonConvert.DeserializeObject <CoinStats>(reader.ReadToEnd()); return(stats); } }
public static void Main(string[] args) { CoinStats coinStats = BitStats.GetCoinStats("BTC-USD"); BlockList blockHash = BitStats.GetBlockStats(); // Configure window Application.Init(); win = new MainWindow(); win.Title = "BitTracker"; //win.KeepAbove = true; HBox hbox1 = new HBox(false, 5); HBox hbox2 = new HBox(false, 5); VBox vbox = new VBox(false, 5); win.Add(vbox); vbox.PackStart(hbox1, false, false, 10); vbox.PackStart(hbox2, false, false, 10); // Display 24-hour coin stats float coinStatsChange = ((coinStats.last / coinStats.open) * 100 - 100); string coinStatsLabelString = "Opening:\t\t" + coinStats.open.ToString("0.00") + "\nCurrent:\t\t" + coinStats.last.ToString("0.00") + "\nChange\t\t" + coinStatsChange.ToString("0.00") + "%" + (coinStatsChange > 0 ? "\u2191" : "\u2193"); Label coinStatsLabel = new Label(); coinStatsLabel.Text = coinStatsLabelString; Frame coinStatsFrame = new Frame(); coinStatsFrame.Label = "24-hour Stats"; coinStatsFrame.Add(coinStatsLabel); hbox1.PackStart(coinStatsFrame, false, false, 10); // Persistence of toggle ToggleButton persToggle = new ToggleButton("Keep on Top"); persToggle.Clicked += persToggleCallback; hbox1.PackStart(persToggle, false, false, 10); // Display blocks string prevblockHash = blockHash.blocks[0].hash; DateTime unixTimeBase = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); Table blockStatsTable = new Table(3, 6, false); blockStatsTable.SetColSpacing(0, 15); blockStatsTable.SetColSpacing(1, 15); Frame blockStatsFrame = new Frame(); blockStatsFrame.Add(blockStatsTable); hbox2.PackStart(blockStatsFrame, false, false, 10); Label blockStatsLabel1 = new Label(); blockStatsLabel1.Text = "Hash"; Label blockStatsLabel2 = new Label(); blockStatsLabel2.Text = "Height"; Label blockStatsLabel3 = new Label(); blockStatsLabel3.Text = "Time"; blockStatsTable.Attach(blockStatsLabel1, 0, 1, 0, 1); blockStatsTable.Attach(blockStatsLabel2, 1, 2, 0, 1); blockStatsTable.Attach(blockStatsLabel3, 2, 3, 0, 1); List <Label> blockHashLabel = new List <Label>() { new Label(), new Label(), new Label(), new Label(), new Label() }; List <Label> blockHeightLabel = new List <Label>() { new Label(), new Label(), new Label(), new Label(), new Label() }; List <Label> blockTimeLabel = new List <Label>() { new Label(), new Label(), new Label(), new Label(), new Label() }; for (int i = 0; i < 5; i++) { blockHashLabel[i].Text = blockHash.blocks[i].hash; blockHashLabel[i].SetAlignment(0, 1); blockStatsTable.Attach(blockHashLabel[i], 0, 1, 1 + (uint)i, 2 + (uint)i); blockHeightLabel[i].Text = blockHash.blocks[i].height.ToString(); blockHeightLabel[i].SetAlignment(0, 1); blockStatsTable.Attach(blockHeightLabel[i], 1, 2, 1 + (uint)i, 2 + (uint)i); DateTime blockHashTime = unixTimeBase.AddSeconds(blockHash.blocks[i].time); blockTimeLabel[i].Text = blockHashTime.ToString("MM/dd/yy H:mm UTC"); blockTimeLabel[i].SetAlignment(0, 1); blockStatsTable.Attach(blockTimeLabel[i], 2, 3, 1 + (uint)i, 2 + (uint)i); } // Update stats uint timer = GLib.Timeout.Add(10000, new GLib.TimeoutHandler(() => { // Coin stats coinStats = BitStats.GetCoinStats("BTC-USD"); coinStatsChange = ((coinStats.last / coinStats.open) * 100 - 100); coinStatsLabelString = "Opening:\t\t" + coinStats.open.ToString("0.00") + "\nCurrent:\t\t" + coinStats.last.ToString("0.00") + "\nChange\t\t" + coinStatsChange.ToString("0.00") + "%" + (coinStatsChange > 0 ? "\u2191" : "\u2193"); coinStatsLabel.Text = coinStatsLabelString; // Blocks blockHash = BitStats.GetBlockStats(); if (blockHash.blocks[0].hash == prevblockHash) { prevblockHash = blockHash.blocks[0].hash; for (int i = 0; i < 5; i++) { blockHashLabel[i].Text = blockHash.blocks[i].hash; blockHeightLabel[i].Text = blockHash.blocks[i].height.ToString(); DateTime blockHashTime = unixTimeBase.AddSeconds(blockHash.blocks[i].time); blockTimeLabel[i].Text = blockHashTime.ToString("MM/dd/yy H:mm UTC"); } } return(true); })); win.ShowAll(); Application.Run(); }
private MiningStats MapDTO(ClaymoreMessageDTO dto) { var entity = new MiningStats(); entity.MinerVersion = dto.Result[0]; entity.UptimeMinutes = int.Parse(dto.Result[1]); var primaryCoinHashrateAndShares = dto.Result[2].Split(";"); var primaryHashratesPerGPU = dto.Result[3].Split(";"); var secondaryCoinHashrateAndShares = dto.Result[4].Split(";"); var secondaryHashratesPerGPU = dto.Result[5].Split(";"); var temperaturesAndFanSpeedsPerGPU = dto.Result[6].Split(";"); var poolAddresses = dto.Result[7].Split(";"); var invalidsAndSwitches = dto.Result[8].Split(";"); var primaryCoin = new CoinStats(); primaryCoin.PoolAddress = poolAddresses[0]; primaryCoin.Hashrate = long.Parse(primaryCoinHashrateAndShares[0]); primaryCoin.Shares = int.Parse(primaryCoinHashrateAndShares[1]); primaryCoin.RejectedShares = int.Parse(primaryCoinHashrateAndShares[2]); primaryCoin.InvalidShares = int.Parse(invalidsAndSwitches[0]); primaryCoin.PoolSwitches = int.Parse(invalidsAndSwitches[1]); entity.PrimaryCoin = primaryCoin; entity.SecondaryCoin = null; if (poolAddresses.Length == 2) { var secondaryCoin = new CoinStats(); secondaryCoin.PoolAddress = poolAddresses[1]; secondaryCoin.Hashrate = long.Parse(secondaryCoinHashrateAndShares[0]); secondaryCoin.Shares = int.Parse(secondaryCoinHashrateAndShares[1]); secondaryCoin.RejectedShares = int.Parse(secondaryCoinHashrateAndShares[2]); secondaryCoin.InvalidShares = int.Parse(invalidsAndSwitches[2]); secondaryCoin.PoolSwitches = int.Parse(invalidsAndSwitches[3]); entity.SecondaryCoin = secondaryCoin; } var gpuList = new List <GPUStats>(); entity.GPUStats = gpuList; for (var i = 0; i < primaryHashratesPerGPU.Length; i++) { var gpuStat = new GPUStats(); var primaryHashrate = long.Parse(primaryHashratesPerGPU[i]); var rawSecondaryHashrate = secondaryHashratesPerGPU[i]; var secondaryHashrate = rawSecondaryHashrate == "off" ? (long?)null : long.Parse(rawSecondaryHashrate); var temperature = int.Parse(temperaturesAndFanSpeedsPerGPU[i * 2]); var fanspeed = int.Parse(temperaturesAndFanSpeedsPerGPU[i * 2 + 1]); gpuStat.PrimaryHashrate = primaryHashrate; gpuStat.SecondaryHashrate = secondaryHashrate; gpuStat.Temperature = temperature; gpuStat.FanSpeed = fanspeed; gpuList.Add(gpuStat); } return(entity); }