In this small tutorial we will install the python API for ethermine to connect to their services and gather information. We will code a small example to show the monthly average hashrate based on the data gathered.

1) Installation

Install via PIP:

pip install ethermine

2) Use

The names of the objects and variables are pretty self-explanatory. The complete guide on the available objects is in https://ethermine.org/api/pool. Let’s get to code!

First import ethermine and the time library which will be used later on to convert from epoch time to human readable time:

from ethermine import Ethermine
import time

Then, create an Ethermine() object to get its history.

Remember to change “address” for your current miner address

ethermine = Ethermine() 
history = ethermine.miner_history("address")

In this example we will be focusing on two indicators, the “currentHashrate” and the “averageHashrate”.

The monthly average hashrate will be obtained by adding up all the values in “currentHashrate” and then dividing them by the number of datapoints.

The averageHashrate is an average performed over the last 12 hours or so and recorded. It could be redundant to use the averageHashrate to get a monthly average, but in this example we will use it anyways just to demonstrate that there are no significant differences between the currentHashrate and the averageHashrate when it comes to a monthly hashrate average.

monthCurrentHashrate = 0
monthAverageHashrate = 0

for item in enumerate(history):
    timeEpoch = item[1]['time']

    currentHashrate = item[1]['currentHashrate']
    monthCurrentHashrate += int(currentHashrate)

    averageHashrate = item[1]['averageHashrate']
    monthAverageHashrate += int(averageHashrate)

monthCurrentHashrate = monthCurrentHashrate / len(history)
monthAverageHashrate = monthAverageHashrate / len(history)

print('monthCurrentHashrate = ' + str(monthCurrentHashrate/1000000) + ' MHs')
print('monthAverageHashrate = ' + str(monthAverageHashrate/1000000) + ' MHs')
print('From ' + str(time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime(history[0]['time']))))
print('To ' + str(time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime(history[len(history) - 1]['time']))))

That´s it! We should get some output like the following:

monthCurrentHashrate = 697.6938710502284 MHs
monthAverageHashrate = 697.6651380776256 MHs
From Sun, 30 Jan 2022 23:10:00 Central Standard Time (Mexico)
To Tue, 01 Feb 2022 11:30:00 Central Standard Time (Mexico)

More examples & info

If you want to get more data, you could try out one of the following pieces of code to get more data points:

stats = ethermine.pool_stats()
print(stats)
dashboard = ethermine.miner_dashboard("address")
print(dashboard)
history = ethermine.miner_history("9de66eC1FCa0Fb7D2d3916C1Dd3e9B86bD3B05e6")
print('Number of records: ' + str(len(history)))
print(history)

Hope it was useful to you! If you want more info and examples you can find them in the python pip project description webpage ethermine 0.2.0

Leave a Reply

Your email address will not be published.