Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Get Bytecent Price in $USD
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Net; using System.IO; namespace Rextester { public class Program { public static void Main(string[] args) { // display Console.WriteLine(String.Format("BTC/USD\t\t${0}",getBitcoinInUSD())); Console.WriteLine(String.Format("BTC/BYC\t\t{0}",getBytecentInBTC())); Console.WriteLine(String.Format("BYC/USD\t\t${0}",getBytecentInUSD(4))); } private static decimal getBitcoinInUSD() { // get BTC string btc = getWebResponse("https://www.bitstamp.net/api/ticker/"); int pos1 = btc.IndexOf("last", 0); int pos2 = btc.IndexOf(":", pos1); int pos3 = btc.IndexOf(",", pos2); return Convert.ToDecimal(btc.Substring(pos2+3, pos3-pos2-4)); } private static decimal getBytecentInBTC() { // get BYC string byc = getWebResponse("https://bittrex.com/api/v1.1/public/getticker?market=BTC-BYC"); int pos1 = byc.IndexOf("Last", 0); int pos2 = byc.IndexOf(":", pos1); int pos3 = byc.IndexOf("}", pos2); return Convert.ToDecimal(byc.Substring(pos2+1, pos3-pos2-1)); } private static decimal getBytecentInUSD(int decimalPlaces) { decimal bycRate = getBytecentInBTC(); decimal btcRate = getBitcoinInUSD(); return Math.Round(btcRate*bycRate, decimalPlaces); } public static string getWebResponse(string url) { // create request.. HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); // use GET method webRequest.Method = "GET"; // POST! HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); // read response into StreamReader Stream responseStream = webResponse.GetResponseStream(); StreamReader _responseStream = new StreamReader(responseStream); // get raw result return _responseStream.ReadToEnd(); } } }
run
|
edit
|
history
|
help
0
test
max & min binary search tree
ds
5. Generics
Anagrams String
sdrfgthyuytgrfdwcd
Write a program to sort given array using bubble sort.
Sum of digits in a string
aaa
DaysOfYear