// Cryptsy has an API now...w00t!
 private decimal GetExchangeRateCryptsy(string abbrev)
 {
     RegistrySettings rs = new RegistrySettings();
     WebClient wc = new WebClient();
     //string extra = null;
     //foreach (KeyValuePair<string, CoinInfo> i in rs.Coins)
     //    if (i.Value.Abbreviation == abbrev)
     //        extra = i.Value.ExchangeExtraData;
     //if (extra == "")
     //    extra = null;
     string url="http://pubapi.cryptsy.com/api.php?method=orderdata";
     //if (extra != null)
     //    url = "http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=" + extra;
     if (CryptsyOrderData == "")
         CryptsyOrderData = wc.DownloadString(url);
     string data = CryptsyOrderData;
     var jss = new JavaScriptSerializer();
     var table = jss.Deserialize<dynamic>(data);
     return Convert.ToDecimal(table["return"][abbrev]["buyorders"][0]["price"]);
 }
Example #2
0
 static int Lookup(string szSelectedCoin, decimal hashrate, bool bIncomeInBTC, long interval, string exchange, RegistrySettings rs)
 {
     Profitability p = new Profitability();
     CoinInformation ci = new CoinInformation();
     ExchangeInformation ei = new ExchangeInformation();
     CoinInfo inf = rs.Coins[szSelectedCoin];
     double diff = 0;
     try { diff = ci.GetDifficulty(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); }
     catch { Console.WriteLine("Unable to fetch difficulty"); return -1; }
     decimal reward = 0;
     try { reward = ci.GetReward(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain, inf.Abbreviation); }
     catch { Console.WriteLine("Unable to fetch reward"); return -1; }
     if (hashrate == 0)
         switch (inf.DefaultHashRateUnit)
         {
             case "H/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate);
                 break;
             case "kH/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000;
                 break;
             case "MH/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 1000000;
                 break;
             case "GH/s":
                 hashrate = Convert.ToDecimal(inf.DefaultHashRate) * 100000000;
                 break;
             default:
                 throw new ArgumentException("invalid hashrate unit");
         }
     if (!bIncomeInBTC)
         Console.WriteLine(p.ProfitOnInterval(interval, hashrate, reward, (decimal)diff).ToString("F8"));
     else
     {
         decimal exchrate = 0;
         try { exchrate = (szSelectedCoin.ToLower() != "bitcoin") ? ei.GetExchangeRate((exchange != "") ? exchange : inf.Exchange, inf.Abbreviation) : 1; }
         catch { Console.WriteLine("Unable to fetch exchange rate"); return -1; }
         Console.WriteLine(p.ProfitOnIntervalBTC(interval, hashrate, reward, (decimal)diff, exchrate).ToString("F8"));
     }
     return 0;
 }
Example #3
0
        // Cryptsy has an API now...w00t!

        private decimal GetExchangeRateCryptsy(string abbrev)
        {
            RegistrySettings rs = new RegistrySettings();
            WebClient        wc = new WebClient();
            //string extra = null;
            //foreach (KeyValuePair<string, CoinInfo> i in rs.Coins)
            //    if (i.Value.Abbreviation == abbrev)
            //        extra = i.Value.ExchangeExtraData;
            //if (extra == "")
            //    extra = null;
            string url = "http://pubapi.cryptsy.com/api.php?method=orderdata";

            //if (extra != null)
            //    url = "http://pubapi.cryptsy.com/api.php?method=singleorderdata&marketid=" + extra;
            if (CryptsyOrderData == "")
            {
                CryptsyOrderData = wc.DownloadString(url);
            }
            string data  = CryptsyOrderData;
            var    jss   = new JavaScriptSerializer();
            var    table = jss.Deserialize <dynamic>(data);

            return(Convert.ToDecimal(table["return"][abbrev]["buyorders"][0]["price"]));
        }
Example #4
0
        static int Main(string[] args)
        {
            RegistrySettings rs = new RegistrySettings();
            Getopt go = new Getopt("profit", args, "hlc:br:x:i:a",
                new LongOpt[]
                {
                    new LongOpt("help", Argument.No, null, 'h'),
                    new LongOpt("list", Argument.No, null, 'l'),
                    new LongOpt("coin", Argument.Required, null, 'c'),
                    new LongOpt("bitcoin", Argument.No, null, 'b'),
                    new LongOpt("hashrate", Argument.Required, null, 'r'),
                    new LongOpt("exchange", Argument.Required, null, 'x'),
                    new LongOpt("interval", Argument.Required, null, 'i'),
                    new LongOpt("all", Argument.No, null, 'a')
                });
            int opt=-1;
            bool bLookUpAll = false;
            bool bIncomeInBTC = false;
            string szSelectedCoin = "";
            foreach (string name in rs.GetCoinTypes())
                if (name.ToLower()=="bitcoin")
                    szSelectedCoin = name;
            decimal hashrate = 0;
            string exchange = "";
            long interval = 86400;

            while ((opt=go.getopt())!=-1)
                switch (opt)
                {
                    case 'h':
                        Help();
                        return 0;
                    case 'l':
                        foreach (string name in rs.GetCoinTypes())
                            Console.WriteLine(name);
                        return 0;
                    case 'c':
                        szSelectedCoin = go.Optarg;
                        break;
                    case 'b':
                        bIncomeInBTC = true;
                        break;
                    case 'r':
                        hashrate = Convert.ToDecimal(go.Optarg);
                        break;
                    case 'x':
                        exchange = go.Optarg;
                        break;
                    case 'i':
                        interval = Convert.ToInt64(go.Optarg);
                        break;
                    case 'a':
                        bLookUpAll = true;
                        break;
                    default:
                        Help();
                        return -1;
                }
            if (bLookUpAll)
            {
                foreach (string name in rs.GetCoinTypes())
                {
                    Console.Write(name + ": ");
                    Lookup(name, hashrate, bIncomeInBTC, interval, exchange, rs);
                }
                return 0;
            }
            if (szSelectedCoin == "")
            {
                Console.WriteLine("No coin selected");
                return -1;
            }
            return Lookup(szSelectedCoin, hashrate, bIncomeInBTC, interval, exchange, rs);
        }