Skip to content

Commit

Permalink
nicehash api now requires org id in the request
Browse files Browse the repository at this point in the history
  • Loading branch information
grin committed Jun 25, 2021
1 parent 9ac2d50 commit 6b09e66
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions grin_nicehash_defender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
10 changes: 7 additions & 3 deletions nicehash_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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 + \
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6b09e66

Please sign in to comment.