Beispiel #1
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            ApiWebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            //get GPU coin info (scrypt, X11, etc)
            string jsonString = client.DownloadString(GetApiUrl());            
            Data.ApiResponse apiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString);

            //merge in ASIC coin info (sha-256, scrypt, etc)
            jsonString = client.DownloadString(GetAsicApiUrl());            
            Data.ApiResponse asicApiResponse = JsonConvert.DeserializeObject<Data.ApiResponse>(jsonString);
            foreach (string coinName in asicApiResponse.Coins.Keys)
                apiResponse.Coins[coinName] = asicApiResponse.Coins[coinName];

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (string coinName in apiResponse.Coins.Keys)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.Name = coinName;
                coinInformation.PopulateFromJson(apiResponse.Coins[coinName]);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Beispiel #2
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = client.DownloadString(apiUrl);

            JObject jsonObject = JObject.Parse(jsonString);
            
            if (!jsonObject.Value<bool>("Success"))
            {
                throw new CoinApiException(jsonObject.Value<string>("Message"));
            }

            JArray jsonArray = jsonObject.Value<JArray>("Data");

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Beispiel #3
0
        public IEnumerable<MultipoolInformation> GetMultipoolInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = client.DownloadString(apiUrl);

            JObject jsonObject = JObject.Parse(jsonString);
            jsonObject = jsonObject.Value<JObject>("result");

            JArray jsonArray = jsonObject.Value<JArray>("stats");

            List<MultipoolInformation> result = new List<MultipoolInformation>();

            foreach (JToken jToken in jsonArray)
            {
                MultipoolInformation multipoolInformation = new MultipoolInformation();
                if (multipoolInformation.PopulateFromJson(jToken))
                    result.Add(multipoolInformation);
            }

            MultipoolInformation btcInformation = result.Single(mpi => mpi.Algorithm.Equals(AlgorithmNames.SHA256));

            foreach (MultipoolInformation otherInformation in result)
            {
                KnownAlgorithm knownAlgorithm = KnownAlgorithms.Algorithms.Single(ka => ka.Name.Equals(otherInformation.Algorithm));
                otherInformation.Profitability = ((otherInformation.Price * knownAlgorithm.Multiplier) / btcInformation.Price) * PoolProfitability * 100;
            }

            return result;
        }
Beispiel #4
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();
            string jsonString = client.DownloadString(apiUrl);
            JObject jsonObject = JObject.Parse(jsonString);

            string resultStatus = jsonObject.Value<string>("status");
            if (!resultStatus.Equals("success", StringComparison.OrdinalIgnoreCase))
                throw new CoinApiException(resultStatus);

            List<CoinInformation> result = new List<CoinInformation>();

            JArray jsonArray = jsonObject.Value<JArray>("Data");
            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            CalculateProfitability(result);

            return result;
        }
Beispiel #5
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            ApiWebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = client.DownloadFlakyString(apiUrl);

            JArray jsonArray = JArray.Parse(jsonString);

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Beispiel #6
0
        public static Data.SellPrices GetSellPrices()
        {
            WebClient webClient = new ApiWebClient();

            string response = webClient.DownloadString(new Uri(GetApiUrl()));

            Data.SellPrices sellPrices = JsonConvert.DeserializeObject<Data.SellPrices>(response);
            return sellPrices;
        }
Beispiel #7
0
 public static void SubmitMinerStatistics(string url, Data.Machine machine)
 {
     if (!url.EndsWith("/"))
         url = url + "/";
     string fullUrl = String.Format("{0}machines", url);
     using (WebClient client = new ApiWebClient())
     {
         //specify UTF8 so devices with Unicode characters are posted up properly
         client.Encoding = Encoding.UTF8;
                         
         string jsonData = JsonConvert.SerializeObject(machine);
         client.Headers[HttpRequestHeader.ContentType] = "application/json";
         string response = client.UploadString(fullUrl, jsonData);
     }
 }
        public static List<AvailableMiner> GetAvailableMiners(string userAgent)
        {
            WebClient webClient = new ApiWebClient();
            webClient.Headers.Add("user-agent", userAgent);

            string platform = "win32";
            if (OSVersionPlatform.GetConcretePlatform() == PlatformID.MacOSX)
                platform = "osx64";
            
            //include www. to avoid redirect
            string url = "http://www.multiminerapp.com/miners?platform=" + platform;
            string response = webClient.DownloadString(new Uri(url));

            List<AvailableMiner> availableMiners = JsonConvert.DeserializeObject<List<AvailableMiner>>(response);
            return availableMiners;
        }
