diff --git a/config.yml b/config.yml index 78ac349..367eaed 100644 --- a/config.yml +++ b/config.yml @@ -5,6 +5,7 @@ # NiceHash Auth Config NICEHASH_API_ID: "" # NiceHash API ID (here, or set it as an environment variable) NICEHASH_API_KEY: "" # NiceHash API Key (here, or set it as an environment variable) + NICEHASH_ORG_ID: "" # NiceHash ORG ID (here, or set it as an environment variable) # NiceHash Order Config POOL_NAME: "defender" # Must exist in "MY POOLS" NiceHash configuration and point to a C32 pool diff --git a/grin_nicehash_defender.py b/grin_nicehash_defender.py index 8cf8cb0..9a009d6 100755 --- a/grin_nicehash_defender.py +++ b/grin_nicehash_defender.py @@ -58,9 +58,11 @@ def getConfig(self): self.config["NICEHASH_API_ID"] = os.environ["NICEHASH_API_ID"] if self.config["NICEHASH_API_KEY"] == "": self.config["NICEHASH_API_KEY"] = os.environ["NICEHASH_API_KEY"] - self.nh_api.setAuth(self.config["NICEHASH_API_ID"], self.config["NICEHASH_API_KEY"]) + if self.config["NICEHASH_ORG_ID"] == "": + self.config["NICEHASH_ORG_ID"] = os.environ["NICEHASH_ORG_ID"] + self.nh_api.setAuth(self.config["NICEHASH_API_ID"], self.config["NICEHASH_API_KEY"], self.config["NICEHASH_ORG_ID"]) except Exception as e: - logger.error("Failed to find NICEHASH_API_ID and NICEHASH_API_KEY: {}".format(e)) + logger.error("Failed to find NICEHASH_API_ID and/or NICEHASH_API_KEY and/or NICEHASH_ORG_ID: {}".format(e)) sys.exit(1) try: self.nh_pool_id = self.nh_api.getPoolId(self.config["POOL_NAME"]) diff --git a/nicehash_api.py b/nicehash_api.py index 55f2171..a733d14 100755 --- a/nicehash_api.py +++ b/nicehash_api.py @@ -36,9 +36,10 @@ ## -- class NiceHash(): - def __init__(self, API_ID="", API_KEY="", logger=None): + def __init__(self, API_ID="", API_KEY="", ORG_ID="", logger=None): self.API_ID = API_ID self.API_KEY = API_KEY + self.ORG_ID = ORG_ID self.mfd = {} if logger is not None: self.logger = logger @@ -47,9 +48,10 @@ def __init__(self, API_ID="", API_KEY="", logger=None): self.logger = logging.getLogger("gnd") - def setAuth(self, nhid, nhkey): + def setAuth(self, nhid, nhkey, nhorg): self.API_ID = nhid self.API_KEY = nhkey + self.ORG_ID = nhorg def call_nicehash_api(self, path, method, args=None, body=None): url = "https://api2.nicehash.com" @@ -80,6 +82,7 @@ def call_nicehash_api(self, path, method, args=None, body=None): nonce + \ zero_byte_field + \ zero_byte_field + \ + self.ORG_ID + \ zero_byte_field + \ zero_byte_field + \ method + \ @@ -98,6 +101,7 @@ def call_nicehash_api(self, path, method, args=None, body=None): 'Content-type': 'application/json', "X-Time": timestamp, "X-Nonce": nonce, + "X-Organization-ID": self.ORG_ID, } if self.API_ID != "" and self.API_KEY != "": headers["X-Auth"] = self.API_ID + ":" + signature @@ -343,7 +347,7 @@ def getCurrentSpeed(self, market, algo): def main(): # Some Tests nh_api = NiceHash() - nh_api.setAuth("x", "y") + nh_api.setAuth(os.getenv("NICEHASH_API_ID"), os.getenv("NICEHASH_API_KEY"), os.getenv("NICEHASH_ORG_ID")) p = nh_api.getCurrentPrice("EU", "GRINCUCKATOO32") print("Current Price EU: {}".format(p)) p = nh_api.getCurrentPrice("USA", "GRINCUCKATOO32")