public bool IsProfitABetterThanB(Profit profitA, ProfitTimeframe timeframeA, Profit profitB, ProfitTimeframe timeframeB, double threshold)
        {
            double relativeRewardA = GetReward(profitA, timeframeA);
            double relativeRewardB = GetReward(profitB, timeframeB);

            return(relativeRewardA > relativeRewardB + (relativeRewardB * threshold));
        }
Exemplo n.º 2
0
 public Profit(double usdRewardLive, double usdRewardDay, double coinRewardLive, double coinRewardDay, ProfitProvider source, ProfitTimeframe timeframe)
 {
     UsdRewardLive  = usdRewardLive;
     UsdRewardDay   = usdRewardDay;
     CoinRewardLive = coinRewardLive;
     CoinRewardDay  = coinRewardDay;
     Source         = source;
     Timeframe      = timeframe;
 }
        public double GetReward(Profit profit, Mineable mineable, ProfitTimeframe timeframe)
        {
            double reward = 0;

            if (profit.CoinRewardDay > 0 && profit.CoinRewardLive > 0)
            {
                reward = profit.CoinRewardLive / profit.CoinRewardDay;
            }
            return(reward);
        }
Exemplo n.º 4
0
        public Dictionary <string, Profit> GetProfits(DirectoryInfo appRootFolder, Settings settings, IList <Coin> coins, CancellationToken ct)
        {
            var poolProfitsDictionary = new Dictionary <string, Profit>();

            try
            {
                var profitsLiveJson = Helpers.GetJsonFromUrl("https://www.cryptunit.com/api/earnings/?hashrate=10000&device=GPU&dataavg=1h&volumefilter=&algofilter=", settings, appRootFolder, ct);
                var profitsDayJson  = Helpers.GetJsonFromUrl("https://www.cryptunit.com/api/earnings/?hashrate=10000&device=GPU&dataavg=24h&volumefilter=&algofilter=", settings, appRootFolder, ct);

                dynamic profitsLive = JsonConvert.DeserializeObject(profitsLiveJson);
                dynamic profitsDay  = JsonConvert.DeserializeObject(profitsDayJson);


                foreach (dynamic rewardLive in profitsLive[0].coins)
                {
                    string tickerSymbol = rewardLive.coin_ticker;
                    //Adjust profits based on user defined hashrate
                    Coin matchedCoin = coins.FirstOrDefault(c => c.TickerSymbol == tickerSymbol);

                    if (matchedCoin != null)
                    {
                        double hashrate        = rewardLive.hashrate_auto;
                        double rewardUsdLive   = rewardLive.reward_day_usd;
                        double rewardCoinsLive = rewardLive.reward_day_coins;
                        foreach (dynamic rewardDay in profitsDay[0].coins)
                        {
                            if (rewardDay.coin_ticker == tickerSymbol)
                            {
                                double          rewardUsdDay   = rewardDay.reward_day_usd;
                                double          rewardCoinsDay = rewardDay.reward_day_coins;
                                ProfitTimeframe timeFrame      = matchedCoin.OverrideProfitTimeframe.HasValue ? matchedCoin.OverrideProfitTimeframe.Value : settings.ProfitTimeframe;
                                rewardUsdLive   = (rewardUsdLive / hashrate) * matchedCoin.GetExpectedHashrate(settings);
                                rewardCoinsLive = (rewardCoinsLive / hashrate) * matchedCoin.GetExpectedHashrate(settings);
                                rewardUsdDay    = (rewardUsdDay / hashrate) * matchedCoin.GetExpectedHashrate(settings);
                                rewardCoinsDay  = (rewardCoinsDay / hashrate) * matchedCoin.GetExpectedHashrate(settings);
                                poolProfitsDictionary[tickerSymbol] = new Profit(rewardUsdLive, rewardUsdDay, rewardCoinsLive, rewardCoinsDay, ProfitProvider.CryptunitApi, timeFrame);
                                Console.WriteLine($"Got profit data for {tickerSymbol} from CryptunitAPI");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to get profits data from Cryptunit Api: " + ex.Message);
            }
            return(poolProfitsDictionary);
        }
Exemplo n.º 5
0
        private Task SetProfitForCoinTaskAsync(Coin coin, Settings settings, DirectoryInfo appRootFolder, Dictionary <string, Profit> poolProfitsDictionary, CancellationToken ct)
        {
            return(Task.Run(() =>
            {
                try
                {
                    string apiUrl = GetApiUrl(coin);
                    if (!String.IsNullOrEmpty(apiUrl))
                    {
                        var profitsJson = Helpers.GetJsonFromUrl(apiUrl, settings, appRootFolder, ct);
                        dynamic lastStats = JObject.Parse(profitsJson);
                        ProfitTimeframe timeFrame = coin.OverrideProfitTimeframe.HasValue ? coin.OverrideProfitTimeframe.Value : settings.ProfitTimeframe;

                        decimal diffDay = lastStats.charts.difficulty_1d;
                        decimal diffLive = lastStats.network.difficulty;

                        decimal reward = lastStats.lastblock.reward;

                        decimal profitDay = (coin.GetExpectedHashrate(settings) * (86400 / diffDay)) * reward;
                        decimal profitLive = (coin.GetExpectedHashrate(settings) * (86400 / diffLive)) * reward;

                        // Get amount of coins
                        decimal coinUnits = lastStats.config.coinUnits;
                        decimal amountDay = profitDay / coinUnits;
                        decimal amountLive = profitLive / coinUnits;

                        //Get usd price
                        decimal usdPrice = lastStats.charts.price_1h;

                        //Multiplicate
                        decimal usdRewardDecDay = amountDay * usdPrice;
                        double usdRewardDay = (double)usdRewardDecDay;

                        decimal usdRewardDecLive = amountLive * usdPrice;
                        double usdRewardLive = (double)usdRewardDecLive;

                        poolProfitsDictionary[coin.TickerSymbol] = new Profit(usdRewardLive, usdRewardDay, (double)amountLive, (double)amountDay, ProfitProvider.HeroMinersApi, timeFrame);
                        Console.WriteLine($"Got profit data for {coin.TickerSymbol} from MinerRocksAPI");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Couldn't get profits data for {coin.DisplayName} from HeroMinersApi: " + ex.Message);
                }
            }, ct));
        }
Exemplo n.º 6
0
        public double GetReward(Profit profit, Mineable mineable, ProfitTimeframe timeframe)
        {
            timeframe = mineable.OverrideProfitTimeframe.HasValue ? mineable.OverrideProfitTimeframe.Value : timeframe;
            double reward = 0;

            switch (timeframe)
            {
            case ProfitTimeframe.Day:
                reward = profit.UsdRewardDay;
                break;

            default:
                reward = profit.UsdRewardLive;
                break;
            }
            return(reward);
        }
        private double GetReward(Profit profit, ProfitTimeframe timeframe)
        {
            double reward = 0;

            switch (timeframe)
            {
            case ProfitTimeframe.Day:
                reward = profit.UsdRewardDay;
                break;

            case ProfitTimeframe.Live:
                reward = profit.UsdRewardLive;
                break;
            }

            return(reward);
        }
        private double GetReward(Profit profit, ProfitTimeframe timeframe)
        {
            double reward = 0;

            switch (timeframe)
            {
            case ProfitTimeframe.Day:
                reward = profit.UsdRewardDay;
                break;

            case ProfitTimeframe.Live:
                reward = profit.UsdRewardLive;
                break;
            }
            if (profit.CoinRewardDay > 0 && profit.CoinRewardLive > 0)
            {
                reward *= (profit.CoinRewardLive / profit.CoinRewardDay);
            }
            return(reward);
        }
        private void SetProfitFromJson(string json, ProfitTimeframe profitTimeframe, List <Pool> pools, Dictionary <Pool, Profit> poolProfitsDictionary)
        {
            foreach (JToken jCoin in JToken.Parse(json).First["coins"].Children())
            {
                foreach (Pool matchedPool in pools.Where(p => p.ProfitProviderInfo == jCoin.Value <string>("coin_ticker")))
                {
                    switch (profitTimeframe)
                    {
                    case ProfitTimeframe.Live:
                        poolProfitsDictionary[matchedPool] = new Profit(jCoin.Value <double>("reward_day_usd"), 0, jCoin.Value <double>("reward_day_coins"), 0, ProfitProvider.CryptunitApi);
                        break;

                    case ProfitTimeframe.Day:
                        poolProfitsDictionary[matchedPool] = new Profit(0, jCoin.Value <double>("reward_day_usd"), 0, jCoin.Value <double>("reward_day_coins"), ProfitProvider.CryptunitApi);
                        break;

                    default: throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }
Exemplo n.º 10
0
        private static void SetProfitFromJson(string json, double btcUsdPrice, ProfitTimeframe timeframe, IList <Pool> nicehashAlgorithms, Dictionary <Pool, Profit> nicehashProfitsDictionary)
        {
            foreach (JToken stat in JToken.Parse(json)["algos"].Children())
            {
                int    algo  = stat.Value <int>("a");
                double price = stat.Value <double>("p");

                foreach (Pool matchedPool in nicehashAlgorithms.Where(na => na.ProfitProviderInfo == algo.ToString(CultureInfo.InvariantCulture)))
                {
                    double pricePerHashPerDay = price / 100000000;
                    double btcReward          = pricePerHashPerDay * Profit.BaseHashrate;
                    var    usdReward          = btcReward * btcUsdPrice;

                    if (timeframe == ProfitTimeframe.Day)
                    {
                        nicehashProfitsDictionary[matchedPool] = new Profit(0, usdReward, 0, 0, ProfitProvider.NiceHashApi);
                    }
                    else
                    {
                        nicehashProfitsDictionary[matchedPool] = new Profit(usdReward, 0, 0, 0, ProfitProvider.NiceHashApi);
                    }
                }
            }
        }
        Task SetProfitForCoinTask(Coin coin, Settings settings, DirectoryInfo appRootFolder, Dictionary <string, Profit> poolProfitsDictionary, CancellationToken ct)
        {
            return(Task.Run(() =>
            {
                try
                {
                    string apiUrl = GetApiUrl(coin);
                    if (!String.IsNullOrEmpty(apiUrl))
                    {
                        var profitsJson = Helpers.GetJsonFromUrl(apiUrl, settings, appRootFolder, ct);
                        dynamic lastStats = JObject.Parse(profitsJson);

                        ProfitTimeframe timeFrame = coin.OverrideProfitTimeframe.HasValue ? coin.OverrideProfitTimeframe.Value : settings.ProfitTimeframe;

                        // Get live profit
                        decimal diffLive = lastStats.network.difficulty;
                        decimal reward = lastStats.network.reward;
                        decimal profitLive = (coin.GetExpectedHashrate(settings) * (86400 / diffLive)) * reward;

                        // Get amount of coins
                        decimal coinUnits = lastStats.config.coinUnits;
                        decimal amountLive = profitLive / coinUnits;

                        //Get usd price
                        JArray usdPrices = lastStats.charts.priceUSD;
                        JArray lastUsdPriceData = usdPrices.Last().ToObject <JArray>();
                        decimal lastUsdPrice = lastUsdPriceData[1].ToObject <decimal>();

                        //Multiplicate
                        decimal usdRewardDecLive = amountLive * lastUsdPrice;
                        double usdRewardLive = (double)usdRewardDecLive;

                        //Get day profit
                        double amountDay = 0;
                        double usdRewardDay = 0;
                        JArray difficulties = lastStats.charts.difficulty;
                        List <decimal> validDifficulties = new List <decimal>();
                        foreach (var diffToken in difficulties)
                        {
                            var diffData = diffToken.ToObject <JArray>();
                            long unixEpochTime = diffData[0].ToObject <long>();
                            var date = DateTimeOffset.FromUnixTimeSeconds(unixEpochTime);
                            if (date.UtcDateTime > DateTimeOffset.UtcNow.AddDays(-1))
                            {
                                decimal validDiff = diffData[1].ToObject <decimal>();
                                validDifficulties.Add(validDiff);
                            }
                        }
                        if (validDifficulties.Count > 0)
                        {
                            List <decimal> validPrices = new List <decimal>();
                            foreach (var usdPriceToken in usdPrices)
                            {
                                var priceData = usdPriceToken.ToObject <JArray>();
                                long unixEpochTime = priceData[0].ToObject <long>();
                                var date = DateTimeOffset.FromUnixTimeSeconds(unixEpochTime);
                                if (date.UtcDateTime > DateTimeOffset.UtcNow.AddDays(-1))
                                {
                                    decimal validPrice = priceData[1].ToObject <decimal>();
                                    validPrices.Add(validPrice);
                                }
                            }

                            if (validPrices.Count > 0)
                            {
                                decimal averagePrice = validPrices.Sum() / validPrices.Count;
                                decimal averageDiff = validDifficulties.Sum() / validDifficulties.Count;
                                decimal profitDay = (coin.GetExpectedHashrate(settings) * (86400 / averageDiff)) * reward;
                                decimal amountDayDec = profitDay / coinUnits;
                                amountDay = (double)amountDayDec;
                                decimal usdRewardDecDay = amountDayDec * averagePrice;
                                usdRewardDay = (double)usdRewardDecDay;
                            }
                        }

                        poolProfitsDictionary[coin.TickerSymbol] = new Profit(usdRewardLive, usdRewardDay, (double)amountLive, amountDay, ProfitProvider.CryptoknightCCApi, timeFrame);
                        Console.WriteLine($"Got profit data for {coin.TickerSymbol} from CryptoknightCCAPI");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Couldn't get profits data for {coin.DisplayName} from CryptoknightCCAPI: " + ex.Message);
                }
            }, ct));
        }
        private static void SetProfitFromJson(string json, double btcUsdPrice, Settings settings, ProfitTimeframe timeframe, IList <NicehashAlgorithm> nicehashAlgorithms, Dictionary <int, Profit> nicehashProfitsDictionary)
        {
            dynamic nicehashProfits = JObject.Parse(json);
            var     result          = nicehashProfits.result;

            foreach (dynamic stat in result.stats)
            {
                int    algo  = stat.algo;
                double price = stat.price;

                var matchedAlgorithm = nicehashAlgorithms.FirstOrDefault(na => na.ApiId == algo);
                if (matchedAlgorithm != null)
                {
                    double btcReward = 0;
                    btcReward = (price / 1000000) * matchedAlgorithm.GetExpectedHashrate(settings);
                    var usdReward = btcReward * btcUsdPrice;
                    if (timeframe == ProfitTimeframe.Day)
                    {
                        nicehashProfitsDictionary[matchedAlgorithm.ApiId] = new Profit(0, usdReward, 0, 0, ProfitProvider.NiceHashApi, timeframe);
                    }
                    else
                    {
                        nicehashProfitsDictionary[matchedAlgorithm.ApiId] = new Profit(usdReward, 0, 0, 0, ProfitProvider.NiceHashApi, timeframe);
                    }
                    Console.WriteLine($"Got profit data for {matchedAlgorithm.DisplayName} from NiceHashAPI");
                }
            }
        }