Skip to content

Commit

Permalink
Commit for version 1.0.3.0
Browse files Browse the repository at this point in the history
- Compatibility with all NiceHash algorithms
- Automatic compatibility with future NiceHash algorithms
- Bug fixes & improvements
  • Loading branch information
nicehashdev committed Oct 25, 2015
1 parent 8243485 commit aa7d25f
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 45 deletions.
17 changes: 9 additions & 8 deletions src/NiceHashBot/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions src/NiceHashBot/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,18 @@ private void TimerRefresh_Tick(object sender, EventArgs e)
listView1.Items.Clear();
for (int i = 0; i < Orders.Length; i++)
{
int Algorithm = Orders[i].Algorithm;
ListViewItem LVI = new ListViewItem(APIWrapper.SERVICE_NAME[Orders[i].ServiceLocation]);
LVI.SubItems.Add(APIWrapper.ALGORITHM_NAME[Orders[i].Algorithm]);
LVI.SubItems.Add(APIWrapper.ALGORITHM_NAME[Algorithm]);
if (Orders[i].OrderStats != null)
{
LVI.SubItems.Add("#" + Orders[i].OrderStats.ID.ToString());
string PriceText = Orders[i].OrderStats.Price.ToString("F4") + " (" + Orders[i].MaxPrice.ToString("F4") + ")";
if (Orders[i].Algorithm == 1)
PriceText += " BTC/TH/Day";
else
PriceText += " BTC/GH/Day";
PriceText += " BTC/" + APIWrapper.SPEED_TEXT[Algorithm] + "/Day";
LVI.SubItems.Add(PriceText);
LVI.SubItems.Add(Orders[i].OrderStats.BTCAvailable.ToString("F8"));
LVI.SubItems.Add(Orders[i].OrderStats.Workers.ToString());
string SpeedText = "";
if (Orders[i].Algorithm == 1)
SpeedText = (Orders[i].OrderStats.Speed * 0.001).ToString("F4") + " (" + Orders[i].Limit.ToString("F2") + ") TH/s";
else
SpeedText = Orders[i].OrderStats.Speed.ToString("F4") + " (" + Orders[i].Limit.ToString("F2") + ") GH/s";
string SpeedText = (Orders[i].OrderStats.Speed * APIWrapper.ALGORITHM_MULTIPLIER[Algorithm]).ToString("F4") + " (" + Orders[i].Limit.ToString("F2") + ") " + APIWrapper.SPEED_TEXT[Algorithm] + "/s";
LVI.SubItems.Add(SpeedText);
if (!Orders[i].OrderStats.Alive)
LVI.BackColor = Color.PaleVioletRed;
Expand Down Expand Up @@ -150,8 +144,13 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)

if (APIWrapper.Initialize(SettingsContainer.Settings.APIID.ToString(), SettingsContainer.Settings.APIKey))
{
createNewToolStripMenuItem.Enabled = true;
BalanceRefresh_Tick(sender, e);
}
else
{
createNewToolStripMenuItem.Enabled = false;
}
}
}

Expand Down
23 changes: 10 additions & 13 deletions src/NiceHashBot/FormNewOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,10 @@ private void FormNewOrder_FormClosing(object sender, FormClosingEventArgs e)

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.SelectedIndex == 1)
{
label5.Text = "TH/s";
label8.Text = "BTC/TH/Day";
label11.Text = "BTC/TH/Day";
}
else
{
label5.Text = "GH/s";
label8.Text = "BTC/GH/Day";
label11.Text = "BTC/GH/Day";
}
int index = comboBox2.SelectedIndex;
label5.Text = APIWrapper.SPEED_TEXT[index] + "/s";
label8.Text = "BTC/" + APIWrapper.SPEED_TEXT[index] + "/Day";
label11.Text = "BTC/" + APIWrapper.SPEED_TEXT[index] + "/Day";
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Expand Down Expand Up @@ -102,7 +94,12 @@ private void button2_Click(object sender, EventArgs e)

