Skip to content

Instantly share code, notes, and snippets.

@lazear
Created June 12, 2017 21:37
Show Gist options
  • Save lazear/4c31f7af34556805ed37239905947834 to your computer and use it in GitHub Desktop.
Save lazear/4c31f7af34556805ed37239905947834 to your computer and use it in GitHub Desktop.
import json
import requests
import time
algorithm_id_to_str = [
"Scrypt",
"SHA256",
"ScryptNf",
"X11",
"X13",
"Keccak",
"X15",
"Nist5",
"NeoScrypt",
"Lyra2RE",
"WhirlpoolX",
"Qubit",
"Quark",
"Axiom",
"Lyra2REv2",
"ScryptJaneNf16",
"Blake256r8",
"Blake256r14",
"Blake256r8vnl",
"Hodl",
"DaggerHashimoto",
"Decred",
"CryptoNight",
"Lbry",
"Equihash",
"Pascal",
"X11Gost",
"Sia"
]
def get_average_rate(data, timespan):
''' timespan is a tuple of format (timestamp_start, timestamp_end)
i.e. (4991008, 4991108) '''
rate = 0.0
for packet in data:
if len(packet) != 3:
return -1
timestamp = packet[0]
if (timestamp > timespan[0]) and (timestamp < timespan[1]):
rate += float(packet[1].get('a', '0.0'))
return round(rate / (timespan[1] - timespan[0]), 4)
url = 'https://api.nicehash.com/api?method=stats.provider.ex&addr=1DM7mqR6fvcWW8JwZB6X6xgT8CsAiqmpj4'
print(url)
resp = requests.get(url=url)
data = json.loads(resp.text)
results = data.get('result', {})
#print(results)
if 'error' in results:
print('API request quota overflow')
exit()
total_profitability = 0.0
print("Current hash rates")
for algo in results.get('current'):
r = algo.get('data', {})[0]
if len(r) != 0:
current_hash = round(float(algo.get('data', {})[0].get("a", "0.0")), 4)
profitability = round(current_hash * float(algo.get('profitability', "0.0")), 8)
total_profitability += profitability
print("{0} @ {1} {2}/s = {3} BTC/day".format(algo.get("name"), current_hash, algo.get("suffix"), profitability))
print("Current profitability: {0} mBTC/day".format(total_profitability * 1000.0))
t = int(time.time() / 300)
start = time.strftime("%D %H:%M", time.localtime((t - 120) * 300))
end = time.strftime("%D %H:%M", time.localtime(t * 300))
print('\nAverage rates from {0} to {1}'.format(start, end))
for algorithm in results.get('past'):
print(algorithm_id_to_str[algorithm.get('algo')], get_average_rate(algorithm.get('data', []), (t - 15, t)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment