From 65178bcde2c7ce3fd27493d741c8bb3e3cc93d3e Mon Sep 17 00:00:00 2001 From: Dane Isburgh Date: Mon, 11 Dec 2023 14:15:04 -0500 Subject: [PATCH] feat: add initial schwab task and notebook --- invaas/schwab/__init__.py | 0 invaas/{ => schwab}/cnn_fear_greed_index.py | 16 +++---- invaas/schwab/schwab_task.py | 38 ++++++++++++++++ invaas/schwab_notebook.ipynb | 49 +++++++++++++++++++++ 4 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 invaas/schwab/__init__.py rename invaas/{ => schwab}/cnn_fear_greed_index.py (83%) create mode 100644 invaas/schwab/schwab_task.py create mode 100644 invaas/schwab_notebook.ipynb diff --git a/invaas/schwab/__init__.py b/invaas/schwab/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/invaas/cnn_fear_greed_index.py b/invaas/schwab/cnn_fear_greed_index.py similarity index 83% rename from invaas/cnn_fear_greed_index.py rename to invaas/schwab/cnn_fear_greed_index.py index 69e3bcb..77348ad 100644 --- a/invaas/cnn_fear_greed_index.py +++ b/invaas/schwab/cnn_fear_greed_index.py @@ -1,5 +1,3 @@ -#! /usr/bin/env python3 - import datetime import requests import typing @@ -41,12 +39,10 @@ def __call__(self) -> dict: return r.json() -def get_current_cnn_fear_greed_index(fetcher: Fetcher = None): +def get_current_cnn_fear_greed_index(): """Returns CNN's Fear & Greed Index.""" - if fetcher is None: - fetcher = Fetcher() - + fetcher = Fetcher() response = fetcher()["fear_and_greed"] return FearGreedIndex( value=response["score"], @@ -55,10 +51,8 @@ def get_current_cnn_fear_greed_index(fetcher: Fetcher = None): ) -def get_historical_cnn_fear_greed_index(fetcher: Fetcher = None): +def get_historical_cnn_fear_greed_index(): """Returns CNN's Fear & Greed Index.""" - if fetcher is None: - fetcher = Fetcher() - - return fetcher()["fear_and_greed_historical"] \ No newline at end of file + fetcher = Fetcher() + return fetcher()["fear_and_greed_historical"] diff --git a/invaas/schwab/schwab_task.py b/invaas/schwab/schwab_task.py new file mode 100644 index 0000000..006c1af --- /dev/null +++ b/invaas/schwab/schwab_task.py @@ -0,0 +1,38 @@ +# Task class for Schwab trading + +import requests + +from invaas.task import Task +from invaas.schwab.cnn_fear_greed_index import get_current_cnn_fear_greed_index + + +class SchwabTask(Task): + """ + Task class to execute ETL processes for loading and preparing data. + """ + + def __init__(self, env: str = "local"): + super().__init__(env=env) + + self.product_ids = ["VUG"] + self.logger.info(f"Products to trade: {str(self.product_ids)}") + + self.current_fear_greed_index = int(get_current_cnn_fear_greed_index().value) + self.logger.info(f"Current fear greed index: {self.current_fear_greed_index}") + + self.min_buy_amount = 2 + self.max_buy_amount = 100 + self.logger.info(f"Min buy amount: ${self.min_buy_amount}") + self.logger.info(f"Max buy amount: ${self.max_buy_amount}") + + def __get_available_balance(self, account_name: str): + pass + + def __buy_product(self, product_id: str, available_cash: float): + pass + + def __sell_product(self, product_id: str, owned_crypto: float): + pass + + def create_orders(self): + pass diff --git a/invaas/schwab_notebook.ipynb b/invaas/schwab_notebook.ipynb new file mode 100644 index 0000000..5c7f7dc --- /dev/null +++ b/invaas/schwab_notebook.ipynb @@ -0,0 +1,49 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%pip install /Workspace/Shared/.bundle/prod/invaas/files" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import sys\n", + "\n", + "from dotenv import load_dotenv, find_dotenv\n", + "\n", + "load_dotenv(find_dotenv())\n", + "app_env = os.getenv(\"APP-ENV\")\n", + "app_source = os.getenv(\"APP-SOURCE\")\n", + "\n", + "sys.path.append((app_source if app_env != \"local\" else os.path.abspath(os.path.join(\"..\"))))\n", + "\n", + "from invaas.schwab.schwab_task import SchwabTask\n", + "\n", + "task = SchwabTask(env=app_env)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "task.create_orders()" + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}