performance improvements, CoinChoose support
Since scraping coin explorers is getting somewhat iffy, you can now use CoinChoose to get difficulty and reward information for the coins that are listed there. Also, the library buffers data received from CoinChoose and Cryptsy for reuse, which speeds things up when you're (for instance) using the CLI to list all coins.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Express 2012 for Windows Desktop
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoinProfitability", "CoinProfitability\CoinProfitability.csproj", "{583376E1-A666-4199-8ACE-7B7CBC734C56}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{F496F99C-A09D-40A0-BC87-5662893FCBB3} = {F496F99C-A09D-40A0-BC87-5662893FCBB3}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
// Coin Profitability Calculator
|
||||
//
|
||||
@@ -29,12 +30,16 @@ namespace ScottAlfter.CoinProfitabilityLibrary
|
||||
{
|
||||
public class CoinInformation
|
||||
{
|
||||
private string CoinChooseJSONData = "";
|
||||
|
||||
// wrapper to get current block reward
|
||||
|
||||
public decimal GetReward(string chain_type, string url_prefix, string chain_name)
|
||||
{
|
||||
switch (chain_type)
|
||||
{
|
||||
case "CoinChoose":
|
||||
return GetRewardCoinChoose(chain_name);
|
||||
case "Abe":
|
||||
return GetRewardAbe(url_prefix, chain_name);
|
||||
case "BlockEx":
|
||||
@@ -44,6 +49,24 @@ namespace ScottAlfter.CoinProfitabilityLibrary
|
||||
}
|
||||
}
|
||||
|
||||
// get block reward from CoinChoose
|
||||
|
||||
private decimal GetRewardCoinChoose(string chain_name)
|
||||
{
|
||||
if (CoinChooseJSONData == "")
|
||||
{
|
||||
WebClient wc = new WebClient();
|
||||
CoinChooseJSONData = wc.DownloadString("http://www.coinchoose.com/api.php?base=BTC");
|
||||
}
|
||||
string jsondata = CoinChooseJSONData;
|
||||
var jss = new JavaScriptSerializer();
|
||||
var table = jss.Deserialize<dynamic>(jsondata);
|
||||
foreach (var row in table)
|
||||
if (row["name"].ToLower() == chain_name.ToLower())
|
||||
return Convert.ToDecimal(row["reward"]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get block reward from most recent block on an Abe blockchain explorer
|
||||
|
||||
private decimal GetRewardAbe(string url_prefix, string chain_name)
|
||||
@@ -125,6 +148,8 @@ namespace ScottAlfter.CoinProfitabilityLibrary
|
||||
{
|
||||
switch (chain_type)
|
||||
{
|
||||
case "CoinChoose":
|
||||
return GetDifficultyCoinChoose(chain_name);
|
||||
case "Abe":
|
||||
double difficulty = -1;
|
||||
try { difficulty = GetDifficultyAbe(url_prefix, chain_name); }
|
||||
@@ -145,6 +170,24 @@ namespace ScottAlfter.CoinProfitabilityLibrary
|
||||
}
|
||||
}
|
||||
|
||||
// get difficulty from CoinChoose
|
||||
|
||||
private double GetDifficultyCoinChoose(string chain_name)
|
||||
{
|
||||
if (CoinChooseJSONData == "")
|
||||
{
|
||||
WebClient wc = new WebClient();
|
||||
CoinChooseJSONData = wc.DownloadString("http://www.coinchoose.com/api.php?base=BTC");
|
||||
}
|
||||
string jsondata = CoinChooseJSONData;
|
||||
var jss = new JavaScriptSerializer();
|
||||
var table = jss.Deserialize<dynamic>(jsondata);
|
||||
foreach (var row in table)
|
||||
if (row["name"].ToLower() == chain_name.ToLower())
|
||||
return Convert.ToDouble(row["difficulty"]);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// get difficulty (only works with newer Abe servers)
|
||||
|
||||
private double GetDifficultyAbe(string url_prefix, string chain_name)
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace ScottAlfter.CoinProfitabilityLibrary
|
||||
{
|
||||
public class ExchangeInformation
|
||||
{
|
||||
private string CryptsyOrderData = "";
|
||||
|
||||
// exchange rate wrapper
|
||||
|
||||
public decimal GetExchangeRate(string exchange, string abbrev)
|
||||
@@ -62,16 +64,18 @@ namespace ScottAlfter.CoinProfitabilityLibrary
|
||||
{
|
||||
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 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;
|
||||
string data = wc.DownloadString(url);
|
||||
//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"]);
|
||||
|
||||
10
README
10
README
@@ -1,4 +1,4 @@
|
||||
Is that altcoin you're considering more profitable than what you're currently mining? http://dustcoin.com/mining and http://www.coinchoose.com/ have some altcoins listed, but not all of them. (For instance, neither of them have Yacoin listed.) This little app I knocked together will tell you how much to expect.
|
||||
Is that altcoin you're considering more profitable than what you're currently mining? http://dustcoin.com/mining and http://www.coinchoose.com/ have some altcoins listed, but not all of them. (For instance, neither of them have Bitgem listed.) This little app I knocked together will tell you how much to expect.
|
||||
|
||||
It needs these to do its calculation:
|
||||
|
||||
@@ -12,13 +12,13 @@ You most likely know your hashrate for SHA-256 and scrypt coins. Difficulty is
|
||||
|
||||
I built this in Visual Studio 2012 Express against .NET Framework 4.0 (needed that version because it's the first that includes BigInteger support). I've also tested it under Mono; its implementation of Decimal.ToString() is a bit different and needed some adjustment.
|
||||
|
||||
You can store configuration information for the coins of your choice in the registry, and to select a coin from a drop-down list. A sample registry file (with configurations for five coins) is included. Most items are self-explanatory. Valid choices for ExplorerType are BlockEx (for blockexplorer.com and blockchain.info) and Abe (for block explorers running Abe). DefaultHashRate is optional; you can set it to whatever's appropriate for your hardware.
|
||||
You can store configuration information for the coins of your choice in the registry, and to select a coin from a drop-down list. A sample registry file (with configurations for seven coins) is included. Most items are self-explanatory. Valid choices for ExplorerType are BlockEx (for blockexplorer.com and blockchain.info), Abe (for block explorers running Abe), and CoinChoose (which you can use for the coins they follow). DefaultHashRate is optional; you can set it to whatever's appropriate for your hardware.
|
||||
|
||||
To select an exchange to use to convert a coin value to Bitcoinm just create a string value named Exchange. You can set this to either Bter or Cryptsy. Also, create another string value named Abbreviation; set it to the common three-character abbreviation (such as LTC for Litecoin). As long as the exchange you use supports the altcoin you want, either should work. Implementation of support for other exchanges is left as an exercise for the reader. For Bitcoin, the exchange rate is automatically set to 1.
|
||||
To select an exchange to use to convert a coin value to Bitcoin, just create a string value named Exchange. You can set this to either Bter or Cryptsy. Also, create another string value named Abbreviation; set it to the common three-character abbreviation (such as LTC for Litecoin). As long as the exchange you use supports the altcoin you want, either should work. Implementation of support for other exchanges is left as an exercise for the reader. For Bitcoin, the exchange rate is automatically set to 1.
|
||||
|
||||
If you don't have any configuration stored in the registry, an error will pop up at startup. On Windows, import CoinProfitability.reg. On Linux, unpack CoinProfitability.reg.tar.gz in your home directory. If you don't want any configuration information, you can ignore the error.
|
||||
|
||||
This release introduces two new components: CoinProfitLibrary and profit.exe. CoinProfitLibrary is a DLL that provides the core functionality for the two included apps. profit.exe is a simple command-line client you can use in your scripts. Help is available with the -h or --help options; read it to learn what you can do. By default, it will calculate Bitcoin mining revenue per day. It uses the same registry settings as the GUI.
|
||||
This release provides three components: CoinProfitLibrary, CoinProfitability.exe, and profit.exe. CoinProfitLibrary is a DLL that provides the core functionality for the two included apps. profit.exe is a simple command-line client you can use in your scripts. Help is available with the -h or --help options; read it to learn what you can do. By default, it will calculate Bitcoin mining revenue per day. It uses the same registry settings as the GUI.
|
||||
|
||||
profit.exe also depends on GNU Getopt .NET:
|
||||
|
||||
@@ -33,4 +33,4 @@ https://bitcointalk.org/index.php?topic=213580
|
||||
Scott Alfter
|
||||
scott@alfter.us
|
||||
|
||||
(last updated: 31 May 2013)
|
||||
(last updated: 6 May 2014)
|
||||
|
||||
Reference in New Issue
Block a user