From cff5b92ae153df40ea711ac16dce3133e82de8a1 Mon Sep 17 00:00:00 2001 From: Blade Doyle Date: Sun, 22 Nov 2020 15:02:20 -0800 Subject: [PATCH] enforce price limit --- grin_nicehash_defender.py | 10 +++++++--- nicehash_api.py | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/grin_nicehash_defender.py b/grin_nicehash_defender.py index 679649b..86bf9f1 100755 --- a/grin_nicehash_defender.py +++ b/grin_nicehash_defender.py @@ -80,8 +80,11 @@ def getConfig(self): def checkForAttack(self): attack = False if self.config["CHECK_TYPE"] == "file": + file_stats = {"exists": False} if os.path.exists('attack'): attack = True + file_stats["exists"] = True + self.attack_stats["file"] = file_stats elif self.config["CHECK_TYPE"] == "grin51": attack = self.grin51.under_attack self.attack_stats = self.grin51.get_stats() @@ -108,8 +111,9 @@ def checkForAttack(self): def manageOrders(self): if self.attack_start is not None: try: - eu_price = self.nh_api.getCurrentPrice("EU", "GRINCUCKATOO32") + self.config["ORDER_PRICE_ADD"] - us_price = self.nh_api.getCurrentPrice("USA", "GRINCUCKATOO32") + self.config["ORDER_PRICE_ADD"] + eu_price = min(self.nh_api.getCurrentPrice("EU", "GRINCUCKATOO32") + self.config["ORDER_PRICE_ADD"], self.config["MAX_PRICE"]) + us_price = min(self.nh_api.getCurrentPrice("USA", "GRINCUCKATOO32") + self.config["ORDER_PRICE_ADD"], self.config["MAX_PRICE"]) + logger.warn("nh eu_price: {}, nh us_price: {}".format(eu_price, us_price)) except Exception as e: logger.error("Error getting NH price data: {}".format(e)) return @@ -146,7 +150,7 @@ def manageOrders(self): self.nh_orders["USA"] = new_order["id"] logger.warning("Created USA Order: {}".format(self.nh_orders["USA"])) # XXX DEBUGGING XXX -# self.nh_orders["USA"] = "8ef742e2-6a8c-4c19-b46c-d96b2050a43f" +# self.nh_orders["USA"] = "a1bd4612-1279-4fd6-be79-137384b54c7f" # XXX DEBUGGING XXX except Exception as e: logger.error("Error creating USA order: {}".format(e)) diff --git a/nicehash_api.py b/nicehash_api.py index b7e93b1..55f2171 100755 --- a/nicehash_api.py +++ b/nicehash_api.py @@ -227,6 +227,7 @@ def createOrder(self, algo, market, pool_id, price, speed, amount): "marketFactor": marketFactor, "displayMarketFactor": displayMarketFactor.encode(), } + self.logger.warn("createOrder_body: {}".format(createOrder_body)) try: result = self.call_nicehash_api( path = createOrder_path, @@ -234,6 +235,7 @@ def createOrder(self, algo, market, pool_id, price, speed, amount): method = "POST", ) order = result + self.logger.warn("order: {}".format(order)) except Exception as e: self.logger.error("failed createOrder(): {}".format(e)) raise @@ -304,12 +306,14 @@ def updateOrder(self, algo, order_id, speed, price): "limit": "{:.2f}".format(float(speed)), "price": "{:.4f}".format(float(price)), } + self.logger.warn("increasePrice_body: {}".format(increasePrice_body)) try: result = self.call_nicehash_api( path = increasePrice_path, body = increasePrice_body, method = "POST", ) + self.logger.warn("updated order: {}".format(result)) except Exception as e: self.logger.error("failed updateOrder(): {}".format(e)) raise