Post
Topic
Board Mining (Altcoins)
Re: [Awesome Miner]- Powerful Windows GUI to manage and monitor up to 5000 miners
by
puwaha
on 13/02/2018, 06:23:12 UTC
Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Request library
using System.Net;
using System.IO;

public class ActionScript
{
private ContextProvider Context = ScriptManager.Context;
public bool Execute(List list)
{
try
{
 



//--------------------Change----------------------
string Str_name = "ALQO";//Name Coin sample   = "ALQO"
double Str_Reward = 150; //Reward Coin sample = 10
string Str1 = this.getdati("https://explorer.alqo.org/api/difficulty");//link difficulty
string Str2 = this.getdati("https://api.coinmarketcap.com/v1/ticker/alqo/");//link coinmarketcap.com
//--------------------------------------------------









Str1 = Str1.Replace(".", ",");
double dif = Convert.ToDouble(Str1);

Uri uri = new Uri(@"https://api.coinmarketcap.com/v1/ticker/alqo/");
WebRequest webRequest = WebRequest.Create(uri);
WebResponse response = webRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
String responseData = streamReader.ReadToEnd();


 


string myString = responseData;
string[] subStrings = myString.Split(',');
string v = "";
foreach (string str in subStrings)
{
 if (str.Contains("price_btc") == true)
            {   
             v = str.Replace(@"""", "");
             v = v.Replace("price_btc", "");
             v = v.Replace(" ", "");
             v = v.Replace(":", "");
             v = v.Replace(".", ",");
            }
 }

double Price = Convert.ToDouble(v);



//MessageBox.Show(Str1);

Context.CoinStat.SetProperties(Str_name, dif, Str_Reward, Price);
 
 
//----------------Exception------------------
 }
catch(Exception exception)
{
   
}
//--------------End--Exception----------------
return true;
}

//--------------------------------------------
protected string getdati(string url)
        {
            try
            {
                string rt;

                WebRequest request = WebRequest.Create(url);

                WebResponse response = request.GetResponse();

                Stream dataStream = response.GetResponseStream();

                StreamReader reader = new StreamReader(dataStream);

                rt = reader.ReadToEnd();

                Console.WriteLine(rt);

                reader.Close();
                response.Close();

                return rt;
            }

            catch(Exception ex)
            {
                return "Error: " + ex.Message;
            }
        }       
}//end







Hello Spinter... a couple of questions...

On this line you have it hardcoded to the URL for the coinmarketcaps ALQO API.

Uri uri = new Uri(@"https://api.coinmarketcap.com/v1/ticker/alqo/");

Shouldn't this be using the Str2 like this:

Uri uri = new Uri(@Str2);


Also, I tried to duplicate your code for Bulwark, but I never get any returns.  Is there something wrong with this below?

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//Request library
using System.Net;
using System.IO;

public class ActionScript
{
private ContextProvider Context = ScriptManager.Context;
public bool Execute(List list)
{
try
{
 



//--------------------Change----------------------
string Str_name = "Bulwark";//Name Coin sample   = "ALQO"
double Str_Reward = 33; //Reward Coin sample = 10
string Str1 = this.getdati("http://explorer.bulwarkcrypto.com/api/getdifficulty");//link difficulty
string Str2 = this.getdati("https://api.coinmarketcap.com/v1/ticker/bulwark/");//link coinmarketcap.com
//--------------------------------------------------









Str1 = Str1.Replace(".", ",");
double dif = Convert.ToDouble(Str1);

Uri uri = new Uri(@Str2);
WebRequest webRequest = WebRequest.Create(uri);
WebResponse response = webRequest.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
String responseData = streamReader.ReadToEnd();


 


string myString = responseData;
string[] subStrings = myString.Split(',');
string v = "";
foreach (string str in subStrings)
{
 if (str.Contains("price_btc") == true)
            {   
             v = str.Replace(@"""", "");
             v = v.Replace("price_btc", "");
             v = v.Replace(" ", "");
             v = v.Replace(":", "");
             v = v.Replace(".", ",");
            }
 }

double Price = Convert.ToDouble(v);



//MessageBox.Show(Str1);

Context.CoinStat.SetProperties(Str_name, dif, Str_Reward, Price);
 
 
//----------------Exception------------------
 }
catch(Exception exception)
{
   
}
//--------------End--Exception----------------
return true;
}

//--------------------------------------------
protected string getdati(string url)
        {
            try
            {
                string rt;

                WebRequest request = WebRequest.Create(url);

                WebResponse response = request.GetResponse();

                Stream dataStream = response.GetResponseStream();

                StreamReader reader = new StreamReader(dataStream);

                rt = reader.ReadToEnd();

                Console.WriteLine(rt);

                reader.Close();
                response.Close();

                return rt;
            }

            catch(Exception ex)
            {
                return "Error: " + ex.Message;
            }
        }       
}//end