Skip to content

Commit

Permalink
enforce price limit
Browse files Browse the repository at this point in the history
  • Loading branch information
bladedoyle committed Nov 22, 2020
1 parent 34ccd9e commit cff5b92
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions grin_nicehash_defender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions nicehash_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ 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,
body = createOrder_body,
method = "POST",
)
order = result
self.logger.warn("order: {}".format(order))
except Exception as e:
self.logger.error("failed createOrder(): {}".format(e))
raise
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cff5b92

Please sign in to comment.