Skip to content

Commit aa7d25f

Browse files
author
nicehashdev
committed
Commit for version 1.0.3.0
- Compatibility with all NiceHash algorithms - Automatic compatibility with future NiceHash algorithms - Bug fixes & improvements
1 parent 8243485 commit aa7d25f

10 files changed

+132
-45
lines changed

src/NiceHashBot/FormMain.Designer.cs

+9-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NiceHashBot/FormMain.cs

+9-10
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,18 @@ private void TimerRefresh_Tick(object sender, EventArgs e)
6262
listView1.Items.Clear();
6363
for (int i = 0; i < Orders.Length; i++)
6464
{
65+
int Algorithm = Orders[i].Algorithm;
6566
ListViewItem LVI = new ListViewItem(APIWrapper.SERVICE_NAME[Orders[i].ServiceLocation]);
66-
LVI.SubItems.Add(APIWrapper.ALGORITHM_NAME[Orders[i].Algorithm]);
67+
LVI.SubItems.Add(APIWrapper.ALGORITHM_NAME[Algorithm]);
6768
if (Orders[i].OrderStats != null)
6869
{
6970
LVI.SubItems.Add("#" + Orders[i].OrderStats.ID.ToString());
7071
string PriceText = Orders[i].OrderStats.Price.ToString("F4") + " (" + Orders[i].MaxPrice.ToString("F4") + ")";
71-
if (Orders[i].Algorithm == 1)
72-
PriceText += " BTC/TH/Day";
73-
else
74-
PriceText += " BTC/GH/Day";
72+
PriceText += " BTC/" + APIWrapper.SPEED_TEXT[Algorithm] + "/Day";
7573
LVI.SubItems.Add(PriceText);
7674
LVI.SubItems.Add(Orders[i].OrderStats.BTCAvailable.ToString("F8"));
7775
LVI.SubItems.Add(Orders[i].OrderStats.Workers.ToString());
78-
string SpeedText = "";
79-
if (Orders[i].Algorithm == 1)
80-
SpeedText = (Orders[i].OrderStats.Speed * 0.001).ToString("F4") + " (" + Orders[i].Limit.ToString("F2") + ") TH/s";
81-
else
82-
SpeedText = Orders[i].OrderStats.Speed.ToString("F4") + " (" + Orders[i].Limit.ToString("F2") + ") GH/s";
76+
string SpeedText = (Orders[i].OrderStats.Speed * APIWrapper.ALGORITHM_MULTIPLIER[Algorithm]).ToString("F4") + " (" + Orders[i].Limit.ToString("F2") + ") " + APIWrapper.SPEED_TEXT[Algorithm] + "/s";
8377
LVI.SubItems.Add(SpeedText);
8478
if (!Orders[i].OrderStats.Alive)
8579
LVI.BackColor = Color.PaleVioletRed;
@@ -150,8 +144,13 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
150144

151145
if (APIWrapper.Initialize(SettingsContainer.Settings.APIID.ToString(), SettingsContainer.Settings.APIKey))
152146
{
147+
createNewToolStripMenuItem.Enabled = true;
153148
BalanceRefresh_Tick(sender, e);
154149
}
150+
else
151+
{
152+
createNewToolStripMenuItem.Enabled = false;
153+
}
155154
}
156155
}
157156

src/NiceHashBot/FormNewOrder.cs

+10-13
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,10 @@ private void FormNewOrder_FormClosing(object sender, FormClosingEventArgs e)
5555

5656
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
5757
{
58-
if (comboBox2.SelectedIndex == 1)
59-
{
60-
label5.Text = "TH/s";
61-
label8.Text = "BTC/TH/Day";
62-
label11.Text = "BTC/TH/Day";
63-
}
64-
else
65-
{
66-
label5.Text = "GH/s";
67-
label8.Text = "BTC/GH/Day";
68-
label11.Text = "BTC/GH/Day";
69-
}
58+
int index = comboBox2.SelectedIndex;
59+
label5.Text = APIWrapper.SPEED_TEXT[index] + "/s";
60+
label8.Text = "BTC/" + APIWrapper.SPEED_TEXT[index] + "/Day";
61+
label11.Text = "BTC/" + APIWrapper.SPEED_TEXT[index] + "/Day";
7062
}
7163

