Skip to content

Commit 9152e72

Browse files
committed
improved err handling
1 parent b35028a commit 9152e72

File tree

4 files changed

+97
-263
lines changed

4 files changed

+97
-263
lines changed

NHB3/ApiConnect.cs

+2-26
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,6 @@ public ApiSettings readSettings() {
236236
return new ApiSettings();
237237
}
238238

239-
public OrdersSettings readOrdersSettings()
240-
{
241-
String fileName = Path.Combine(Directory.GetCurrentDirectory(), "orders.json");
242-
if (File.Exists(fileName))
243-
{
244-
OrdersSettings saved = JsonConvert.DeserializeObject<OrdersSettings>(File.ReadAllText(@fileName));
245-
return saved;
246-
}
247-
return new OrdersSettings();
248-
}
249-
250239
public JObject getAlgo(string algo) {
251240
foreach (JObject obj in algorithms)
252241
{
@@ -263,8 +252,8 @@ private string getApiUrl(int Enviorment)
263252
if (Enviorment == 1)
264253
{
265254
return "https://api2.nicehash.com";
266-
}
267-
else if (Enviorment == 99) {
255+
} else if (Enviorment == 99)
256+
{
268257
return "https://api-test-dev.nicehash.com";
269258
}
270259
return "https://api-test.nicehash.com";
@@ -280,18 +269,5 @@ public class ApiSettings
280269

281270
public int Enviorment { get; set; }
282271
}
283-
284-
public class OrdersSettings
285-
{
286-
public List<OrderSettings> OrderList { get; set; }
287-
}
288-
289-
public class OrderSettings
290-
{
291-
292-
public string Id { get; set; }
293-
294-
public string MaxPrice { get; set; }
295-
}
296272
}
297273
}

NHB3/Home.cs

+4-40
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public Home()
3131
ac = new ApiConnect();
3232

3333
ApiSettings saved = ac.readSettings();
34-
OrdersSettings orders = ac.readOrdersSettings();
3534

3635
if (saved.OrganizationID != null) {
3736
ac.setup(saved);
@@ -102,9 +101,6 @@ private void refreshBalance() {
102101

103102
private void refreshOrders(bool fromThread)
104103
{
105-
//read custom order settings
106-
ApiConnect.OrdersSettings cos = ac.readOrdersSettings();
107-
108104
if (ac.connected)
109105
{
110106
orders = ac.getOrders();
@@ -131,9 +127,6 @@ private void refreshOrders(bool fromThread)
131127
cleanOrder.Add("limit", "" + order["limit"]);
132128
cleanOrder.Add("price", "" + order["price"]);
133129

134-
//max price
135-
cleanOrder.Add("maxPrice", getMaxPrice("" + order["id"], cos));
136-
137130
cleanOrder.Add("rigsCount", "" + order["rigsCount"]);
138131
cleanOrder.Add("acceptedCurrentSpeed", "" + order["acceptedCurrentSpeed"]);
139132
cleanOrders.Add(cleanOrder);
@@ -157,17 +150,6 @@ private void refreshOrders(bool fromThread)
157150
}
158151
}
159152

160-
private string getMaxPrice(string id, ApiConnect.OrdersSettings cos) {
161-
foreach (var order in cos.OrderList)
162-
{
163-
if (id.Equals(order.Id))
164-
{
165-
return order.MaxPrice;
166-
}
167-
}
168-
return "";
169-
}
170-
171153
private void refreshMarket() {
172154
if (ac.connected)
173155
{
@@ -218,9 +200,6 @@ private void runBot() {
218200

219201
toolStripStatusLabel1.Text = "Working";
220202

221-
//read order individual settings
222-
ApiConnect.OrdersSettings cos = ac.readOrdersSettings();
223-
224203
BotSettings saved = JsonConvert.DeserializeObject<BotSettings>(File.ReadAllText(@fileName));
225204
Console.ForegroundColor = ConsoleColor.Green;
226205
Console.WriteLine("bot iteration tasks {0} {1} {2}", saved.reffilOrder, saved.lowerPrice, saved.increasePrice);
@@ -261,35 +240,20 @@ private void runBot() {
261240
string order_type = "" + order["type"]["code"];
262241
if (order_type.Equals("STANDARD"))
263242
{
264-
//get order custom settings
265-
String omp = getMaxPrice("" + order["id"], cos);
266-
float maxOrderPriceLimit = 0F;
267-
if (!String.IsNullOrEmpty(omp)) {
268-
maxOrderPriceLimit = float.Parse("" + omp, CultureInfo.InvariantCulture);
269-
}
270-
271243
JObject algo = ac.getAlgo("" + order["algorithm"]["algorithm"]);
272244
float order_speed = float.Parse("" + order["acceptedCurrentSpeed"], CultureInfo.InvariantCulture);
273245
float rigs_count = float.Parse("" + order["rigsCount"], CultureInfo.InvariantCulture);
274246
float order_price = float.Parse("" + order["price"], CultureInfo.InvariantCulture);
275247
float price_step_down = float.Parse("" + algo["priceDownStep"], CultureInfo.InvariantCulture);
276248

277249
Console.ForegroundColor = ConsoleColor.Green;
278-
Console.WriteLine("?adjust price?; order {0}, speed {1}, rigs {2}, price {3}, step_down {4}, max order limit {5}", order["id"], order_speed, rigs_count, order_price, price_step_down, maxOrderPriceLimit);
250+
Console.WriteLine("?adjust price?; order {0}, speed {1}, rigs {2}, price {3}, step_down {4}", order["id"], order_speed, rigs_count, order_price, price_step_down);
279251

280252
if (saved.increasePrice && (order_speed == 0 || rigs_count == 0)) {
281253
float new_price = (float)Math.Round(order_price + (price_step_down * -1), 4);
282-
283-
if (maxOrderPriceLimit > 0 && new_price > maxOrderPriceLimit) {
284-
Console.ForegroundColor = ConsoleColor.Red;
285-
Console.WriteLine("===> price up denied - max limit enforced {0} {1}", new_price, maxOrderPriceLimit);
286-
}
287-
else
288-
{
289-
Console.ForegroundColor = ConsoleColor.Yellow;
290-
Console.WriteLine("===> price up order to {0}", new_price);
291-
ac.updateOrder("" + order["algorithm"]["algorithm"], "" + order["id"], new_price.ToString(new CultureInfo("en-US")), "" + order["limit"]);
292-
}
254+
Console.ForegroundColor = ConsoleColor.Yellow;
255+
Console.WriteLine("===> price up order to {0}", new_price);
256+
ac.updateOrder("" + order["algorithm"]["algorithm"], "" + order["id"], new_price.ToString(new CultureInfo("en-US")), "" + order["limit"]);
293257
} else if (saved.lowerPrice && (order_speed > 0 || rigs_count > 0)) {
294258
Dictionary<string, float> market = getOrderPriceRangesForAlgoAndMarket("" + order["algorithm"]["algorithm"], "" + order["market"]);
295259
var list = market.Keys.ToList();

NHB3/OrderForm.Designer.cs

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

0 commit comments

Comments
 (0)