Skip to content

Commit

Permalink
Merge pull request #1 from jtbarclay/master
Browse files Browse the repository at this point in the history
Use WhatToMine
  • Loading branch information
metalicjames authored Dec 7, 2016
2 parents 8ab4c58 + 5577548 commit 698f09f
Showing 1 changed file with 34 additions and 37 deletions.
71 changes: 34 additions & 37 deletions src/HandlerExample/HandlerClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ public static void HandleOrder(ref Order OrderStats, ref double MaxPrice, ref do
if (OrderStats == null) return;

// Retreive JSON data from API server. Replace URL with your own API request URL.
string JSONData = GetHTTPResponseInJSON("http://www.coinwarz.com/v1/api/coininformation/?apikey=<API_KEY>&cointag=<COIN>");
string JSONData = GetHTTPResponseInJSON("http://www.whattomine.com/coins/<COIN>.json");
if (JSONData == null) return;

// Serialize returned JSON data.
CoinwarzResponse Response;
WhattomineResponse Response;
try
{
Response = JsonConvert.DeserializeObject<CoinwarzResponse>(JSONData);
Response = JsonConvert.DeserializeObject<WhattomineResponse>(JSONData);
}
catch
{
return;
}

// Check if exchange rate is provided - at least one exchange must be included.
if (Response.Data.ExchangeRates.Length == 0) return;
double ExchangeRate = Response.Data.ExchangeRates[0].ToBTC;
//if (Response.Length == 0) return;
double ExchangeRate = Response.exchange_rate;

// Calculate mining profitability in BTC per 1 TH of hashpower.
double HT = Response.Data.Difficulty * (Math.Pow(2.0, 32) / (1000000000000.0));
double CPD = Response.Data.BlockReward * 24.0 * 3600.0 / HT;
double HT = Response.difficulty * (Math.Pow(2.0, 32) / (1000000000000.0));
double CPD = Response.block_reward * 24.0 * 3600.0 / HT;
double C = CPD * ExchangeRate;

// Subtract service fees.
Expand All @@ -63,38 +63,35 @@ public static void HandleOrder(ref Order OrderStats, ref double MaxPrice, ref do
/// Data structure used for serializing JSON response from CoinWarz.
/// It allows us to parse JSON with one line of code and easily access every data contained in JSON message.
/// </summary>
#pragma warning disable 0649
class CoinwarzResponse
#pragma warning disable 0649
class WhattomineResponse
{
public bool Success;
public string Message;

public class DataStruct
{
public string CoinName;
public string CoinTag;
public int BlockCount;
public double Difficulty;
public double BlockReward;
public bool IsBlockExplorerOnline;
public bool IsExchangeOnline;
public string Algorithm;
public class ExchangeRateStruct
{
public string Exchange;
public double ToUSD;
public double ToBTC;
public double Volume;
public double TimeStamp;
}
public ExchangeRateStruct[] ExchangeRates;
public double BlockTimeInSeconds;
public string HealthStatus;
public string Message;
}
public DataStruct Data;
public string name;
public string tag;
public string algorithm;
public string block_time;
public double block_reward;
public double block_reward24;
public int last_block;
public double difficulty;
public double difficulty24;
public string nethash;
public double exchange_rate;
public double exchange_rate24;
public double exchange_rate_vol;
public string exchange_rate_curr;
public string market_cap;
public string estimated_rewards;
public string pool_fee;
public string btc_revenue;
public string revenue;
public string cost;
public string profit;
public string status;
public bool lagging;
public int timestamp;
}
#pragma warning restore 0649
#pragma warning restore 0649


/// <summary>
Expand Down

0 comments on commit 698f09f

Please sign in to comment.