Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # usage example
- # obj = nicehash_request("/main/api/v2/accounting/accounts2","fiat=USD")
- def nicehash_request(url, query=""):
- start = utime.ticks_ms()
- localtime = str('{0:f}'.format(get_time(False,True) * 1000)).split('.')[0] # epoch in ms
- nonce = str(uuid.uuid4())
- reqid = str(uuid.uuid4())
- message = bytearray(secrets['nicehash_key'],"utf-8") # api key
- message += b'\x00'
- message += bytearray(localtime,"utf-8")
- message += b'\x00'
- message += bytearray(nonce,"utf-8")
- message += b'\x00'
- message += b'\x00'
- message += bytearray(secrets['nicehash_org'],"utf-8") # api organization
- message += b'\x00'
- message += b'\x00'
- message += bytearray("GET","utf-8")
- message += b'\x00'
- message += bytearray(url,"utf-8")
- if query != "":
- message += b'\x00'
- message += bytearray(query,"utf-8")
- hmacs = hmac.HMAC(bytearray(secrets['nicehash_secret'],"utf-8"), message, hashlib.sha256) # api secret
- hashed_string = hmacs.hexdigest()
- auth = secrets['nicehash_key']+":"+hashed_string; # api key
- headers = {
- "X-Time": localtime,
- "X-Nonce": nonce,
- "X-Organization-ID": secrets['nicehash_org'], # api organization
- "X-Request-ID": reqid,
- "X-Auth": auth
- }
- response = urequests.get("https://api2.nicehash.com"+url+"?"+query, headers=headers)
- obj = json.loads(response.text)
- response.close()
- delta = utime.ticks_diff(utime.ticks_ms(), start)
- debug("Received response from Nicehash API (took "+str(delta)+"ms)")
- return obj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement