-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgas_tracker.py
More file actions
50 lines (39 loc) · 1.57 KB
/
gas_tracker.py
File metadata and controls
50 lines (39 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from datetime import datetime, timedelta
from brownie import *
import plotext as plt
import time
network.connect('arbitrum-main')
graph_width = timedelta(days=1).total_seconds()
points_x_count = 24*60 # amount of measurements for given graph width
sleep_time = graph_width/points_x_count
plt.title(network.show_active() + " gas history for last 24 hours")
plt.ylabel("Gas price")
x, y = [], []
while True:
plt.clear_terminal()
plt.clear_data()
#plt.plot_size(width=plt.terminal_width(), height=plt.terminal_height())
date_time, gas_price = None, None
while gas_price is None:
try:
date_time = int(datetime.now().timestamp())
gas_price = float(web3.fromWei(web3.eth.gas_price, 'gwei'))
except Exception as e:
print(f'Getting gas price caused error {e}')
x.append(date_time)
y.append(gas_price)
if len(x) > points_x_count:
x.pop(0)
y.pop(0)
xticks = [x[0] + timedelta(hours=i).total_seconds() for i in range(25)]
xlabels = [datetime.fromtimestamp(tick).strftime("%H:%M") for tick in xticks]
plt.xticks(xticks, xlabels)
# setting xlabel to current day
plt.xlabel("Starting date " + datetime.fromtimestamp(x[0]).strftime("%d/%m/%Y"))
# setting x axis limit to first element timestamp + 1 day
plt.xlim(x[0], x[0] + timedelta(days=1).total_seconds())
# setting y axis limit to 110% of max value
plt.ylim(0, float(max(y))*1.1)
plt.plot(x, y)
plt.show()
time.sleep(sleep_time)