CLI feature enhancement

-a option to profit.exe fetches information for all coins
This commit is contained in:
2014-04-01 09:58:58 -07:00
parent 0ed60e6059
commit aab69d7414
2 changed files with 83 additions and 60 deletions

View File

@@ -40,73 +40,18 @@ namespace profit
Console.WriteLine(" -h|--help this message");
Console.WriteLine(" -l|--list list coins configured in registry");
Console.WriteLine(" -c|--coin select coin to look up");
Console.WriteLine(" -a|--all look up all coins");
Console.WriteLine(" -b|--bitcoin report expected income in BTC");
Console.WriteLine(" -r|--hashrate override hashrate (provide in H/s)");
Console.WriteLine(" -x|--exchange override exchange (Bter or Cryptsy)");
Console.WriteLine(" -i|--interval select interval (provide in seconds, default=86400)");
}
static int Main(string[] args)
static int Lookup(string szSelectedCoin, decimal hashrate, bool bIncomeInBTC, long interval, string exchange, RegistrySettings rs)
{
RegistrySettings rs = new RegistrySettings();
Profitability p = new Profitability();
CoinInformation ci = new CoinInformation();
ExchangeInformation ei = new ExchangeInformation();
Getopt go = new Getopt("profit", args, "hlc:br:x:i:",
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')
});
int opt=-1;
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;
default:
Help();
return -1;
}
if (szSelectedCoin == "")
{
Console.WriteLine("No coin selected");
return -1;
}
CoinInfo inf = rs.Coins[szSelectedCoin];
double diff = 0;
try { diff = ci.GetDifficulty(inf.ExplorerType, inf.ExplorerBaseURL, inf.ExplorerChain); }
@@ -143,5 +88,80 @@ namespace profit
}
return 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);
}
}
}

View File

@@ -32,9 +32,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CoinProfitabilityLibrary">
<HintPath>..\CoinProfitabilityLibrary\bin\Release\CoinProfitabilityLibrary.dll</HintPath>
</Reference>
<Reference Include="Gnu.Getopt">
<HintPath>..\..\..\Visual Studio 2008\Projects\Gnu.Getopt\bin\Release\Gnu.Getopt.dll</HintPath>
</Reference>
@@ -49,6 +46,12 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CoinProfitabilityLibrary\CoinProfitabilityLibrary.csproj">
<Project>{f496f99c-a09d-40a0-bc87-5662893fcbb3}</Project>
<Name>CoinProfitabilityLibrary</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.