fix: switch gwei command source

This commit is contained in:
jose-donato
2021-10-20 01:08:19 +01:00
committed by GitHub
parent f29565cf18
commit f833493707
5 changed files with 70 additions and 47 deletions

View File

@@ -0,0 +1,52 @@
import pandas as pd
import requests
def get_gwei_fees() -> pd.DataFrame:
"""Returns the most recent Ethereum gas fees in gwei
[Source: https://ethgasstation.info]
Parameters
----------
Returns
-------
pd.DataFrame
four gas fees and durations
(fees for slow, average, fast and
fastest transactions in gwei and
its average durations in seconds)
"""
r = requests.get("https://ethgasstation.info/json/ethgasAPI.json")
if r.status_code == 200:
try:
apiData = r.json()
return pd.DataFrame(
data=[
[
"Fastest",
int(apiData["fastest"] / 10),
round(apiData["fastestWait"], 1),
],
["Fast", int(apiData["fast"] / 10), round(apiData["fastWait"], 1)],
[
"Average",
int(apiData["average"] / 10),
round(apiData["avgWait"], 1),
],
[
"Slow",
int(apiData["safeLow"] / 10),
round(apiData["safeLowWait"], 1),
],
],
columns=["Tx Type", "Fee (gwei)", "Duration (min)"],
)
except TypeError:
print("Error in ethgasstation JSON response.\n")
return pd.DataFrame()
else:
print("Error in ethgasstation GET request\n")
return pd.DataFrame()

View File

@@ -2,13 +2,13 @@ import os
from tabulate import tabulate
from gamestonk_terminal.helper_funcs import export_data
from gamestonk_terminal.cryptocurrency.onchain.gasnow_model import get_gwei_fees
from gamestonk_terminal.cryptocurrency.onchain.ethgasstation_model import get_gwei_fees
from gamestonk_terminal import feature_flags as gtff
def display_gwei_fees(export: str) -> None:
"""Current gwei fees
[Source: https://www.gasnow.org]
[Source: https://ethgasstation.info]
Parameters
----------

View File

@@ -1,40 +0,0 @@
import pandas as pd
import requests
def get_gwei_fees() -> pd.DataFrame:
"""Returns the most recent Ethereum gas fees in gwei
[Source: https://www.gasnow.org]
Parameters
----------
Returns
-------
pd.DataFrame
four gas fees and durations
(fees for slow, average, fast and
fastest transactions in gwei and
its average durations in seconds)
"""
r = requests.get("https://www.gasnow.org/api/v3/gas/price")
if r.status_code == 200:
try:
data = r.json()["data"]
return pd.DataFrame(
data=[
["Fastest", int(data["rapid"] / 1_000_000_000), "~15 sec"],
["Fast", int(data["fast"] / 1_000_000_000), "~1 min"],
["Standard", int(data["standard"] / 1_000_000_000), "~3 min"],
["Slow", int(data["slow"] / 1_000_000_000), ">10 min"],
],
columns=["Tx Type", "Fee (gwei)", "Duration"],
)
except TypeError:
print("Error in gasnow JSON response.\n")
return pd.DataFrame()
else:
print("Error in gasnow GET request\n")
return pd.DataFrame()

View File

@@ -15,7 +15,10 @@ from gamestonk_terminal.helper_funcs import (
check_int_range,
)
from gamestonk_terminal.cryptocurrency.onchain import gasnow_view, whale_alert_view
from gamestonk_terminal.cryptocurrency.onchain import (
ethgasstation_view,
whale_alert_view,
)
# pylint: disable=R1732
@@ -102,7 +105,7 @@ class OnchainController:
prog="onchain",
description="""
Display ETH gas fees
[Source: https://www.gasnow.org]
[Source: https://ethgasstation.info]
""",
)
@@ -121,7 +124,7 @@ class OnchainController:
if not ns_parser:
return
gasnow_view.display_gwei_fees(export=ns_parser.export)
ethgasstation_view.display_gwei_fees(export=ns_parser.export)
except Exception as e:
print(e, "\n")

View File

@@ -2,8 +2,7 @@
usage: onchain [--export {csv,json,xlsx}] [-h]
```
Display ETH gas fees [Source: https://www.gasnow.org]
Display ETH gas fees [Source: https://ethgasstation.info]
```
optional arguments:
@@ -11,3 +10,12 @@ optional arguments:
Export dataframe data to csv,json,xlsx file (default: )
-h, --help show this help message (default: False)
```
Example output:
| Tx Type | Fee (gwei) | Duration (min) |
| ------- | ---------- | -------------- |
| Fastest | 108 | 0.4 |
| Fast | 95 | 0.5 |
| Average | 72 | 4.0 |
| Slow | 68 | 11.9 |