if (AdvancedOptionsShown)
{
OrderContainer.Add(comboBox1.SelectedIndex, comboBox2.SelectedIndex, MaxPrice, Limit, Pools[comboBox3.SelectedIndex], OrderID, StartPrice, StartAmount, textBox1.Text);
if (!OrderContainer.Add(comboBox1.SelectedIndex, comboBox2.SelectedIndex, MaxPrice, Limit, Pools[comboBox3.SelectedIndex], OrderID, StartPrice, StartAmount, textBox1.Text))
{
MessageBox.Show("Order already in list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
numericUpDown3.Focus();
return;
}
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion src/NiceHashBot/FormSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/NiceHashBot/OrderContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,17 @@ public static void Add(int SL, int Algo, double Price, double SpeedLimit, Pool P
}


public static void Add(int SL, int Algo, double Price, double SpeedLimit, Pool PoolInfo, int OrderID, double StartPrice, double StartAmount, string HandlerFile)
public static bool Add(int SL, int Algo, double Price, double SpeedLimit, Pool PoolInfo, int OrderID, double StartPrice, double StartAmount, string HandlerFile)
{
foreach (OrderContainer OC_ in OrderList)
if (OC_.ID == OrderID) return false;

OrderContainer OC = new OrderContainer(SL, Algo, Price, SpeedLimit, PoolInfo, OrderID, StartPrice, StartAmount, HandlerFile);
OC.Launch();
OrderList.Add(OC);
Commit();

return true;
}


Expand Down
4 changes: 2 additions & 2 deletions src/NiceHashBot/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
37 changes: 37 additions & 0 deletions src/NiceHashBotLib/APIBuyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace NiceHashBotLib
{
class APIAlgorithmInfo
{
[JsonProperty(PropertyName = "algo")]
public int ID;

[JsonProperty(PropertyName = "name")]
public string Name;

[JsonProperty(PropertyName = "min_limit")]
public double MinimalLimit;

[JsonProperty(PropertyName = "down_step")]
public double PriceDownStep;

[JsonProperty(PropertyName = "multi")]
public double Multiplier;

[JsonProperty(PropertyName = "speed_text")]
public string SpeedText;
}

class APIBuyInfo
{
[JsonProperty(PropertyName = "algorithms")]
public APIAlgorithmInfo[] Algorithms;

[JsonProperty(PropertyName = "down_time")]
public int DownStepTime;
}
}
64 changes: 55 additions & 9 deletions src/NiceHashBotLib/APIWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class APIWrapper
/// <summary>
/// API Version compatible with.
/// </summary>
public readonly static string API_VERSION_COMPATIBLE = "1.2.0";
public readonly static string API_VERSION_COMPATIBLE = "1.2.2";

/// <summary>
/// URLs for NiceHash services.
Expand All @@ -23,27 +23,42 @@ public class APIWrapper
/// <summary>
/// Names for NiceHash services.
/// </summary>
public readonly static string[] SERVICE_NAME = { "Europe (NiceHash)", " USA (WestHash)" };
public readonly static string[] SERVICE_NAME = { "Europe (NiceHash)", "USA (WestHash)" };

/// <summary>
/// Names for algorithms.
/// </summary>
public readonly static string[] ALGORITHM_NAME = { "Scrypt", "SHA256", "Scrypt-A.-Nf.", "X11", "X13", "Keccak", "X15", "Nist5", "NeoScrypt", "Lyra2RE", "WhirlpoolX", "Qubit", "Quark" };
public static string[] ALGORITHM_NAME;

/// <summary>
/// Total number of algorithms.
/// </summary>
public readonly static int NUMBER_OF_ALGORITHMS = ALGORITHM_NAME.Length;
public static int NUMBER_OF_ALGORITHMS;

/// <summary>
/// Price decrease steps for all algorithms.
/// </summary>
public readonly static double[] PRICE_DECREASE_STEP = { -0.001, -0.0001, -0.002, -0.001, -0.001, -0.0001, -0.001, -0.001, -0.01, -0.002, -0.0001, -0.0005, -0.001 };
public static double[] PRICE_DECREASE_STEP;

/// <summary>
/// Price decrase interval - it is 10 minutes.
/// Minimal speed limit for order.
/// </summary>
public readonly static TimeSpan PRICE_DECREASE_INTERVAL = new TimeSpan(0, 10, 1);
public static double[] MINIMAL_LIMIT;

/// <summary>
/// Algorithm multiplier used for limit (to get GH/s speed).
/// </summary>
public static double[] ALGORITHM_MULTIPLIER;

/// <summary>
/// Algorithm speed text.
/// </summary>
public static string[] SPEED_TEXT;

/// <summary>
/// Price decrase interval.
/// </summary>
public static TimeSpan PRICE_DECREASE_INTERVAL;

/// <summary>
/// API ID.
Expand All @@ -70,8 +85,8 @@ public class APIWrapper
#region PRIVATE_PROPERTIES

private static object CacheLock = new object();
private static CachedOrderList[,] CachedOList = new CachedOrderList[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
private static CachedStats[,] CachedSList = new CachedStats[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
private static CachedOrderList[,] CachedOList;
private static CachedStats[,] CachedSList;

#endregion

Expand Down Expand Up @@ -120,7 +135,38 @@ public static bool Initialize(string ID, string Key)

LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Provided ID and Key are correct!");


Result<APIBuyInfo> R = Request<Result<APIBuyInfo>>(0, "buy.info", false, null);
if (R == null)
{
LibConsole.WriteLine(LibConsole.TEXT_TYPE.ERROR, "Unable to get buy information. Service unavailable.");
return false;
}

PRICE_DECREASE_INTERVAL = new TimeSpan(0, 0, R.Data.DownStepTime);
ALGORITHM_NAME = new string[R.Data.Algorithms.Length];
PRICE_DECREASE_STEP = new double[R.Data.Algorithms.Length];
ALGORITHM_MULTIPLIER = new double[R.Data.Algorithms.Length];
MINIMAL_LIMIT = new double[R.Data.Algorithms.Length];
SPEED_TEXT = new string[R.Data.Algorithms.Length];
for (int i = 0; i < R.Data.Algorithms.Length; i++)
{
ALGORITHM_NAME[i] = R.Data.Algorithms[i].Name;
PRICE_DECREASE_STEP[i] = R.Data.Algorithms[i].PriceDownStep;
ALGORITHM_MULTIPLIER[i] = R.Data.Algorithms[i].Multiplier;
MINIMAL_LIMIT[i] = R.Data.Algorithms[i].MinimalLimit;
SPEED_TEXT[i] = R.Data.Algorithms[i].SpeedText;
}

NUMBER_OF_ALGORITHMS = ALGORITHM_NAME.Length;

CachedOList = new CachedOrderList[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
CachedSList = new CachedStats[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];

LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Buy information loaded.");

ValidAuthorization = true;

return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/NiceHashBotLib/NiceHashBotLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="APIBalance.cs" />
<Compile Include="APIBuyInfo.cs" />
<Compile Include="APIError.cs" />
<Compile Include="APIMethodVersion.cs" />
<Compile Include="APIOrdersGet.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/NiceHashBotLib/OrderInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private bool IncreasePrice(Order MyOrder, Order[] AllOrders, double MinimalPrice
}

// Do not increase price, if we already have price higher or equal compared to minimal price.
if (MyOrder.Price >= MinimalPrice) return false;
if (MyOrder.Price >= (MinimalPrice - 0.00001)) return false;

if (MaxPrice >= MinimalPrice)
{
Expand Down

0 comments on commit aa7d25f

Please sign in to comment.