Skip to content

Commit

Permalink
improved err handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bl4z committed Nov 4, 2020
1 parent b35028a commit 9152e72
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 263 deletions.
28 changes: 2 additions & 26 deletions NHB3/ApiConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,6 @@ public ApiSettings readSettings() {
return new ApiSettings();
}

public OrdersSettings readOrdersSettings()
{
String fileName = Path.Combine(Directory.GetCurrentDirectory(), "orders.json");
if (File.Exists(fileName))
{
OrdersSettings saved = JsonConvert.DeserializeObject<OrdersSettings>(File.ReadAllText(@fileName));
return saved;
}
return new OrdersSettings();
}

public JObject getAlgo(string algo) {
foreach (JObject obj in algorithms)
{
Expand All @@ -263,8 +252,8 @@ private string getApiUrl(int Enviorment)
if (Enviorment == 1)
{
return "https://api2.nicehash.com";
}
else if (Enviorment == 99) {
} else if (Enviorment == 99)
{
return "https://api-test-dev.nicehash.com";
}
return "https://api-test.nicehash.com";
Expand All @@ -280,18 +269,5 @@ public class ApiSettings

public int Enviorment { get; set; }
}

public class OrdersSettings
{
public List<OrderSettings> OrderList { get; set; }
}

public class OrderSettings
{

public string Id { get; set; }

public string MaxPrice { get; set; }
}
}
}
44 changes: 4 additions & 40 deletions NHB3/Home.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public Home()
ac = new ApiConnect();

ApiSettings saved = ac.readSettings();
OrdersSettings orders = ac.readOrdersSettings();

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

private void refreshOrders(bool fromThread)
{
//read custom order settings
ApiConnect.OrdersSettings cos = ac.readOrdersSettings();

if (ac.connected)
{
orders = ac.getOrders();
Expand All @@ -131,9 +127,6 @@ private void refreshOrders(bool fromThread)
cleanOrder.Add("limit", "" + order["limit"]);
cleanOrder.Add("price", "" + order["price"]);

//max price
cleanOrder.Add("maxPrice", getMaxPrice("" + order["id"], cos));

cleanOrder.Add("rigsCount", "" + order["rigsCount"]);
cleanOrder.Add("acceptedCurrentSpeed", "" + order["acceptedCurrentSpeed"]);
cleanOrders.Add(cleanOrder);
Expand All @@ -157,17 +150,6 @@ private void refreshOrders(bool fromThread)
}
}

private string getMaxPrice(string id, ApiConnect.OrdersSettings cos) {
foreach (var order in cos.OrderList)
{
if (id.Equals(order.Id))
{
return order.MaxPrice;
}
}
return "";
}

private void refreshMarket() {
if (ac.connected)
{
Expand Down Expand Up @@ -218,9 +200,6 @@ private void runBot() {

toolStripStatusLabel1.Text = "Working";

//read order individual settings
ApiConnect.OrdersSettings cos = ac.readOrdersSettings();

BotSettings saved = JsonConvert.DeserializeObject<BotSettings>(File.ReadAllText(@fileName));
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("bot iteration tasks {0} {1} {2}", saved.reffilOrder, saved.lowerPrice, saved.increasePrice);
Expand Down Expand Up @@ -261,35 +240,20 @@ private void runBot() {
string order_type = "" + order["type"]["code"];
if (order_type.Equals("STANDARD"))
{
//get order custom settings
String omp = getMaxPrice("" + order["id"], cos);
float maxOrderPriceLimit = 0F;
if (!String.IsNullOrEmpty(omp)) {
maxOrderPriceLimit = float.Parse("" + omp, CultureInfo.InvariantCulture);
}

JObject algo = ac.getAlgo("" + order["algorithm"]["algorithm"]);
float order_speed = float.Parse("" + order["acceptedCurrentSpeed"], CultureInfo.InvariantCulture);
float rigs_count = float.Parse("" + order["rigsCount"], CultureInfo.InvariantCulture);
float order_price = float.Parse("" + order["price"], CultureInfo.InvariantCulture);
float price_step_down = float.Parse("" + algo["priceDownStep"], CultureInfo.InvariantCulture);

Console.ForegroundColor = ConsoleColor.Green;
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);
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);

if (saved.increasePrice && (order_speed == 0 || rigs_count == 0)) {
float new_price = (float)Math.Round(order_price + (price_step_down * -1), 4);

if (maxOrderPriceLimit > 0 && new_price > maxOrderPriceLimit) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("===> price up denied - max limit enforced {0} {1}", new_price, maxOrderPriceLimit);
}
else
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("===> price up order to {0}", new_price);
ac.updateOrder("" + order["algorithm"]["algorithm"], "" + order["id"], new_price.ToString(new CultureInfo("en-US")), "" + order["limit"]);
}
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("===> price up order to {0}", new_price);
ac.updateOrder("" + order["algorithm"]["algorithm"], "" + order["id"], new_price.ToString(new CultureInfo("en-US")), "" + order["limit"]);
} else if (saved.lowerPrice && (order_speed > 0 || rigs_count > 0)) {
Dictionary<string, float> market = getOrderPriceRangesForAlgoAndMarket("" + order["algorithm"]["algorithm"], "" + order["market"]);
var list = market.Keys.ToList();
Expand Down
170 changes: 46 additions & 124 deletions NHB3/OrderForm.Designer.cs

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

Loading

0 comments on commit 9152e72

Please sign in to comment.