Beispiel #9
0
        public static List<Data.RemoteCommand> GetCommands(string url, string apiKey, string emailAddress, string applicationKey, string machineName)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&apiKey={4}",
                url, emailAddress, applicationKey, machineName, apiKey);
            using (WebClient client = new ApiWebClient())
            {
                string response = ExecuteWebAction(() =>
                {
                    return client.DownloadString(fullUrl);
                });

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return serializer.Deserialize<List<Data.RemoteCommand>>(response);
            }
        }
Beispiel #10
0
        public static Data.RemoteCommand DeleteCommand(string url, string apiKey, string emailAddress, string applicationKey, string machineName, long commandId)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&machineName={3}&commandId={4}&apiKey={5}",
                url, emailAddress, applicationKey, machineName, commandId, apiKey);
            using (WebClient client = new ApiWebClient())
            {
                string response = ExecuteWebAction(() =>
                {
                    return client.UploadString(fullUrl, "DELETE", "");
                });

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                return serializer.Deserialize<Data.RemoteCommand>(response);
            }
        }
Beispiel #11
0
        public static void SubmitNotifications(string url, string apiKey, string emailAddress, string applicationKey, List<Data.Notification> notifications)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}NotificationsInput?emailAddress={1}&applicationKey={2}&apiKey={3}&detailed=true",
                url, emailAddress, applicationKey, apiKey);
            using (WebClient client = new ApiWebClient())
            {
                string jsonData = JsonConvert.SerializeObject(notifications);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                ExecuteWebAction(() =>
                {
                    return client.UploadString(fullUrl, jsonData);
                });
            }
        }
Beispiel #12
0
        public static void SubmitMachinePools(string url, string apiKey, string emailAddress, string applicationKey,
            Dictionary<string, List<string>> machinePools)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}PoolsInput?emailAddress={1}&applicationKey={2}&apiKey={3}",
                url, emailAddress, applicationKey, apiKey);
            using (WebClient client = new ApiWebClient())
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string jsonData = serializer.Serialize(machinePools);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                ExecuteWebAction(() =>
                {
                    return client.UploadString(fullUrl, jsonData);
                });
            }
        }
Beispiel #13
0
        public IEnumerable<CoinInformation> GetCoinInformation(string userAgent = "")
        {
            WebClient client = new ApiWebClient();
            if (!string.IsNullOrEmpty(userAgent))
                client.Headers.Add("user-agent", userAgent);

            string apiUrl = GetApiUrl();

            string jsonString = String.Empty;

            try
            {
                jsonString = client.DownloadString(apiUrl);
            }
            catch (WebException ex)
            {
                if ((ex.Status == WebExceptionStatus.ProtocolError) &&
                    (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadGateway))
                {
                    //try again 1 more time if error 502
                    Thread.Sleep(750);
                    jsonString = client.DownloadString(apiUrl);
                }
                else
                    throw;
            }

            JArray jsonArray = JArray.Parse(jsonString);

            List<CoinInformation> result = new List<CoinInformation>();

            foreach (JToken jToken in jsonArray)
            {
                CoinInformation coinInformation = new CoinInformation();
                coinInformation.PopulateFromJson(jToken);
                if (coinInformation.Difficulty > 0)
                    //only add coins with valid info since the user may be basing
                    //strategies on Difficulty
                    result.Add(coinInformation);
            }

            return result;
        }