7264
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
@@ -102,7 +94,12 @@ private void button2_Click(object sender, EventArgs e)
10294

10395
if (AdvancedOptionsShown)
10496
{
105-
OrderContainer.Add(comboBox1.SelectedIndex, comboBox2.SelectedIndex, MaxPrice, Limit, Pools[comboBox3.SelectedIndex], OrderID, StartPrice, StartAmount, textBox1.Text);
97+
if (!OrderContainer.Add(comboBox1.SelectedIndex, comboBox2.SelectedIndex, MaxPrice, Limit, Pools[comboBox3.SelectedIndex], OrderID, StartPrice, StartAmount, textBox1.Text))
98+
{
99+
MessageBox.Show("Order already in list!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
100+
numericUpDown3.Focus();
101+
return;
102+
}
106103
}
107104
else
108105
{

src/NiceHashBot/FormSettings.Designer.cs

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NiceHashBot/OrderContainer.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,17 @@ public static void Add(int SL, int Algo, double Price, double SpeedLimit, Pool P
193193
}
194194

195195

196-
public static void Add(int SL, int Algo, double Price, double SpeedLimit, Pool PoolInfo, int OrderID, double StartPrice, double StartAmount, string HandlerFile)
196+
public static bool Add(int SL, int Algo, double Price, double SpeedLimit, Pool PoolInfo, int OrderID, double StartPrice, double StartAmount, string HandlerFile)
197197
{
198+
foreach (OrderContainer OC_ in OrderList)
199+
if (OC_.ID == OrderID) return false;
200+
198201
OrderContainer OC = new OrderContainer(SL, Algo, Price, SpeedLimit, PoolInfo, OrderID, StartPrice, StartAmount, HandlerFile);
199202
OC.Launch();
200203
OrderList.Add(OC);
201204
Commit();
205+
206+
return true;
202207
}
203208

204209

src/NiceHashBot/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.2.0")]
36-
[assembly: AssemblyFileVersion("1.0.2.0")]
35+
[assembly: AssemblyVersion("1.0.3.0")]
36+
[assembly: AssemblyFileVersion("1.0.3.0")]

src/NiceHashBotLib/APIBuyInfo.cs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Newtonsoft.Json;
5+
6+
namespace NiceHashBotLib
7+
{
8+
class APIAlgorithmInfo
9+
{
10+
[JsonProperty(PropertyName = "algo")]
11+
public int ID;
12+
13+
[JsonProperty(PropertyName = "name")]
14+
public string Name;
15+
16+
[JsonProperty(PropertyName = "min_limit")]
17+
public double MinimalLimit;
18+
19+
[JsonProperty(PropertyName = "down_step")]
20+
public double PriceDownStep;
21+
22+
[JsonProperty(PropertyName = "multi")]
23+
public double Multiplier;
24+
25+
[JsonProperty(PropertyName = "speed_text")]
26+
public string SpeedText;
27+
}
28+
29+
class APIBuyInfo
30+
{
31+
[JsonProperty(PropertyName = "algorithms")]
32+
public APIAlgorithmInfo[] Algorithms;
33+
34+
[JsonProperty(PropertyName = "down_time")]
35+
public int DownStepTime;
36+
}
37+
}

src/NiceHashBotLib/APIWrapper.cs

+55-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class APIWrapper
1313
/// <summary>
1414
/// API Version compatible with.
1515
/// </summary>
16-
public readonly static string API_VERSION_COMPATIBLE = "1.2.0";
16+
public readonly static string API_VERSION_COMPATIBLE = "1.2.2";
1717

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

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

3333
/// <summary>
3434
/// Total number of algorithms.
3535
/// </summary>
36-
public readonly static int NUMBER_OF_ALGORITHMS = ALGORITHM_NAME.Length;
36+
public static int NUMBER_OF_ALGORITHMS;
3737

3838
/// <summary>
3939
/// Price decrease steps for all algorithms.
4040
/// </summary>
41-
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 };
41+
public static double[] PRICE_DECREASE_STEP;
4242

4343
/// <summary>
44-
/// Price decrase interval - it is 10 minutes.
44+
/// Minimal speed limit for order.
4545
/// </summary>
46-
public readonly static TimeSpan PRICE_DECREASE_INTERVAL = new TimeSpan(0, 10, 1);
46+
public static double[] MINIMAL_LIMIT;
47+
48+
/// <summary>
49+
/// Algorithm multiplier used for limit (to get GH/s speed).
50+
/// </summary>
51+
public static double[] ALGORITHM_MULTIPLIER;
52+
53+
/// <summary>
54+
/// Algorithm speed text.
55+
/// </summary>
56+
public static string[] SPEED_TEXT;
57+
58+
/// <summary>
59+
/// Price decrase interval.
60+
/// </summary>
61+
public static TimeSpan PRICE_DECREASE_INTERVAL;
4762

4863
/// <summary>
4964
/// API ID.
@@ -70,8 +85,8 @@ public class APIWrapper
7085
#region PRIVATE_PROPERTIES
7186

7287
private static object CacheLock = new object();
73-
private static CachedOrderList[,] CachedOList = new CachedOrderList[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
74-
private static CachedStats[,] CachedSList = new CachedStats[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
88+
private static CachedOrderList[,] CachedOList;
89+
private static CachedStats[,] CachedSList;
7590

7691
#endregion
7792

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

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

138+
139+
Result<APIBuyInfo> R = Request<Result<APIBuyInfo>>(0, "buy.info", false, null);
140+
if (R == null)
141+
{
142+
LibConsole.WriteLine(LibConsole.TEXT_TYPE.ERROR, "Unable to get buy information. Service unavailable.");
143+
return false;
144+
}
145+
146+
PRICE_DECREASE_INTERVAL = new TimeSpan(0, 0, R.Data.DownStepTime);
147+
ALGORITHM_NAME = new string[R.Data.Algorithms.Length];
148+
PRICE_DECREASE_STEP = new double[R.Data.Algorithms.Length];
149+
ALGORITHM_MULTIPLIER = new double[R.Data.Algorithms.Length];
150+
MINIMAL_LIMIT = new double[R.Data.Algorithms.Length];
151+
SPEED_TEXT = new string[R.Data.Algorithms.Length];
152+
for (int i = 0; i < R.Data.Algorithms.Length; i++)
153+
{
154+
ALGORITHM_NAME[i] = R.Data.Algorithms[i].Name;
155+
PRICE_DECREASE_STEP[i] = R.Data.Algorithms[i].PriceDownStep;
156+
ALGORITHM_MULTIPLIER[i] = R.Data.Algorithms[i].Multiplier;
157+
MINIMAL_LIMIT[i] = R.Data.Algorithms[i].MinimalLimit;
158+
SPEED_TEXT[i] = R.Data.Algorithms[i].SpeedText;
159+
}
160+
161+
NUMBER_OF_ALGORITHMS = ALGORITHM_NAME.Length;
162+
163+
CachedOList = new CachedOrderList[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
164+
CachedSList = new CachedStats[SERVICE_LOCATION.Length, NUMBER_OF_ALGORITHMS];
165+
166+
LibConsole.WriteLine(LibConsole.TEXT_TYPE.INFO, "Buy information loaded.");
167+
123168
ValidAuthorization = true;
169+
124170
return true;
125171
}
126172

src/NiceHashBotLib/NiceHashBotLib.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
</ItemGroup>
4242
<ItemGroup>
4343
<Compile Include="APIBalance.cs" />
44+
<Compile Include="APIBuyInfo.cs" />
4445
<Compile Include="APIError.cs" />
4546
<Compile Include="APIMethodVersion.cs" />
4647
<Compile Include="APIOrdersGet.cs" />

src/NiceHashBotLib/OrderInstance.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private bool IncreasePrice(Order MyOrder, Order[] AllOrders, double MinimalPrice
246246
}
247247

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

251251
if (MaxPrice >= MinimalPrice)
252252
{

0 commit comments

Comments
 (0)