{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "Fe71FFKEm3Jr",
    "outputId": "4017db64-4989-4472-fd8e-363411ba35f6"
   },
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
      "\u001b[0m"
     ]
    }
   ],
   "source": [
    "!pip install -Uqqq pip --progress-bar off\n",
    "!pip install -qqq pyautogen==0.1.10 --progress-bar off"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "id": "vn4FZrxepZum"
   },
   "outputs": [],
   "source": [
    "import json\n",
    "from getpass import getpass\n",
    "\n",
    "import autogen\n",
    "import pandas as pd\n",
    "import requests\n",
    "from autogen import AssistantAgent, UserProxyAgent\n",
    "from IPython.display import Image"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "OPENAI_API_KEY = getpass()"
   ],
   "metadata": {
    "id": "NAktMfNDhTq1",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "outputId": "6e57ac98-d339-4f9a-a0ab-8520f3e2e74c"
   },
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "··········\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "ALPHA_VANTAGE_API_KEY = getpass()"
   ],
   "metadata": {
    "id": "BG2pSpOEh3YY",
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "outputId": "4f9e0eb2-8bd4-4027-c78b-fe4e52505e5d"
   },
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "··········\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "!gdown 1YIw3kRmPmWPeVu-wJlG3uNtJ4YjBVDEq\n",
    "!gdown 1zBz5qC1TmweDOKsmFo2AXSjk8uI6jT7d\n",
    "!gdown 1BpCOBIz-3OVgW2s337n9lgxgL5z8G4mG"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "Y07yB5PdrVEL",
    "outputId": "78c3114a-3a7f-4b5c-ff03-6864561a0b73"
   },
   "execution_count": 1,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "Downloading...\n",
      "From: https://drive.google.com/uc?id=1YIw3kRmPmWPeVu-wJlG3uNtJ4YjBVDEq\n",
      "To: /content/news.csv\n",
      "100% 14.6k/14.6k [00:00<00:00, 45.0MB/s]\n",
      "Downloading...\n",
      "From: https://drive.google.com/uc?id=1zBz5qC1TmweDOKsmFo2AXSjk8uI6jT7d\n",
      "To: /content/eth_price.csv\n",
      "100% 69.2k/69.2k [00:00<00:00, 103MB/s]\n",
      "Downloading...\n",
      "From: https://drive.google.com/uc?id=1BpCOBIz-3OVgW2s337n9lgxgL5z8G4mG\n",
      "To: /content/btc_price.csv\n",
      "100% 71.3k/71.3k [00:00<00:00, 107MB/s]\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "id": "Pys3Hxd-ak26"
   },
   "outputs": [],
   "source": [
    "gpt_config_list = [\n",
    "    {\n",
    "        \"model\": \"gpt-4\",\n",
    "        # 'model': \"gpt-3.5-turbo\",\n",
    "        \"api_key\": OPENAI_API_KEY,\n",
    "    }\n",
    "]\n",
    "\n",
    "llm_config = {\"config_list\": gpt_config_list, \"use_cache\": False, \"temperature\": 0}"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "assistant = AssistantAgent(\n",
    "    name=\"assistant\",\n",
    "    llm_config=llm_config,\n",
    ")"
   ],
   "metadata": {
    "id": "BREFs0PElz_V"
   },
   "execution_count": 9,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "def is_termination_msg(data):\n",
    "    has_content = \"content\" in data and data[\"content\"] is not None\n",
    "    return has_content and \"TERMINATE\" in data[\"content\"]"
   ],
   "metadata": {
    "id": "88n-QwnOU6RB"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "id": "w7n9TUDLbgKx"
   },
   "outputs": [],
   "source": [
    "user_proxy = UserProxyAgent(\n",
    "    name=\"user_proxy\",\n",
    "    human_input_mode=\"NEVER\",\n",
    "    max_consecutive_auto_reply=10,\n",
    "    is_termination_msg=is_termination_msg,\n",
    "    code_execution_config={\"work_dir\": \"coding\"},\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "user_proxy.initiate_chat(\n",
    "    assistant,\n",
    "    message=\"\"\"What is the current year? Compare the year-to-date gain for BTC, ETH and TESLA.\"\"\",\n",
    ")"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "bERczDaVp6gx",
    "outputId": "3bb15d17-6bbe-4fa2-8c63-ac8173adbfd2"
   },
   "execution_count": 11,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "What is the current year? Compare the year-to-date gain for BTC, ETH and TESLA.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "First, let's get the current year using Python. \n",
      "\n",
      "```python\n",
      "# python code\n",
      "import datetime\n",
      "\n",
      "current_year = datetime.datetime.now().year\n",
      "print(\"The current year is:\", current_year)\n",
      "```\n",
      "\n",
      "Next, we need to fetch the year-to-date (YTD) gain for BTC, ETH, and TESLA. We can use the Yahoo Finance API to get this information. However, Yahoo Finance does not provide a direct API to fetch data. We can use the `yfinance` library in Python, which allows you to download historical market data from Yahoo Finance.\n",
      "\n",
      "Please install the library using the following command:\n",
      "\n",
      "```sh\n",
      "# shell script\n",
      "pip install yfinance\n",
      "```\n",
      "\n",
      "After installing the library, we can fetch the YTD gain for BTC, ETH, and TESLA using the following Python code:\n",
      "\n",
      "```python\n",
      "# python code\n",
      "import yfinance as yf\n",
      "\n",
      "# Define the tickers\n",
      "tickers = ['BTC-USD', 'ETH-USD', 'TSLA']\n",
      "\n",
      "# Get the current date\n",
      "now = datetime.datetime.now()\n",
      "\n",
      "# Define the start date as the first day of the current year\n",
      "start_date = datetime.datetime(now.year, 1, 1)\n",
      "\n",
      "# Fetch the data\n",
      "data = yf.download(tickers, start=start_date, end=now)\n",
      "\n",
      "# Calculate the YTD gain for each ticker\n",
      "for ticker in tickers:\n",
      "    start_price = data['Adj Close'][ticker][0]\n",
      "    end_price = data['Adj Close'][ticker][-1]\n",
      "    ytd_gain = ((end_price - start_price) / start_price) * 100\n",
      "    print(f'The YTD gain for {ticker} is {ytd_gain}%')\n",
      "```\n",
      "\n",
      "This code fetches the adjusted close price for each ticker from the start of the current year to the current date, and then calculates the YTD gain as a percentage.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 1 (inferred language is sh)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 2 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "exitcode: 1 (execution failed)\n",
      "Code output: \n",
      "The current year is: 2023\n",
      "\n",
      "Requirement already satisfied: yfinance in /usr/local/lib/python3.10/dist-packages (0.2.31)\n",
      "Requirement already satisfied: pandas>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from yfinance) (1.5.3)\n",
      "Requirement already satisfied: numpy>=1.16.5 in /usr/local/lib/python3.10/dist-packages (from yfinance) (1.23.5)\n",
      "Requirement already satisfied: requests>=2.31 in /usr/local/lib/python3.10/dist-packages (from yfinance) (2.31.0)\n",
      "Requirement already satisfied: multitasking>=0.0.7 in /usr/local/lib/python3.10/dist-packages (from yfinance) (0.0.11)\n",
      "Requirement already satisfied: lxml>=4.9.1 in /usr/local/lib/python3.10/dist-packages (from yfinance) (4.9.3)\n",
      "Requirement already satisfied: appdirs>=1.4.4 in /usr/local/lib/python3.10/dist-packages (from yfinance) (1.4.4)\n",
      "Requirement already satisfied: pytz>=2022.5 in /usr/local/lib/python3.10/dist-packages (from yfinance) (2023.3.post1)\n",
      "Requirement already satisfied: frozendict>=2.3.4 in /usr/local/lib/python3.10/dist-packages (from yfinance) (2.3.8)\n",
      "Requirement already satisfied: peewee>=3.16.2 in /usr/local/lib/python3.10/dist-packages (from yfinance) (3.16.3)\n",
      "Requirement already satisfied: beautifulsoup4>=4.11.1 in /usr/local/lib/python3.10/dist-packages (from yfinance) (4.11.2)\n",
      "Requirement already satisfied: html5lib>=1.1 in /usr/local/lib/python3.10/dist-packages (from yfinance) (1.1)\n",
      "Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4>=4.11.1->yfinance) (2.5)\n",
      "Requirement already satisfied: six>=1.9 in /usr/local/lib/python3.10/dist-packages (from html5lib>=1.1->yfinance) (1.16.0)\n",
      "Requirement already satisfied: webencodings in /usr/local/lib/python3.10/dist-packages (from html5lib>=1.1->yfinance) (0.5.1)\n",
      "Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.10/dist-packages (from pandas>=1.3.0->yfinance) (2.8.2)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31->yfinance) (3.3.0)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31->yfinance) (3.4)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31->yfinance) (2.0.6)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests>=2.31->yfinance) (2023.7.22)\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"\", line 8, in <module>\n",
      "    now = datetime.datetime.now()\n",
      "NameError: name 'datetime' is not defined\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "I apologize for the oversight. The error occurred because the `datetime` module was not imported in the second Python code block. Let's correct this and try again.\n",
      "\n",
      "```python\n",
      "# python code\n",
      "import datetime\n",
      "import yfinance as yf\n",
      "\n",
      "# Define the tickers\n",
      "tickers = ['BTC-USD', 'ETH-USD', 'TSLA']\n",
      "\n",
      "# Get the current date\n",
      "now = datetime.datetime.now()\n",
      "\n",
      "# Define the start date as the first day of the current year\n",
      "start_date = datetime.datetime(now.year, 1, 1)\n",
      "\n",
      "# Fetch the data\n",
      "data = yf.download(tickers, start=start_date, end=now)\n",
      "\n",
      "# Calculate the YTD gain for each ticker\n",
      "for ticker in tickers:\n",
      "    start_price = data['Adj Close'][ticker][0]\n",
      "    end_price = data['Adj Close'][ticker][-1]\n",
      "    ytd_gain = ((end_price - start_price) / start_price) * 100\n",
      "    print(f'The YTD gain for {ticker} is {ytd_gain}%')\n",
      "```\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "exitcode: 0 (execution succeeded)\n",
      "Code output: \n",
      "\n",
      "[                       0%%                      ]\n",
      "[**********************67%%******                ]  2 of 3 completed\n",
      "[*********************100%%**********************]  3 of 3 completed\n",
      "The YTD gain for BTC-USD is 61.252700732996935%\n",
      "The YTD gain for ETH-USD is 29.914312466864207%\n",
      "The YTD gain for TSLA is nan%\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "The code has successfully fetched the year-to-date (YTD) gain for BTC (Bitcoin), ETH (Ethereum), and TSLA (Tesla). Here are the results:\n",
      "\n",
      "- The YTD gain for BTC (Bitcoin) is approximately 61.25%\n",
      "- The YTD gain for ETH (Ethereum) is approximately 29.91%\n",
      "- The YTD gain for TSLA (Tesla) is not available (NaN)\n",
      "\n",
      "The NaN result for Tesla could be due to various reasons such as lack of data for the specified period or issues with the data source. It's recommended to check the data source or try a different one if necessary.\n",
      "\n",
      "TERMINATE\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "user_proxy.send(\n",
    "    recipient=assistant,\n",
    "    message=\"\"\"Plot a chart of their price change YTD and save to price_ytd.png.\"\"\",\n",
    ")"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "TbvwOLNkffl_",
    "outputId": "786a893f-1ab3-48a6-ec03-b3d43277e7f4"
   },
   "execution_count": 12,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "Plot a chart of their price change YTD and save to price_ytd.png.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "We can use the `matplotlib` library in Python to plot the chart. If you haven't installed it yet, please install it using the following command:\n",
      "\n",
      "```sh\n",
      "# shell script\n",
      "pip install matplotlib\n",
      "```\n",
      "\n",
      "After installing the library, we can plot the chart and save it to a file using the following Python code:\n",
      "\n",
      "```python\n",
      "# python code\n",
      "import matplotlib.pyplot as plt\n",
      "\n",
      "# Plot the adjusted close price for each ticker\n",
      "for ticker in tickers:\n",
      "    plt.plot(data['Adj Close'][ticker], label=ticker)\n",
      "\n",
      "# Set the title and labels\n",
      "plt.title('Price Change YTD')\n",
      "plt.xlabel('Date')\n",
      "plt.ylabel('Price')\n",
      "\n",
      "# Add a legend\n",
      "plt.legend()\n",
      "\n",
      "# Save the plot to a file\n",
      "plt.savefig('price_ytd.png')\n",
      "```\n",
      "\n",
      "This code plots the adjusted close price for each ticker from the start of the current year to the current date, adds a title and labels to the plot, adds a legend, and then saves the plot to a file named 'price_ytd.png'.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is sh)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 1 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "exitcode: 1 (execution failed)\n",
      "Code output: \n",
      "Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (3.7.1)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (1.1.1)\n",
      "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (0.12.0)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (4.43.1)\n",
      "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (1.4.5)\n",
      "Requirement already satisfied: numpy>=1.20 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (1.23.5)\n",
      "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (23.2)\n",
      "Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (9.4.0)\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (3.1.1)\n",
      "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib) (2.8.2)\n",
      "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"\", line 5, in <module>\n",
      "    for ticker in tickers:\n",
      "NameError: name 'tickers' is not defined\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "I apologize for the oversight. The error occurred because the `tickers` variable was not defined in the Python code block. Let's correct this and try again.\n",
      "\n",
      "```python\n",
      "# python code\n",
      "import matplotlib.pyplot as plt\n",
      "\n",
      "# Define the tickers\n",
      "tickers = ['BTC-USD', 'ETH-USD', 'TSLA']\n",
      "\n",
      "# Plot the adjusted close price for each ticker\n",
      "for ticker in tickers:\n",
      "    plt.plot(data['Adj Close'][ticker], label=ticker)\n",
      "\n",
      "# Set the title and labels\n",
      "plt.title('Price Change YTD')\n",
      "plt.xlabel('Date')\n",
      "plt.ylabel('Price')\n",
      "\n",
      "# Add a legend\n",
      "plt.legend()\n",
      "\n",
      "# Save the plot to a file\n",
      "plt.savefig('price_ytd.png')\n",
      "```\n",
      "\n",
      "This code plots the adjusted close price for each ticker from the start of the current year to the current date, adds a title and labels to the plot, adds a legend, and then saves the plot to a file named 'price_ytd.png'.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "exitcode: 1 (execution failed)\n",
      "Code output: \n",
      "Traceback (most recent call last):\n",
      "  File \"\", line 9, in <module>\n",
      "    plt.plot(data['Adj Close'][ticker], label=ticker)\n",
      "NameError: name 'data' is not defined\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "I apologize for the oversight. The error occurred because the `data` variable was not defined in the Python code block. We need to fetch the data again before plotting. Let's correct this and try again.\n",
      "\n",
      "```python\n",
      "# python code\n",
      "import matplotlib.pyplot as plt\n",
      "import yfinance as yf\n",
      "import datetime\n",
      "\n",
      "# Define the tickers\n",
      "tickers = ['BTC-USD', 'ETH-USD', 'TSLA']\n",
      "\n",
      "# Get the current date\n",
      "now = datetime.datetime.now()\n",
      "\n",
      "# Define the start date as the first day of the current year\n",
      "start_date = datetime.datetime(now.year, 1, 1)\n",
      "\n",
      "# Fetch the data\n",
      "data = yf.download(tickers, start=start_date, end=now)\n",
      "\n",
      "# Plot the adjusted close price for each ticker\n",
      "for ticker in tickers:\n",
      "    plt.plot(data['Adj Close'][ticker], label=ticker)\n",
      "\n",
      "# Set the title and labels\n",
      "plt.title('Price Change YTD')\n",
      "plt.xlabel('Date')\n",
      "plt.ylabel('Price')\n",
      "\n",
      "# Add a legend\n",
      "plt.legend()\n",
      "\n",
      "# Save the plot to a file\n",
      "plt.savefig('price_ytd.png')\n",
      "```\n",
      "\n",
      "This code fetches the adjusted close price for each ticker from the start of the current year to the current date, plots the data, adds a title and labels to the plot, adds a legend, and then saves the plot to a file named 'price_ytd.png'.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "exitcode: 0 (execution succeeded)\n",
      "Code output: \n",
      "\n",
      "[                       0%%                      ]\n",
      "[**********************67%%******                ]  2 of 3 completed\n",
      "[*********************100%%**********************]  3 of 3 completed\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "Great! The code has successfully fetched the data and created the plot. The plot has been saved to a file named 'price_ytd.png'. You can find this file in the current directory.\n",
      "\n",
      "Please open the 'price_ytd.png' file to view the plot. It shows the price change year-to-date (YTD) for BTC (Bitcoin), ETH (Ethereum), and TSLA (Tesla).\n",
      "\n",
      "TERMINATE\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "Image(filename=\"coding/price_ytd.png\")"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 497
    },
    "id": "Hpfbe2GIS1S1",
    "outputId": "97dddee1-b38b-42ae-b620-96099955b81f"
   },
   "execution_count": 13,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "image/png": "[encoded data, 52632 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "execution_count": 13
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "user_proxy.send(\n",
    "    recipient=assistant,\n",
    "    message=\"\"\"I can't see the ETH stock price on the chart\"\"\",\n",
    ")"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "liQLJEYfS6Un",
    "outputId": "b2de3447-fd53-4d0b-aa60-4ed83efa32c5"
   },
   "execution_count": 14,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "I can't see the ETH stock price on the chart\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "I apologize for the confusion. The issue might be due to the scale of the prices. The prices of BTC (Bitcoin) and ETH (Ethereum) are much higher than the price of TSLA (Tesla), which could make the changes in the TSLA price appear very small on the plot.\n",
      "\n",
      "To solve this issue, we can plot the percentage change in the price instead of the actual price. This will put all stocks on the same scale and make the plot easier to read.\n",
      "\n",
      "Here is the updated Python code:\n",
      "\n",
      "```python\n",
      "# python code\n",
      "import matplotlib.pyplot as plt\n",
      "import yfinance as yf\n",
      "import datetime\n",
      "\n",
      "# Define the tickers\n",
      "tickers = ['BTC-USD', 'ETH-USD', 'TSLA']\n",
      "\n",
      "# Get the current date\n",
      "now = datetime.datetime.now()\n",
      "\n",
      "# Define the start date as the first day of the current year\n",
      "start_date = datetime.datetime(now.year, 1, 1)\n",
      "\n",
      "# Fetch the data\n",
      "data = yf.download(tickers, start=start_date, end=now)\n",
      "\n",
      "# Plot the percentage change in the adjusted close price for each ticker\n",
      "for ticker in tickers:\n",
      "    plt.plot(data['Adj Close'][ticker].pct_change().cumsum(), label=ticker)\n",
      "\n",
      "# Set the title and labels\n",
      "plt.title('Price Change YTD')\n",
      "plt.xlabel('Date')\n",
      "plt.ylabel('Cumulative Percentage Change')\n",
      "\n",
      "# Add a legend\n",
      "plt.legend()\n",
      "\n",
      "# Save the plot to a file\n",
      "plt.savefig('price_ytd.png')\n",
      "```\n",
      "\n",
      "This code fetches the adjusted close price for each ticker from the start of the current year to the current date, calculates the percentage change in the price, plots the cumulative sum of the percentage changes, adds a title and labels to the plot, adds a legend, and then saves the plot to a file named 'price_ytd.png'.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "exitcode: 0 (execution succeeded)\n",
      "Code output: \n",
      "\n",
      "[                       0%%                      ]\n",
      "[**********************67%%******                ]  2 of 3 completed\n",
      "[*********************100%%**********************]  3 of 3 completed\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "Great! The code has successfully fetched the data and created the plot. The plot has been saved to a file named 'price_ytd.png'. You can find this file in the current directory.\n",
      "\n",
      "Please open the 'price_ytd.png' file to view the plot. It shows the cumulative percentage change in price year-to-date (YTD) for BTC (Bitcoin), ETH (Ethereum), and TSLA (Tesla). This should make it easier to compare the performance of these assets over the same period.\n",
      "\n",
      "TERMINATE\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "Image(filename=\"coding/price_ytd.png\")"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 497
    },
    "id": "Uf8ScRswTIco",
    "outputId": "4b5ee18d-a9be-493c-df77-eef572d00aa0"
   },
   "execution_count": 15,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "image/png": "[encoded data, 80996 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "execution_count": 15
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "user_proxy.send(\n",
    "    recipient=assistant,\n",
    "    message=\"\"\"The dates overlap, increase the plot size\"\"\",\n",
    ")"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "H-kaiJz7TRGH",
    "outputId": "2912cfcb-8b32-4120-ed75-846cfe5e6d63"
   },
   "execution_count": 16,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "The dates overlap, increase the plot size\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "I apologize for the inconvenience. We can increase the size of the plot and rotate the date labels to make them more readable. Here is the updated Python code:\n",
      "\n",
      "```python\n",
      "# python code\n",
      "import matplotlib.pyplot as plt\n",
      "import yfinance as yf\n",
      "import datetime\n",
      "\n",
      "# Define the tickers\n",
      "tickers = ['BTC-USD', 'ETH-USD', 'TSLA']\n",
      "\n",
      "# Get the current date\n",
      "now = datetime.datetime.now()\n",
      "\n",
      "# Define the start date as the first day of the current year\n",
      "start_date = datetime.datetime(now.year, 1, 1)\n",
      "\n",
      "# Fetch the data\n",
      "data = yf.download(tickers, start=start_date, end=now)\n",
      "\n",
      "# Create a larger plot\n",
      "plt.figure(figsize=(12, 6))\n",
      "\n",
      "# Plot the percentage change in the adjusted close price for each ticker\n",
      "for ticker in tickers:\n",
      "    plt.plot(data['Adj Close'][ticker].pct_change().cumsum(), label=ticker)\n",
      "\n",
      "# Set the title and labels\n",
      "plt.title('Price Change YTD')\n",
      "plt.xlabel('Date')\n",
      "plt.ylabel('Cumulative Percentage Change')\n",
      "\n",
      "# Rotate the date labels\n",
      "plt.xticks(rotation=45)\n",
      "\n",
      "# Add a legend\n",
      "plt.legend()\n",
      "\n",
      "# Save the plot to a file\n",
      "plt.savefig('price_ytd.png')\n",
      "```\n",
      "\n",
      "This code increases the size of the plot to 12x6, rotates the date labels by 45 degrees, and saves the plot to a file named 'price_ytd.png'.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING CODE BLOCK 0 (inferred language is python)...\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stderr",
     "text": [
      "WARNING:autogen.code_utils:execute_code was called with use_docker evaluating to True, but the python docker package is not available. Falling back to native code execution. Note: this fallback behavior is subject to change\n"
     ]
    },
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "user_proxy (to assistant):\n",
      "\n",
      "exitcode: 0 (execution succeeded)\n",
      "Code output: \n",
      "\n",
      "[                       0%%                      ]\n",
      "[**********************67%%******                ]  2 of 3 completed\n",
      "[*********************100%%**********************]  3 of 3 completed\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "assistant (to user_proxy):\n",
      "\n",
      "Great! The code has successfully fetched the data and created the plot with a larger size and rotated date labels. The plot has been saved to a file named 'price_ytd.png'. You can find this file in the current directory.\n",
      "\n",
      "Please open the 'price_ytd.png' file to view the plot. It shows the cumulative percentage change in price year-to-date (YTD) for BTC (Bitcoin), ETH (Ethereum), and TSLA (Tesla). The dates on the x-axis should now be more readable.\n",
      "\n",
      "TERMINATE\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "Image(filename=\"coding/price_ytd.png\")"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 617
    },
    "id": "yegIOX8ATfG0",
    "outputId": "a2626a5c-6cd5-4858-b6de-d5eb78bdc51e"
   },
   "execution_count": 17,
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "image/png": "[encoded data, 122964 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "execution_count": 17
    }
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "## Group Chat"
   ],
   "metadata": {
    "id": "yVd3mmxbw58I"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "def fetch_prices_for_symbol(symbol: str, days: int, use_cache: bool = False) -> str:\n",
    "    if use_cache:\n",
    "        if symbol == \"BTC\":\n",
    "            price_df = pd.read_csv(\"btc_price.csv\")\n",
    "        else:\n",
    "            price_df = pd.read_csv(\"eth_price.csv\")\n",
    "        return price_df[[\"date\", \"close\", \"volume\"]].head(days)\n",
    "\n",
    "    url = f\"https://www.alphavantage.co/query?function=DIGITAL_CURRENCY_DAILY&symbol={symbol}&market=USD&apikey={ALPHA_VANTAGE_API_KEY}\"\n",
    "    r = requests.get(url)\n",
    "    price_data = r.json()\n",
    "\n",
    "    rows = []\n",
    "    for key, day_data in price_data[\"Time Series (Digital Currency Daily)\"].items():\n",
    "        rows.append(\n",
    "            {\n",
    "                \"date\": key,\n",
    "                \"high\": day_data[\"2a. high (USD)\"],\n",
    "                \"low\": day_data[\"3b. low (USD)\"],\n",
    "                \"close\": day_data[\"4a. close (USD)\"],\n",
    "                \"volume\": day_data[\"5. volume\"],\n",
    "            }\n",
    "        )\n",
    "    df = pd.DataFrame(rows)\n",
    "    return df[[\"date\", \"close\", \"volume\"]].head(days)"
   ],
   "metadata": {
    "id": "e_JpHI5bNQaQ"
   },
   "execution_count": 151,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "def fetch_prices(days: int) -> str:\n",
    "    btc_df = fetch_prices_for_symbol(\"BTC\", days, use_cache=True)\n",
    "    eth_df = fetch_prices_for_symbol(\"ETH\", days, use_cache=True)\n",
    "\n",
    "    btc_txt = btc_df.to_string(index=None)\n",
    "    eth_txt = eth_df.to_string(index=None)\n",
    "\n",
    "    return f\"\"\"\n",
    "$BTC prices (last {days} days)\n",
    "{btc_txt}\n",
    "\n",
    "$ETH prices (last {days} days)\n",
    "{eth_txt}\n",
    "    \"\"\".strip()\n",
    "\n",
    "\n",
    "def fetch_news(latest_n: int) -> str:\n",
    "    news_df = pd.read_csv(\"news.csv\", sep=\";\")\n",
    "    return news_df[[\"summary\", \"sentiment_score\"]].head(latest_n).to_string(index=None)\n",
    "    url = f\"https://www.alphavantage.co/query?function=NEWS_SENTIMENT&sort=LATEST&topics=blockchain&apikey={ALPHA_VANTAGE_API_KEY}\"\n",
    "    r = requests.get(url)\n",
    "    data = r.json()\n",
    "\n",
    "    rows = []\n",
    "    for item in data[\"feed\"]:\n",
    "        rows.append(\n",
    "            {\n",
    "                \"title\": item[\"title\"],\n",
    "                \"summary\": item[\"summary\"],\n",
    "                \"time_published\": item[\"time_published\"],\n",
    "                \"sentiment_score\": item[\"overall_sentiment_score\"],\n",
    "            }\n",
    "        )\n",
    "    df = pd.DataFrame(rows)\n",
    "    return df[[\"summary\", \"sentiment_score\"]].head(latest_n).to_string(index=None)"
   ],
   "metadata": {
    "id": "tof0R70Bg23o"
   },
   "execution_count": 152,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "prices_txt = fetch_prices(days=14)\n",
    "print(prices_txt)"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "73Ra8Dlk2LlV",
    "outputId": "164ea7b2-0950-4737-a17d-db7f068f6140"
   },
   "execution_count": 98,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "$BTC prices (last 14 days)\n",
      "       date    close      volume\n",
      " 2023-10-11 27420.00   422.77304\n",
      " 2023-10-10 27390.12 22776.84383\n",
      " 2023-10-09 27590.12 31534.74639\n",
      " 2023-10-08 27917.05 19693.56921\n",
      " 2023-10-07 27956.67 13348.83825\n",
      " 2023-10-06 27931.09 37983.24277\n",
      " 2023-10-05 27410.39 30681.49619\n",
      " 2023-10-04 27778.57 29816.14200\n",
      " 2023-10-03 27426.46 28928.96555\n",
      " 2023-10-02 27494.51 57071.14241\n",
      " 2023-10-01 27992.57 24602.81468\n",
      " 2023-09-30 26962.56 12804.62307\n",
      " 2023-09-29 26906.96 28478.76219\n",
      " 2023-09-28 27021.39 44517.83491\n",
      "\n",
      "$ETH prices (last 14 days)\n",
      "       date   close      volume\n",
      " 2023-10-11 1569.76   3369.1026\n",
      " 2023-10-10 1567.63 240659.3287\n",
      " 2023-10-09 1580.13 340141.0988\n",
      " 2023-10-08 1632.84 149424.6635\n",
      " 2023-10-07 1633.57 101241.5732\n",
      " 2023-10-06 1645.03 220507.9286\n",
      " 2023-10-05 1611.79 237378.7449\n",
      " 2023-10-04 1646.58 222861.7167\n",
      " 2023-10-03 1656.88 198287.1164\n",
      " 2023-10-02 1662.40 378575.6898\n",
      " 2023-10-01 1733.79 225611.5868\n",
      " 2023-09-30 1670.89 136924.9141\n",
      " 2023-09-29 1667.45 251975.6728\n",
      " 2023-09-28 1652.99 331409.7015\n"
     ]
    }
   ]
  },
  {
   "cell_type": "code",
   "source": [
    "llm_config = {\n",
    "    \"config_list\": gpt_config_list,\n",
    "    \"use_cache\": False,\n",
    "    \"temperature\": 0,\n",
    "    \"functions\": [\n",
    "        {\n",
    "            \"name\": \"fetch_prices\",\n",
    "            \"description\": \"Fetch daily prices for $BTC and $ETH\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"days\": {\n",
    "                        \"type\": \"integer\",\n",
    "                        \"description\": \"number of historical days\",\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"days\"],\n",
    "            },\n",
    "        },\n",
    "        {\n",
    "            \"name\": \"fetch_news\",\n",
    "            \"description\": \"Fetch the latest news about cryptocurrencies\",\n",
    "            \"parameters\": {\n",
    "                \"type\": \"object\",\n",
    "                \"properties\": {\n",
    "                    \"latest_n\": {\n",
    "                        \"type\": \"integer\",\n",
    "                        \"description\": \"number of latest news articles to get\",\n",
    "                    }\n",
    "                },\n",
    "                \"required\": [\"latest_n\"],\n",
    "            },\n",
    "        },\n",
    "    ],\n",
    "}"
   ],
   "metadata": {
    "id": "RUVzVEFvnkp8"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "analyst_system_message = f\"\"\"\n",
    "Analyst. You are a senior financial analyst for a cryptocurrency indicator.\n",
    "\n",
    "Follow the plan:\n",
    " - Get news and prices from the engineer\n",
    " - Give the news and prices (in compact format) to the bull and get their opinion\n",
    " - Give the news and prices (in compact format) to the bear and get their opinion\n",
    " - Write a report with BUY, SELL or HODL along with a number between 0 (extremely bearish) and 100 (extremely bullish) based on\n",
    "the discussion with the bear, the bull, and your own opinion for $ETH and $BTC.\n",
    "\n",
    "Add TERMINATE to the end of the message.\n",
    "\"\"\"\n",
    "\n",
    "analyst = AssistantAgent(\n",
    "    name=\"analyst\",\n",
    "    system_message=analyst_system_message,\n",
    "    llm_config=llm_config,\n",
    "    is_termination_msg=is_termination_msg,\n",
    "    code_execution_config=False,\n",
    ")"
   ],
   "metadata": {
    "id": "ewjbrX5RnrX4"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "engineer_system_message = f\"\"\"\n",
    "Engineer. You are a senior software engineer that executes the fetch_prices and fetch_news functions as requested by the analyst.\n",
    "\"\"\"\n",
    "\n",
    "engineer = AssistantAgent(\n",
    "    name=\"engineer\",\n",
    "    system_message=engineer_system_message,\n",
    "    llm_config=llm_config,\n",
    "    function_map={\"fetch_prices\": fetch_prices, \"fetch_news\": fetch_news},\n",
    "    code_execution_config=False,\n",
    ")"
   ],
   "metadata": {
    "id": "bW9U8nrBnxUu"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "bull_system_message = f\"\"\"\n",
    "Bull. You receive news and prices for $ETH and $BTC from the analyst.\n",
    "You're always on the bullish side for cryptocurrencies and try to find sentiment that supports explosive price increases in the short and long term.\n",
    "You reply to the senior analyst with 1-2 sentences why the data suggests bullish times ahead.\n",
    "\"\"\"\n",
    "\n",
    "bull = AssistantAgent(\n",
    "    name=\"bull\",\n",
    "    system_message=bull_system_message,\n",
    "    code_execution_config=False,\n",
    "    llm_config=llm_config,\n",
    ")"
   ],
   "metadata": {
    "id": "HnlHqxsExKfH"
   },
   "execution_count": 154,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "bear_system_message = f\"\"\"\n",
    "Bear. You receive news and prices for $ETH and $BTC from the analyst.\n",
    "You're always on the bearish side for cryptocurrencies and try to find sentiment that supports explosive price drops in the short and long term.\n",
    "You reply to the senior analyst with 1-2 sentences why the data suggests bearish times ahead.\n",
    "\"\"\"\n",
    "\n",
    "bear = AssistantAgent(\n",
    "    name=\"bear\",\n",
    "    system_message=bear_system_message,\n",
    "    code_execution_config=False,\n",
    "    llm_config=llm_config,\n",
    ")"
   ],
   "metadata": {
    "id": "ZmsjksgQyfiR"
   },
   "execution_count": 155,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "user_proxy = UserProxyAgent(\n",
    "    name=\"admin\",\n",
    "    system_message=\"A human admin. Interact with the analyst to discuss the cryptocurrency report. The final report needs to be approved by this admin\",\n",
    "    code_execution_config=False,\n",
    "    human_input_mode=\"NEVER\",\n",
    "    is_termination_msg=is_termination_msg,\n",
    ")"
   ],
   "metadata": {
    "id": "mHcW8cUezcDd"
   },
   "execution_count": 156,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "groupchat = autogen.GroupChat(\n",
    "    agents=[user_proxy, analyst, engineer, bear, bull], messages=[], max_round=20\n",
    ")\n",
    "manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config)"
   ],
   "metadata": {
    "id": "xtiBg9LkoF26"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "message = f\"\"\"\n",
    "Analyze $ETH and $BTC based on the latest 20 news articles and prices for the last 14 days.\n",
    "\"\"\"\n",
    "user_proxy.initiate_chat(manager, clear_history=True, message=message)"
   ],
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "B13hYZ8wh88a",
    "outputId": "9c009812-8e9c-400a-99bc-5b59e53f8df6"
   },
   "execution_count": 164,
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "admin (to chat_manager):\n",
      "\n",
      "\n",
      "Analyze $ETH and $BTC based on the latest 20 news articles and prices for the last 14 days.\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "analyst (to chat_manager):\n",
      "\n",
      "***** Suggested function Call: fetch_prices *****\n",
      "Arguments: \n",
      "\n",
      "{\n",
      "  \"days\": 14\n",
      "}\n",
      "*************************************************\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING FUNCTION fetch_prices...\n",
      "engineer (to chat_manager):\n",
      "\n",
      "***** Response from calling function \"fetch_prices\" *****\n",
      "$BTC prices (last 14 days)\n",
      "       date    close      volume\n",
      " 2023-10-11 27420.00   422.77304\n",
      " 2023-10-10 27390.12 22776.84383\n",
      " 2023-10-09 27590.12 31534.74639\n",
      " 2023-10-08 27917.05 19693.56921\n",
      " 2023-10-07 27956.67 13348.83825\n",
      " 2023-10-06 27931.09 37983.24277\n",
      " 2023-10-05 27410.39 30681.49619\n",
      " 2023-10-04 27778.57 29816.14200\n",
      " 2023-10-03 27426.46 28928.96555\n",
      " 2023-10-02 27494.51 57071.14241\n",
      " 2023-10-01 27992.57 24602.81468\n",
      " 2023-09-30 26962.56 12804.62307\n",
      " 2023-09-29 26906.96 28478.76219\n",
      " 2023-09-28 27021.39 44517.83491\n",
      "\n",
      "$ETH prices (last 14 days)\n",
      "       date   close      volume\n",
      " 2023-10-11 1569.76   3369.1026\n",
      " 2023-10-10 1567.63 240659.3287\n",
      " 2023-10-09 1580.13 340141.0988\n",
      " 2023-10-08 1632.84 149424.6635\n",
      " 2023-10-07 1633.57 101241.5732\n",
      " 2023-10-06 1645.03 220507.9286\n",
      " 2023-10-05 1611.79 237378.7449\n",
      " 2023-10-04 1646.58 222861.7167\n",
      " 2023-10-03 1656.88 198287.1164\n",
      " 2023-10-02 1662.40 378575.6898\n",
      " 2023-10-01 1733.79 225611.5868\n",
      " 2023-09-30 1670.89 136924.9141\n",
      " 2023-09-29 1667.45 251975.6728\n",
      " 2023-09-28 1652.99 331409.7015\n",
      "*********************************************************\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "bear (to chat_manager):\n",
      "\n",
      "The recent price data for both $BTC and $ETH shows a downward trend, indicating bearish sentiment. The consistent decrease in prices over the past 14 days suggests that investors are selling off their holdings, which could lead to further price drops.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "bull (to chat_manager):\n",
      "\n",
      "While it's true that there's been a slight decrease in prices over the past 14 days, this could be seen as a healthy correction in a broader bullish trend. The high trading volumes for both $BTC and $ETH suggest strong market interest, which could fuel a price surge in the near future.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "admin (to chat_manager):\n",
      "\n",
      "\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "analyst (to chat_manager):\n",
      "\n",
      "***** Suggested function Call: fetch_news *****\n",
      "Arguments: \n",
      "\n",
      "{\n",
      "  \"latest_n\": 20\n",
      "}\n",
      "***********************************************\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "\n",
      ">>>>>>>> EXECUTING FUNCTION fetch_news...\n",
      "engineer (to chat_manager):\n",
      "\n",
      "***** Response from calling function \"fetch_news\" *****\n",
      "                                                                                                                                                                                                                                                                                                   summary  sentiment_score\n",
      "                                                              After contending with the SEC that stablecoins shouldn't fall under the same regulations as traditional securities, Circle has chosen to take the initiative. USDC can now be accessed directly on Polygon PoS without the need for bridges.         0.154965\n",
      "                                                                                                                                                                       Crypto firm Immutable has joined Amazon Web Services' ISV Accelerate Program to develop blockchain gaming infrastructure solutions.         0.184156\n",
      "                                                                                                                                    Collaboration will accelerate onboarding of game studios to web3 by leveraging the agility, reliability, and scalability of AWS to securely launch new features faster         0.388342\n",
      "                                                                                                                                                                            Milan Fashion Week included prominent examples of fashion giants embracing emerging tech, but also hesitance from some brands.         0.249563\n",
      "                                                                                                                                                                                                           The DEX is marking its sixth anniversary with upgrades across its peer-to-peer crypto platform.         0.218737\n",
      "             Bitfinex's parent company, iFinex Inc., is considering a $150 million share repurchase to increase its influence over the crypto exchange's operations amidst rising regulatory attention. The Hong Kong-based iFinex, which has ties to the prominent stablecoin issuer Tether Holdings Ltd.         0.253488\n",
      "                                                                                                                                                                                            Energy analyst Alex de Vries says limited data is one reason there was a slow response to the emerging threat.         0.076839\n",
      " Crypto exchange Binance promised to invest a staggering $1 billion, denominated in its branded stablecoin BUSD, into promising crypto startups through its Industry Recovery Initiative ( IRI ) , following the collapse of crypto exchange FTX. As it stands now, IRI has only funded $30 million in ...         0.163709\n",
      "          Major cryptocurrencies surged above the $27,000 mark, displaying resilience amidst the ongoing Israel-Hamas war, as the crypto market remains largely unaffected. What Happened: According to a local news report, the Israeli police have halted cryptocurrency accounts associated with Hamas.         0.164127\n",
      "                                                                                                                              Botanix Labs founder Willem Schroé argues a \"huge amount of value\" from real-world assets will be captured on Bitcoin, provided it connects to the Ethereum Virtual Machine.         0.189273\n",
      "                                                                                                                                                                                                             Sam Bankman-Fried would destroy world with coin flip: Caroline Ellison - Business Insider ...        -0.144994\n",
      "                                                                                                                                                                                Tezos is a crypto platform that supports smart contracts and Dapps. It also looks to evolve faster than other blockchains.         0.146033\n",
      "  Robert Quartly-Janeiro, Strategy Advisor at crypto exchange Bitrue, says America risks losing out on talent in the digital asset space due to regulatory uncertainties. In an interview with Benzinga, Quartly-Janeiro highlighted the advantages of cryptocurrency, emphasizing its ability to move ...         0.248040\n",
      "        Binance announced it is getting rid of more than 10 liquidity pools as well as introducing Neutron NTRN/USD staking. Liquidity Pools Dropped: Binance BUSD/USD announced eliminating selected liquidity pools on Binance Liquid Swap including XRP XRP/BUSD/USD, Fantom FTM/BUSD/USD, Optimism ...         0.279170\n",
      "   Dubai, United Arab Emirates, Oct. 11, 2023 ( GLOBE NEWSWIRE ) -- Trans Global Group Inc. ( \"TGGI\" or the \"company\" ) announced that today the company completed the establishment of Wing Tiger International Block Chain Technology Co., Ltd ( WT ) in BVI ( British Virgin Islands ) on October 12th.         0.226167\n",
      "   Dubai, United Arab Emirates, Oct. 11, 2023 ( GLOBE NEWSWIRE ) -- Trans Global Group Inc. ( \"TGGI\" or the \"company\" ) announced that today the company completed the establishment of Wing Tiger International Block Chain Technology Co., Ltd ( WT ) in BVI ( British Virgin Islands ) on October 12th.         0.221100\n",
      "                                   CNBC TV host Jim Cramer on Tuesday once again took a dig at Bitcoin's BTC/USD future, suggesting it could take a significant hit. What Happened: Cramer made these comments during CNBC's \"Squawk on the Street\" where he discussed potential investment opportunities.         0.064079\n",
      "                                                                                                                              Lawmakers are scheduled to return to the House of Representatives on Oct. 11 to vote on a replacement for Speaker Kevin McCarthy, whose position has been vacant for a week.         0.047623\n",
      "                                                                                                                                                                                          Star witness Caroline Ellison starts testimony at FTX founder Sam Bankman-Fried's trial The Associated Press ...         0.038575\n",
      "                                                                                                                                                     A U.K. parliamentary committee called for a crack down on sports fan tokens and recommended the government issue a code of conduct for NFT platforms.         0.055051\n",
      "*******************************************************\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "bull (to chat_manager):\n",
      "\n",
      "The latest news articles show a positive sentiment overall, with developments like Circle's initiative to make USDC accessible on Polygon PoS, Immutable's collaboration with Amazon Web Services, and Binance's commitment to invest in promising crypto startups. These advancements suggest a bullish future for cryptocurrencies as they gain more mainstream acceptance and infrastructure support.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "bear (to chat_manager):\n",
      "\n",
      "The latest news articles show a mix of sentiment, but there are several bearish indicators. For instance, Bitfinex's parent company is considering a $150 million share repurchase amidst rising regulatory attention, suggesting potential instability. Additionally, the collapse of crypto exchange FTX and the halted cryptocurrency accounts associated with Hamas indicate potential risks and volatility in the market. These factors could contribute to a bearish outlook for cryptocurrencies.\n",
      "\n",
      "--------------------------------------------------------------------------------\n",
      "analyst (to chat_manager):\n",
      "\n",
      "Based on the discussion with the bull and the bear, as well as my own analysis of the price data and news sentiment, here is my report:\n",
      "\n",
      "$BTC: The recent price trend is slightly bearish, but the overall news sentiment is positive. The high trading volumes suggest strong market interest. However, potential regulatory issues and market volatility could pose risks. My recommendation is HODL with a score of 50, indicating a neutral outlook.\n",
      "\n",
      "$ETH: Similar to $BTC, the price trend for $ETH is slightly bearish, but the news sentiment is generally positive. The high trading volumes and developments like the collaboration between Immutable and Amazon Web Services suggest a bullish future. My recommendation is HODL with a score of 60, indicating a slightly bullish outlook.\n",
      "\n",
      "TERMINATE.\n",
      "\n",
      "--------------------------------------------------------------------------------\n"
     ]
    }
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}