Beispiel #14
0
        public IEnumerable<ExchangeInformation> GetExchangeInformation()
        {
            ApiWebClient webClient = new ApiWebClient();

            string response = webClient.DownloadFlakyString(new Uri(GetApiUrl()));

            Data.SellPrices sellPrices = JsonConvert.DeserializeObject<Data.SellPrices>(response);

            List<ExchangeInformation> results = new List<ExchangeInformation>();

            results.Add(new ExchangeInformation()
            {
                SourceCurrency = "BTC",
                TargetCurrency = "USD",
                TargetSymbol = "$",
                ExchangeRate = sellPrices.Subtotal.Amount
            });

            return results;
        }
Beispiel #15
0
        public static void SubmitMiningStatistics(string url, string apiKey, string emailAddress, string applicationKey, List<Data.MiningStatistics> miningStatistics)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}MiningStatisticsInput?emailAddress={1}&applicationKey={2}&apiKey={3}",
                url, emailAddress, applicationKey, apiKey);
            using (WebClient client = new ApiWebClient())
            {
                //specify UTF8 so devices with Unicode characters are posted up properly
                client.Encoding = Encoding.UTF8;

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                string jsonData = serializer.Serialize(miningStatistics);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                ExecuteWebAction(() =>
                {
                    return client.UploadString(fullUrl, jsonData);
                });

            }
        }
Beispiel #16
0
        public static List<Data.RemoteCommand> GetCommands(string url, string apiKey, string emailAddress, string applicationKey, List<string> machineNames)
        {
            if (!url.EndsWith("/"))
                url = url + "/";

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonData = serializer.Serialize(machineNames);

            string fullUrl = String.Format("{0}RemoteCommands?emailAddress={1}&applicationKey={2}&apiKey={4}",
                url, emailAddress, applicationKey, jsonData, apiKey);

            using (WebClient client = new ApiWebClient())
            {
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                string response = ExecuteWebAction(() =>
                {
                    return client.UploadString(fullUrl, jsonData);
                });

                return serializer.Deserialize<List<Data.RemoteCommand>>(response);
            }
        }
Beispiel #17
0
        public static List<Data.RemoteCommand> SubmitMiningStatistics(string url, string apiKey, string emailAddress, string applicationKey, 
            List<Data.MiningStatistics> miningStatistics, bool fetchCommands)
        {
            if (!url.EndsWith("/"))
                url = url + "/";
            string fullUrl = String.Format("{0}MiningStatisticsInput?emailAddress={1}&applicationKey={2}&apiKey={3}&fetchCommands={4}", 
                url, emailAddress, applicationKey, apiKey, fetchCommands);
            using (WebClient client = new ApiWebClient())
            {
                //specify UTF8 so devices with Unicode characters are posted up properly
                client.Encoding = Encoding.UTF8;

                string jsonData = JsonConvert.SerializeObject(miningStatistics);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";

                string response = ExecuteWebAction(() =>
                {
                    return client.UploadString(fullUrl, jsonData);
                });

                return JsonConvert.DeserializeObject<List<Data.RemoteCommand>>(response);
            }
        }
Beispiel #18
0
        public IEnumerable<ExchangeInformation> GetExchangeInformation()
        {
            ApiWebClient webClient = new ApiWebClient();
            webClient.Encoding = Encoding.UTF8;

            string response = webClient.DownloadFlakyString(new Uri(GetApiUrl()));

            Dictionary<string, TickerEntry> tickerEntries = JsonConvert.DeserializeObject<Dictionary<string, TickerEntry>>(response);

            List<ExchangeInformation> results = new List<ExchangeInformation>();

            foreach (KeyValuePair<string, TickerEntry> keyValuePair in tickerEntries)
            {
                results.Add(new ExchangeInformation()
                {
                    SourceCurrency = "BTC",
                    TargetCurrency = keyValuePair.Key,
                    TargetSymbol = keyValuePair.Value.Symbol,
                    ExchangeRate = keyValuePair.Value.Last
                });
            }

            return results;
        }