summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjp <plutakuba@gmail.com>2021-09-25 00:30:07 +0200
committerGitHub <noreply@github.com>2021-09-24 23:30:07 +0100
commit85f48b332e9c1a2519a8321084f0c1485a393131 (patch)
treeaba376af6221eae9970c918ae85daf398df2dfd6
parent78d1678ea6b6a685eb05061d2aa283eb3ab157f5 (diff)
Wales alerts (#760)
* Add separate view for finbrain for crypto curreny sentiment analysis * Move json with symbols to separate directory, little refactoring, update readme * Add screenshot of finbrain for PolkaDot * Add whale alert for crypto menu * Add docs for hugo server * Typo, docs added
-rw-r--r--README.md2
-rw-r--r--gamestonk_terminal/config_terminal.py4
-rw-r--r--gamestonk_terminal/cryptocurrency/onchain/onchain_controller.py105
-rw-r--r--gamestonk_terminal/cryptocurrency/onchain/whale_alert_model.py124
-rw-r--r--gamestonk_terminal/cryptocurrency/onchain/whale_alert_view.py69
-rw-r--r--website/content/cryptocurrency/onchain/whales/_index.md23
6 files changed, 322 insertions, 5 deletions
diff --git a/README.md b/README.md
index 2461ee21146..c756c32378f 100644
--- a/README.md
+++ b/README.md
@@ -267,6 +267,7 @@ These are the ones where a key is necessary:
* Tradier: https://developer.tradier.com/getting_started
* Twitter: https://developer.twitter.com
* Coinbase Pro API: https://docs.pro.coinbase.com/
+* Whale Alert API: https://docs.whale-alert.io/
When these are obtained, don't forget to update [config_terminal.py](/gamestonk_terminal/config_terminal.py).
@@ -290,6 +291,7 @@ Alternatively, you can also set them to the following environment variables:
| [Tradier](https://developer.tradier.com) | GT_TRADIER_TOKEN |
| [Twitter](https://developer.twitter.com) | GT_API_TWITTER_KEY <br/> GT_API_TWITTER_SECRET_KEY <br/> GT_API_TWITTER_BEARER_TOKEN |
| [Coinbase](https://docs.pro.coinbase.com/) | GT_API_COINBASE_KEY <br/> GT_API_COINBASE_SECRET <br/> GT_API_COINBASE_PASS_PHRASE |
+| [Whale Alert](https://docs.whale-alert.io/) | GT_API_WHALE_ALERT_KEY |
Example:
```
diff --git a/gamestonk_terminal/config_terminal.py b/gamestonk_terminal/config_terminal.py
index b81493537f8..e112bae9633 100644
--- a/gamestonk_terminal/config_terminal.py
+++ b/gamestonk_terminal/config_terminal.py
@@ -90,3 +90,7 @@ API_SENTIMENTINVESTOR_TOKEN = (
API_COINBASE_KEY = os.getenv("GT_API_COINBASE_KEY") or "REPLACE_ME"
API_COINBASE_SECRET = os.getenv("GT_API_COINBASE_SECRET") or "REPLACE_ME"
API_COINBASE_PASS_PHRASE = os.getenv("GT_API_COINBASE_PASS_PHRASE") or "REPLACE_ME"
+
+
+# https://docs.whale-alert.io/
+API_WHALE_ALERT_KEY = os.getenv("GT_API_WHALE_ALERT_KEY") or "REPLACE_ME"
diff --git a/gamestonk_terminal/cryptocurrency/onchain/onchain_controller.py b/gamestonk_terminal/cryptocurrency/onchain/onchain_controller.py
index 547e890323c..f1a4fae3b76 100644
--- a/gamestonk_terminal/cryptocurrency/onchain/onchain_controller.py
+++ b/gamestonk_terminal/cryptocurrency/onchain/onchain_controller.py
@@ -8,9 +8,14 @@ from prompt_toolkit.completion import NestedCompleter
from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.menu import session
-from gamestonk_terminal.helper_funcs import get_flair, parse_known_args_and_warn
+from gamestonk_terminal.helper_funcs import (
+ get_flair,
+ parse_known_args_and_warn,
+ check_positive,
+ check_int_range,
+)
-from gamestonk_terminal.cryptocurrency.onchain import gasnow_view
+from gamestonk_terminal.cryptocurrency.onchain import gasnow_view, whale_alert_view
# pylint: disable=R1732
@@ -26,9 +31,7 @@ class OnchainController:
"quit",
]
- CHOICES_COMMANDS = [
- "gwei",
- ]
+ CHOICES_COMMANDS = ["gwei", "whales"]
CHOICES += CHOICES_COMMANDS
@@ -123,6 +126,97 @@ class OnchainController:
except Exception as e:
print(e, "\n")
+ def call_whales(self, other_args: List[str]):
+ """Process whales command"""
+ parser = argparse.ArgumentParser(
+ add_help=False,
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
+ prog="wales",
+ description="""
+ Display crypto whales transactions.
+ [Source: https://docs.whale-alert.io/]
+ """,
+ )
+
+ parser.add_argument(
+ "-m",
+ "--min",
+ dest="min",
+ type=check_int_range(500000, 100 ** 7),
+ help="Minimum value of transactions.",
+ default=1000000,
+ )
+
+ parser.add_argument(
+ "-t",
+ "--top",
+ dest="top",
+ type=check_positive,
+ help="top N number records",
+ default=10,
+ )
+
+ parser.add_argument(
+ "-s",
+ "--sort",
+ dest="sortby",
+ type=str,
+ help="Sort by given column. Default: date",
+ default="date",
+ choices=[
+ "date",
+ "symbol",
+ "blockchain",
+ "amount",
+ "amount_usd",
+ "from",
+ "to",
+ ],
+ )
+ parser.add_argument(
+ "--descend",
+ action="store_false",
+ help="Flag to sort in descending order (lowest first)",
+ dest="descend",
+ default=True,
+ )
+
+ parser.add_argument(
+ "-a",
+ "--address",
+ dest="address",
+ action="store_true",
+ help="Flag to show addresses of transaction",
+ default=False,
+ )
+
+ parser.add_argument(
+ "--export",
+ choices=["csv", "json", "xlsx"],
+ default="",
+ type=str,
+ dest="export",
+ help="Export dataframe data to csv,json,xlsx file",
+ )
+
+ try:
+ ns_parser = parse_known_args_and_warn(parser, other_args)
+
+ if not ns_parser:
+ return
+
+ whale_alert_view.display_whales_transactions(
+ min_value=ns_parser.min,
+ top=ns_parser.top,
+ sortby=ns_parser.sortby,
+ descend=ns_parser.descend,
+ show_address=ns_parser.address,
+ export=ns_parser.export,
+ )
+
+ except Exception as e:
+ print(e)
+
def print_help():
"""Print help"""
@@ -133,6 +227,7 @@ def print_help():
print(" quit quit to abandon program")
print("")
print(" gwei check current eth gas fees")
+ print(" whales check crypto wales transactions")
print("")
diff --git a/gamestonk_terminal/cryptocurrency/onchain/whale_alert_model.py b/gamestonk_terminal/cryptocurrency/onchain/whale_alert_model.py
new file mode 100644
index 00000000000..06554e95b65
--- /dev/null
+++ b/gamestonk_terminal/cryptocurrency/onchain/whale_alert_model.py
@@ -0,0 +1,124 @@
+"""Whale Alert model"""
+__docformat__ = "numpy"
+
+from typing import Optional
+import textwrap
+import requests
+import pandas as pd
+import numpy as np
+import gamestonk_terminal.config_terminal as cfg
+
+
+class ApiKeyException(Exception):
+ """Api Key Exception object"""
+
+ def __init__(self, message: str):
+ super().__init__(message)
+ self.message = message
+
+ def __str__(self) -> str:
+ return "ApiKeyException: %s" % self.message
+
+
+def make_request(params: Optional[dict] = None) -> dict:
+ """Helper methods for requests [Source: https://docs.whale-alert.io/]
+
+ Parameters
+ ----------
+ params: dict
+ additional param
+
+ Returns
+ -------
+ dict:
+ response from api request
+ """
+
+ api_key = cfg.API_WHALE_ALERT_KEY or ""
+ url = "https://api.whale-alert.io/v1/transactions?api_key=" + api_key
+ response = requests.get(url, params=params)
+
+ if not 200 <= response.status_code < 300:
+ raise ApiKeyException("Invalid Authentication: %s" % response.text)
+ try:
+ return response.json()
+ except Exception as e:
+ raise ValueError("Invalid Response: %s" % response.text) from e
+
+
+def get_whales_transactions(min_value: int = 800000, limit: int = 100) -> pd.DataFrame:
+ """Whale Alert's API allows you to retrieve live and historical transaction data from major blockchains.
+ Supported blockchain: Bitcoin, Ethereum, Ripple, NEO, EOS, Stellar and Tron. [Source: https://docs.whale-alert.io/]
+
+ Parameters
+ ----------
+ min_value: int
+ Minimum value of trade to track.
+ limit: int
+ Limit of transactions. Max 100
+
+ Returns
+ -------
+ pd.DataFrame
+ Crypto wales transactions
+ """
+
+ min_value = 800000 if min_value > 800000 else min_value
+ limit = 100 if limit > 100 else limit
+
+ params = {"limit": limit, "min_value": min_value}
+
+ response = make_request(params)
+ data = pd.json_normalize(response["transactions"]).sort_values(
+ "timestamp", ascending=False
+ )
+
+ data["date"] = pd.to_datetime(data["timestamp"], unit="s")
+ data.columns = [col.replace(".address", "") for col in data.columns]
+ data["to_address"] = data["to"].apply(
+ lambda x: "\n".join(textwrap.wrap(x, width=45)) if isinstance(x, str) else x
+ )
+ data["from_address"] = data["from"].apply(
+ lambda x: "\n".join(textwrap.wrap(x, width=45)) if isinstance(x, str) else x
+ )
+
+ data["from"] = data.apply(
+ lambda x: x["from.owner"]
+ if x["from.owner"] not in [np.nan, None, np.NaN]
+ else x["from.owner_type"],
+ axis=1,
+ )
+ data["to"] = data.apply(
+ lambda x: x["to.owner"]
+ if x["to.owner"] not in [np.nan, None, np.NaN]
+ else x["to.owner_type"],
+ axis=1,
+ )
+ data.drop(
+ [
+ "id",
+ "transaction_count",
+ "from.owner_type",
+ "to.owner_type",
+ "to.owner",
+ "from.owner",
+ "transaction_type",
+ "hash",
+ "timestamp",
+ ],
+ axis=1,
+ inplace=True,
+ )
+ return data[
+ [
+ "date",
+ "symbol",
+ "blockchain",
+ "amount",
+ "amount_usd",
+ "from",
+ "to",
+ "from_address",
+ "to_address",
+ ]
+ ]
diff --git a/gamestonk_terminal/cryptocurrency/onchain/whale_alert_view.py b/gamestonk_terminal/cryptocurrency/onchain/whale_alert_view.py
new file mode 100644
index 00000000000..8747a367ae4
--- /dev/null
+++ b/gamestonk_terminal/cryptocurrency/onchain/whale_alert_view.py
@@ -0,0 +1,69 @@
+"""Whale Alert view"""
+__docformat__ = "numpy"
+
+import os
+from tabulate import tabulate
+from gamestonk_terminal.helper_funcs import export_data, long_number_format
+from gamestonk_terminal import feature_flags as gtff
+from gamestonk_terminal.cryptocurrency.onchain import whale_alert_model
+
+
+def display_whales_transactions(
+ min_value: int = 800000,
+ top: int = 100,
+ sortby: str = "date",
+ descend: bool = False,
+ show_address: bool = False,
+ export: str = "",
+) -> None:
+ """Display huge value transactions from major blockchains. [Source: https://docs.whale-alert.io/]
+
+ Parameters
+ ----------
+ min_value: int
+ Minimum value of trade to track.
+ top: int
+ Limit of transactions. Maximum 100
+ sortby: str
+ Key to sort by.
+ descend: str
+ Sort in descending order.
+ show_address: bool
+ Flag to show addresses of transactions.
+ export : str
+ Export dataframe data to csv,json,xlsx file
+ """
+
+ df = whale_alert_model.get_whales_transactions(min_value)
+ df_data = df.copy()
+
+ df = df.sort_values(by=sortby, ascending=descend)
+
+ if not show_address:
+ df = df.drop(["from_address", "to_address"], axis=1)
+ else:
+ df = df.drop(["from", "to", "blockchain"], axis=1)
+
+ for col in ["amount_usd", "amount"]:
+ df[col] = df[col].apply(lambda x: long_number_format(x))
+
+ if gtff.USE_TABULATE_DF:
+ print(
+ tabulate(
+ df.head(top),
+ headers=df.columns,
+ floatfmt=".0f",
+ showindex=False,
+ tablefmt="fancy_grid",
+ ),
+ "\n",
+ )
+ else:
+ print(df.to_string, "\n")
+
+ export_data(
+ export,
+ os.path.dirname(os.path.abspath(__file__)),
+ "whales",
+ df_data,
+ )
diff --git a/website/content/cryptocurrency/onchain/whales/_index.md b/website/content/cryptocurrency/onchain/whales/_index.md
new file mode 100644
index 00000000000..9b440fa6fcf
--- /dev/null
+++ b/website/content/cryptocurrency/onchain/whales/_index.md
@@ -0,0 +1,23 @@
+```
+usage: whales [-m MIN] [-t TOP]
+ [-s {date,symbol,blockchain,amount,amount_usd,from,to}]
+ [--descend] [-a] [--export {csv,json,xlsx}] [-h]
+```
+
+Display huge value transactions from major blockchains. [Source: https://docs.whale-alert.io/]
+
+
+```
+optional arguments:
+ -m MIN, --min MIN Minimum value of transactions. (default: 1000000)
+ -t TOP, --top TOP top N number of records (default: 10)
+ -s {date,symbol,blockchain,amount,amount_usd,from,to}, --sort {date,symbol,blockchain,amount,amount_usd,from,to}
+ Sort by given column. Default: date (default: date)
+ --descend Flag to sort in descending order (lowest first)
+ (default: True)
+ -a, --address Flag to show addresses of transactions (default: False)
+ --export {csv,json,xlsx}
+ Export dataframe data to csv,json,xlsx file (default:
+ )
+ -h, --help show this help message (default: False)
+```