diff --git a/src/binance_api_client.py b/src/binance_api_client.py
new file mode 100644
index 0000000..5863e35
--- /dev/null
+++ b/src/binance_api_client.py
@@ -0,0 +1,29 @@
+# %%
+import numpy as np
+import pandas as pd
+import time
+
+from binance.client import Client
+
+
+# %%
+api_key = "****"
+secret_key = "***"
+
+client = Client(api_key, secret_key)
+
+
+# %%
+coins_response = client.get_all_coins_info()
+coins_df = pd.DataFrame.from_dict(coins_response, orient='columns')
+
+
+# %%
+pairs_list = coins_df.coin.apply(lambda x: f"{x}USDT")
+client.get_historical_klines(
+ 'BTCUSDT',
+ interval=Client.KLINE_INTERVAL_1HOUR,
+ start_str='2022-04-21',
+ end_str='2022-04-22'
+)
+
diff --git a/src/binance_open_data.ipynb b/src/binance_open_data.ipynb
new file mode 100644
index 0000000..dfe4396
--- /dev/null
+++ b/src/binance_open_data.ipynb
@@ -0,0 +1,299 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Binance Open Data lab"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "[Binance Open Data](https://github.com/binance/binance-public-data/#klines) and analyze it.\n",
+ "\n",
+ "### Stet 1. Download data \n",
+ "\n",
+ "Downloading __1-minute candles__ for `BTC/USDT` and `BTC/UDSC` using `bash` or `powershell` scripts:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "vscode": {
+ "languageId": "shellscript"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "#!/bin/sh\n",
+ "\n",
+ "# create dir for data\n",
+ "!mkdir ../data\n",
+ "\n",
+ "# download data using GET request\n",
+ "!wget -N -P ../data https://data.binance.vision/data/spot/daily/klines/BTCUSDT/1m/BTCUSDT-1m-2022-06-21.zip\n",
+ "!wget -N -P../data https://data.binance.vision/data/spot/daily/klines/BTCUSDC/1m/BTCUSDC-1m-2022-06-21.zip\n",
+ "\n",
+ "# unzip\n",
+ "!unzip -o -d ../data ../data/BTCUSDT-1m-2022-06-21.zip \n",
+ "!unzip -o -d ../data ../data/BTCUSDC-1m-2022-06-21.zip"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Step 2: Import data to Dataframe \n",
+ "\n",
+ "Import packages for data analysis:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "\n",
+ "import httpx\n",
+ "\n",
+ "from datetime import datetime"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Import data from CSV file to Pandas DataFrame:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def get_data(pair: str) -> pd.DataFrame:\n",
+ " return pd.read_csv(f'../data/{pair}-1m-2022-06-21.csv', header = None)\n",
+ "\n",
+ "btcusdt_df = get_data('BTCUSDT')\n",
+ "btcusdt_df.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Set names to columns:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def set_column_names(df: pd.DataFrame) -> pd.DataFrame:\n",
+ " column_names_mapping = {\n",
+ " 0: 'Open_time',\n",
+ " 1: 'Open',\n",
+ " 2: 'High',\n",
+ " 3: 'Low',\n",
+ " 4: 'Close',\n",
+ " 5: 'Volume',\n",
+ " 6: 'Close_time',\n",
+ " 7: 'Quote_asset_volume',\n",
+ " 8: 'Number_of_trades',\n",
+ " 9: 'Taker_buy_base_asset_volume',\n",
+ " 10: 'Taker_buy_quote_asset_volume',\n",
+ " 11: 'Ignore'\n",
+ " }\n",
+ " return df.rename(columns=column_names_mapping)\n",
+ "\n",
+ "btcusdt_df = set_column_names(btcusdt_df)\n",
+ "btcusdt_df.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Convert timestamp to human-readable date and time format:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "btcusdt_df['Open_time'] = btcusdt_df.iloc[:, 0].apply(lambda t: datetime.fromtimestamp(t/1000))\n",
+ "btcusdt_df['Close_time'] = btcusdt_df.iloc[:, 6].apply(lambda t: datetime.fromtimestamp(t/1000))\n",
+ "\n",
+ "btcusdt_df.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Let's take a look at _Descriptive statistics_ (min, mean, max, standard deviation):"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "btcusdt_df.describe(datetime_is_numeric=True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Step 2: Transform data\n",
+ "\n",
+ "Calculate __1-hour OHLCV__ candles:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def calculate_ohclv(df: pd.DataFrame) -> pd.DataFrame:\n",
+ " df['hour'] = df['Close_time'].apply(lambda t: t.hour)\n",
+ "\n",
+ " return (\n",
+ " df\n",
+ " .groupby(['hour'])\n",
+ " .agg(\n",
+ " {\n",
+ " 'Open': 'first',\n",
+ " 'High': max,\n",
+ " 'Low': min,\n",
+ " 'Close': 'last',\n",
+ " 'Volume': sum,\n",
+ " 'Close_time': max\n",
+ " }\n",
+ " )\n",
+ " .reset_index()\n",
+ " .drop(columns=['hour'])\n",
+ " )\n",
+ "\n",
+ "btcusdt_1h_df = calculate_ohclv(btcusdt_df)\n",
+ "\n",
+ "btcusdt_1h_df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Data validation is very important. Let's write domain-driven asserts:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "assert(\n",
+ " isinstance(btcusdt_1h_df, pd.DataFrame)\n",
+ " and btcusdt_1h_df.shape == (24, 6)\n",
+ " and not btcusdt_1h_df.isnull().any().any()\n",
+ " and btcusdt_1h_df.iloc[:, 0:5].ge(0).all().all()\n",
+ " )"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Step 3: Expand the dataset with information about `BTC/USDC` \n",
+ "\n",
+ "Download `BTC/USDC` 1-minute candles and transform it to 1-hour candles:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "btcusdc_df = get_data('BTCUSDC') # download data\n",
+ "btcusdc_df = set_column_names(btcusdc_df) # set column names\n",
+ "btcusdc_df['Close_time'] = btcusdc_df.iloc[:, 6].apply(lambda t: datetime.fromtimestamp(t/1000)) # convert timestamp to date+time\n",
+ "\n",
+ "btcusdc_1h_df = calculate_ohclv(btcusdc_df) # calculate 1h OHCLV candles\n",
+ "btcusdc_1h_df"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Join altogether:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "btcusdt_1h_df['pair'] = 'BTC-USDT'\n",
+ "btcusdc_1h_df['pair'] = 'BTC-USDC'\n",
+ "\n",
+ "# Join datasets\n",
+ "candles_1h_df = pd.concat([btcusdt_1h_df, btcusdc_1h_df])\n",
+ "\n",
+ "# Validate result\n",
+ "assert(\n",
+ " isinstance(candles_1h_df, pd.DataFrame)\n",
+ " and candles_1h_df.shape == (48, 7)\n",
+ " and (candles_1h_df['pair'].unique() == ['BTC-USDT', 'BTC-USDC']).all()\n",
+ ")\n",
+ "\n",
+ "# Sort output by Close_time\n",
+ "candles_1h_df.sort_values('Close_time')"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3.9.13 ('base')",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.13"
+ },
+ "orig_nbformat": 4,
+ "vscode": {
+ "interpreter": {
+ "hash": "6fd7ff10be7e3a66c1b3745c4cbc00041a2589eb74ab4be46a3698a7b56001aa"
+ }
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/src/candidate_tests.ipynb b/src/candidate_tests.ipynb
deleted file mode 100644
index 4b9e15e..0000000
--- a/src/candidate_tests.ipynb
+++ /dev/null
@@ -1,2176 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Analyst Code Interview\n",
- "\n",
- "Hi,\n",
- "\n",
- "It's a simple code interview. I shouldn't take you more than an hour, and it's fun :)\n",
- "\n",
- "## Part I. Quizzes\n",
- "\n",
- "If you didn't have `Python badge` on LinkedIn then it's time [to do it](https://www.linkedin.com/skill-assessments/hub/quizzes/)! Please share your results with us. By the way, here's my badge.\n",
- "\n",
- "![](../docs/li.png)\n",
- "\n",
- "If you don't have a LinkedIn account or like quizzes, then take another test from [W3 School](https://www.w3schools.com/quiztest/quiztest.asp?qtest=PANDAS).\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Part II. Coding\n",
- "\n",
- "Please share the screen with us and let's repair our program together. \n",
- "You can use google.com, StackOverflow, or your favorite IDE. Please use a version of Python greater or equals than 3.8\n",
- "\n",
- "We intend to collect data from [Binance Open Data](https://github.com/binance/binance-public-data/#klines) and analyze it.\n",
- "\n",
- "### Stet 1. Download data \n",
- "\n",
- "Downloading __1-minute candles__ for `BTC/USDT` and `BTC/UDSC` using `bash` or `powershell` scripts:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {
- "vscode": {
- "languageId": "shellscript"
- }
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "mkdir: cannot create directory ‘../data’: File exists\n",
- "--2022-06-24 11:22:56-- https://data.binance.vision/data/spot/daily/klines/BTCUSDT/1m/BTCUSDT-1m-2022-06-21.zip\n",
- "Resolving data.binance.vision (data.binance.vision)... 108.138.94.79, 108.138.94.48, 108.138.94.67, ...\n",
- "Connecting to data.binance.vision (data.binance.vision)|108.138.94.79|:443... connected.\n",
- "HTTP request sent, awaiting response... 304 Not Modified\n",
- "File ‘../data/BTCUSDT-1m-2022-06-21.zip’ not modified on server. Omitting download.\n",
- "\n",
- "--2022-06-24 11:22:57-- https://data.binance.vision/data/spot/daily/klines/BTCUSDC/1m/BTCUSDC-1m-2022-06-21.zip\n",
- "Resolving data.binance.vision (data.binance.vision)... 108.138.94.88, 108.138.94.67, 108.138.94.48, ...\n",
- "Connecting to data.binance.vision (data.binance.vision)|108.138.94.88|:443... connected.\n",
- "HTTP request sent, awaiting response... 304 Not Modified\n",
- "File ‘../data/BTCUSDC-1m-2022-06-21.zip’ not modified on server. Omitting download.\n",
- "\n",
- "Archive: ../data/BTCUSDT-1m-2022-06-21.zip\n",
- " inflating: ../data/BTCUSDT-1m-2022-06-21.csv \n",
- "Archive: ../data/BTCUSDC-1m-2022-06-21.zip\n",
- " inflating: ../data/BTCUSDC-1m-2022-06-21.csv \n"
- ]
- }
- ],
- "source": [
- "#!/bin/sh\n",
- "\n",
- "# create dir for data\n",
- "!mkdir ../data\n",
- "\n",
- "# download data using GET request\n",
- "!wget -N -P ../data https://data.binance.vision/data/spot/daily/klines/BTCUSDT/1m/BTCUSDT-1m-2022-06-21.zip\n",
- "!wget -N -P../data https://data.binance.vision/data/spot/daily/klines/BTCUSDC/1m/BTCUSDC-1m-2022-06-21.zip\n",
- "\n",
- "# unzip\n",
- "!unzip -o -d ../data ../data/BTCUSDT-1m-2022-06-21.zip \n",
- "!unzip -o -d ../data ../data/BTCUSDC-1m-2022-06-21.zip"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Step 2: Import data to Dataframe \n",
- "\n",
- "Import packages for data analysis:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import pandas as pd\n",
- "\n",
- "import httpx\n",
- "\n",
- "from datetime import datetime"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Import data from CSV file to Pandas DataFrame:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "
\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " 0 | \n",
- " 1 | \n",
- " 2 | \n",
- " 3 | \n",
- " 4 | \n",
- " 5 | \n",
- " 6 | \n",
- " 7 | \n",
- " 8 | \n",
- " 9 | \n",
- " 10 | \n",
- " 11 | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 1655769600000 | \n",
- " 20573.90 | \n",
- " 20590.00 | \n",
- " 20552.17 | \n",
- " 20558.36 | \n",
- " 70.76925 | \n",
- " 1655769659999 | \n",
- " 1.455321e+06 | \n",
- " 1150 | \n",
- " 37.36821 | \n",
- " 7.683845e+05 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 1655769660000 | \n",
- " 20558.35 | \n",
- " 20611.21 | \n",
- " 20558.35 | \n",
- " 20606.70 | \n",
- " 118.06032 | \n",
- " 1655769719999 | \n",
- " 2.430514e+06 | \n",
- " 1402 | \n",
- " 61.25760 | \n",
- " 1.260950e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 1655769720000 | \n",
- " 20606.69 | \n",
- " 20626.89 | \n",
- " 20552.40 | \n",
- " 20552.40 | \n",
- " 130.42894 | \n",
- " 1655769779999 | \n",
- " 2.686026e+06 | \n",
- " 1433 | \n",
- " 55.80573 | \n",
- " 1.149409e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 1655769780000 | \n",
- " 20552.41 | \n",
- " 20585.69 | \n",
- " 20539.09 | \n",
- " 20578.89 | \n",
- " 103.56318 | \n",
- " 1655769839999 | \n",
- " 2.128819e+06 | \n",
- " 1301 | \n",
- " 64.57346 | \n",
- " 1.327338e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 1655769840000 | \n",
- " 20578.89 | \n",
- " 20579.90 | \n",
- " 20537.57 | \n",
- " 20554.46 | \n",
- " 83.55509 | \n",
- " 1655769899999 | \n",
- " 1.717907e+06 | \n",
- " 1098 | \n",
- " 36.40944 | \n",
- " 7.485065e+05 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " 0 1 2 3 4 5 \\\n",
- "0 1655769600000 20573.90 20590.00 20552.17 20558.36 70.76925 \n",
- "1 1655769660000 20558.35 20611.21 20558.35 20606.70 118.06032 \n",
- "2 1655769720000 20606.69 20626.89 20552.40 20552.40 130.42894 \n",
- "3 1655769780000 20552.41 20585.69 20539.09 20578.89 103.56318 \n",
- "4 1655769840000 20578.89 20579.90 20537.57 20554.46 83.55509 \n",
- "\n",
- " 6 7 8 9 10 11 \n",
- "0 1655769659999 1.455321e+06 1150 37.36821 7.683845e+05 0 \n",
- "1 1655769719999 2.430514e+06 1402 61.25760 1.260950e+06 0 \n",
- "2 1655769779999 2.686026e+06 1433 55.80573 1.149409e+06 0 \n",
- "3 1655769839999 2.128819e+06 1301 64.57346 1.327338e+06 0 \n",
- "4 1655769899999 1.717907e+06 1098 36.40944 7.485065e+05 0 "
- ]
- },
- "execution_count": 3,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "def get_data(pair: str) -> pd.DataFrame:\n",
- " return pd.read_csv(f'../data/binance/{pair}-1m-2022-06-21.csv', header = None)\n",
- "\n",
- "btcusdt_df = get_data('BTCUSDT')\n",
- "btcusdt_df.head()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Set names to columns:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Open_time | \n",
- " Open | \n",
- " High | \n",
- " Low | \n",
- " Close | \n",
- " Volume | \n",
- " Close_time | \n",
- " Quote_asset_volume | \n",
- " Number_of_trades | \n",
- " Taker_buy_base_asset_volume | \n",
- " Taker_buy_quote_asset_volume | \n",
- " Ignore | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 1655769600000 | \n",
- " 20573.90 | \n",
- " 20590.00 | \n",
- " 20552.17 | \n",
- " 20558.36 | \n",
- " 70.76925 | \n",
- " 1655769659999 | \n",
- " 1.455321e+06 | \n",
- " 1150 | \n",
- " 37.36821 | \n",
- " 7.683845e+05 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 1655769660000 | \n",
- " 20558.35 | \n",
- " 20611.21 | \n",
- " 20558.35 | \n",
- " 20606.70 | \n",
- " 118.06032 | \n",
- " 1655769719999 | \n",
- " 2.430514e+06 | \n",
- " 1402 | \n",
- " 61.25760 | \n",
- " 1.260950e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 1655769720000 | \n",
- " 20606.69 | \n",
- " 20626.89 | \n",
- " 20552.40 | \n",
- " 20552.40 | \n",
- " 130.42894 | \n",
- " 1655769779999 | \n",
- " 2.686026e+06 | \n",
- " 1433 | \n",
- " 55.80573 | \n",
- " 1.149409e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 1655769780000 | \n",
- " 20552.41 | \n",
- " 20585.69 | \n",
- " 20539.09 | \n",
- " 20578.89 | \n",
- " 103.56318 | \n",
- " 1655769839999 | \n",
- " 2.128819e+06 | \n",
- " 1301 | \n",
- " 64.57346 | \n",
- " 1.327338e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 1655769840000 | \n",
- " 20578.89 | \n",
- " 20579.90 | \n",
- " 20537.57 | \n",
- " 20554.46 | \n",
- " 83.55509 | \n",
- " 1655769899999 | \n",
- " 1.717907e+06 | \n",
- " 1098 | \n",
- " 36.40944 | \n",
- " 7.485065e+05 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Open_time Open High Low Close Volume \\\n",
- "0 1655769600000 20573.90 20590.00 20552.17 20558.36 70.76925 \n",
- "1 1655769660000 20558.35 20611.21 20558.35 20606.70 118.06032 \n",
- "2 1655769720000 20606.69 20626.89 20552.40 20552.40 130.42894 \n",
- "3 1655769780000 20552.41 20585.69 20539.09 20578.89 103.56318 \n",
- "4 1655769840000 20578.89 20579.90 20537.57 20554.46 83.55509 \n",
- "\n",
- " Close_time Quote_asset_volume Number_of_trades \\\n",
- "0 1655769659999 1.455321e+06 1150 \n",
- "1 1655769719999 2.430514e+06 1402 \n",
- "2 1655769779999 2.686026e+06 1433 \n",
- "3 1655769839999 2.128819e+06 1301 \n",
- "4 1655769899999 1.717907e+06 1098 \n",
- "\n",
- " Taker_buy_base_asset_volume Taker_buy_quote_asset_volume Ignore \n",
- "0 37.36821 7.683845e+05 0 \n",
- "1 61.25760 1.260950e+06 0 \n",
- "2 55.80573 1.149409e+06 0 \n",
- "3 64.57346 1.327338e+06 0 \n",
- "4 36.40944 7.485065e+05 0 "
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "def set_column_names(df: pd.DataFrame) -> pd.DataFrame:\n",
- " column_names_mapping = {\n",
- " 0: 'Open_time',\n",
- " 1: 'Open',\n",
- " 2: 'High',\n",
- " 3: 'Low',\n",
- " 4: 'Close',\n",
- " 5: 'Volume',\n",
- " 6: 'Close_time',\n",
- " 7: 'Quote_asset_volume',\n",
- " 8: 'Number_of_trades',\n",
- " 9: 'Taker_buy_base_asset_volume',\n",
- " 10: 'Taker_buy_quote_asset_volume',\n",
- " 11: 'Ignore'\n",
- " }\n",
- " return df.rename(columns=column_names_mapping)\n",
- "\n",
- "btcusdt_df = set_column_names(btcusdt_df)\n",
- "btcusdt_df.head()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Convert timestamp to human-readable date and time format:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Open_time | \n",
- " Open | \n",
- " High | \n",
- " Low | \n",
- " Close | \n",
- " Volume | \n",
- " Close_time | \n",
- " Quote_asset_volume | \n",
- " Number_of_trades | \n",
- " Taker_buy_base_asset_volume | \n",
- " Taker_buy_quote_asset_volume | \n",
- " Ignore | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 2022-06-21 00:00:00 | \n",
- " 20573.90 | \n",
- " 20590.00 | \n",
- " 20552.17 | \n",
- " 20558.36 | \n",
- " 70.76925 | \n",
- " 2022-06-21 00:00:59.999 | \n",
- " 1.455321e+06 | \n",
- " 1150 | \n",
- " 37.36821 | \n",
- " 7.683845e+05 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 2022-06-21 00:01:00 | \n",
- " 20558.35 | \n",
- " 20611.21 | \n",
- " 20558.35 | \n",
- " 20606.70 | \n",
- " 118.06032 | \n",
- " 2022-06-21 00:01:59.999 | \n",
- " 2.430514e+06 | \n",
- " 1402 | \n",
- " 61.25760 | \n",
- " 1.260950e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 2022-06-21 00:02:00 | \n",
- " 20606.69 | \n",
- " 20626.89 | \n",
- " 20552.40 | \n",
- " 20552.40 | \n",
- " 130.42894 | \n",
- " 2022-06-21 00:02:59.999 | \n",
- " 2.686026e+06 | \n",
- " 1433 | \n",
- " 55.80573 | \n",
- " 1.149409e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 2022-06-21 00:03:00 | \n",
- " 20552.41 | \n",
- " 20585.69 | \n",
- " 20539.09 | \n",
- " 20578.89 | \n",
- " 103.56318 | \n",
- " 2022-06-21 00:03:59.999 | \n",
- " 2.128819e+06 | \n",
- " 1301 | \n",
- " 64.57346 | \n",
- " 1.327338e+06 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 2022-06-21 00:04:00 | \n",
- " 20578.89 | \n",
- " 20579.90 | \n",
- " 20537.57 | \n",
- " 20554.46 | \n",
- " 83.55509 | \n",
- " 2022-06-21 00:04:59.999 | \n",
- " 1.717907e+06 | \n",
- " 1098 | \n",
- " 36.40944 | \n",
- " 7.485065e+05 | \n",
- " 0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Open_time Open High Low Close Volume \\\n",
- "0 2022-06-21 00:00:00 20573.90 20590.00 20552.17 20558.36 70.76925 \n",
- "1 2022-06-21 00:01:00 20558.35 20611.21 20558.35 20606.70 118.06032 \n",
- "2 2022-06-21 00:02:00 20606.69 20626.89 20552.40 20552.40 130.42894 \n",
- "3 2022-06-21 00:03:00 20552.41 20585.69 20539.09 20578.89 103.56318 \n",
- "4 2022-06-21 00:04:00 20578.89 20579.90 20537.57 20554.46 83.55509 \n",
- "\n",
- " Close_time Quote_asset_volume Number_of_trades \\\n",
- "0 2022-06-21 00:00:59.999 1.455321e+06 1150 \n",
- "1 2022-06-21 00:01:59.999 2.430514e+06 1402 \n",
- "2 2022-06-21 00:02:59.999 2.686026e+06 1433 \n",
- "3 2022-06-21 00:03:59.999 2.128819e+06 1301 \n",
- "4 2022-06-21 00:04:59.999 1.717907e+06 1098 \n",
- "\n",
- " Taker_buy_base_asset_volume Taker_buy_quote_asset_volume Ignore \n",
- "0 37.36821 7.683845e+05 0 \n",
- "1 61.25760 1.260950e+06 0 \n",
- "2 55.80573 1.149409e+06 0 \n",
- "3 64.57346 1.327338e+06 0 \n",
- "4 36.40944 7.485065e+05 0 "
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "btcusdt_df['Open_time'] = btcusdt_df.iloc[:, 0].apply(lambda t: datetime.fromtimestamp(t/1000))\n",
- "btcusdt_df['Close_time'] = btcusdt_df.iloc[:, 6].apply(lambda t: datetime.fromtimestamp(t/1000))\n",
- "\n",
- "btcusdt_df.head()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Let's take a look at _Descriptive statistics_ (min, mean, max, standard deviation):"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Open_time | \n",
- " Open | \n",
- " High | \n",
- " Low | \n",
- " Close | \n",
- " Volume | \n",
- " Close_time | \n",
- " Quote_asset_volume | \n",
- " Number_of_trades | \n",
- " Taker_buy_base_asset_volume | \n",
- " Taker_buy_quote_asset_volume | \n",
- " Ignore | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " count | \n",
- " 1440 | \n",
- " 1440.000000 | \n",
- " 1440.000000 | \n",
- " 1440.000000 | \n",
- " 1440.000000 | \n",
- " 1440.000000 | \n",
- " 1440 | \n",
- " 1.440000e+03 | \n",
- " 1440.000000 | \n",
- " 1440.000000 | \n",
- " 1.440000e+03 | \n",
- " 1440.0 | \n",
- "
\n",
- " \n",
- " mean | \n",
- " 2022-06-21 11:59:30 | \n",
- " 21014.355465 | \n",
- " 21033.877319 | \n",
- " 20996.871035 | \n",
- " 21014.458083 | \n",
- " 72.479435 | \n",
- " 2022-06-21 12:00:29.999000320 | \n",
- " 1.526793e+06 | \n",
- " 1052.264583 | \n",
- " 36.245208 | \n",
- " 7.635009e+05 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " min | \n",
- " 2022-06-21 00:00:00 | \n",
- " 20377.840000 | \n",
- " 20396.830000 | \n",
- " 20348.400000 | \n",
- " 20377.850000 | \n",
- " 5.391420 | \n",
- " 2022-06-21 00:00:59.999000 | \n",
- " 1.128460e+05 | \n",
- " 227.000000 | \n",
- " 1.977960 | \n",
- " 4.127662e+04 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " 25% | \n",
- " 2022-06-21 05:59:45 | \n",
- " 20737.965000 | \n",
- " 20763.567500 | \n",
- " 20713.955000 | \n",
- " 20737.970000 | \n",
- " 34.139227 | \n",
- " 2022-06-21 06:00:44.999000064 | \n",
- " 7.153174e+05 | \n",
- " 636.000000 | \n",
- " 15.905650 | \n",
- " 3.315046e+05 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " 50% | \n",
- " 2022-06-21 11:59:30 | \n",
- " 21073.585000 | \n",
- " 21095.075000 | \n",
- " 21052.210000 | \n",
- " 21073.590000 | \n",
- " 52.615730 | \n",
- " 2022-06-21 12:00:29.999000064 | \n",
- " 1.100389e+06 | \n",
- " 859.000000 | \n",
- " 24.948495 | \n",
- " 5.249121e+05 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " 75% | \n",
- " 2022-06-21 17:59:15 | \n",
- " 21241.470000 | \n",
- " 21260.690000 | \n",
- " 21224.115000 | \n",
- " 21241.467500 | \n",
- " 82.058207 | \n",
- " 2022-06-21 18:00:14.999000064 | \n",
- " 1.718243e+06 | \n",
- " 1225.250000 | \n",
- " 39.859655 | \n",
- " 8.356794e+05 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " max | \n",
- " 2022-06-21 23:59:00 | \n",
- " 21691.550000 | \n",
- " 21723.000000 | \n",
- " 21631.910000 | \n",
- " 21691.550000 | \n",
- " 732.181400 | \n",
- " 2022-06-21 23:59:59.999000 | \n",
- " 1.571181e+07 | \n",
- " 8776.000000 | \n",
- " 471.933210 | \n",
- " 1.013001e+07 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- " std | \n",
- " NaN | \n",
- " 325.066922 | \n",
- " 325.563767 | \n",
- " 324.575912 | \n",
- " 324.952908 | \n",
- " 71.230479 | \n",
- " NaN | \n",
- " 1.511238e+06 | \n",
- " 736.290480 | \n",
- " 41.559421 | \n",
- " 8.819089e+05 | \n",
- " 0.0 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Open_time Open High Low \\\n",
- "count 1440 1440.000000 1440.000000 1440.000000 \n",
- "mean 2022-06-21 11:59:30 21014.355465 21033.877319 20996.871035 \n",
- "min 2022-06-21 00:00:00 20377.840000 20396.830000 20348.400000 \n",
- "25% 2022-06-21 05:59:45 20737.965000 20763.567500 20713.955000 \n",
- "50% 2022-06-21 11:59:30 21073.585000 21095.075000 21052.210000 \n",
- "75% 2022-06-21 17:59:15 21241.470000 21260.690000 21224.115000 \n",
- "max 2022-06-21 23:59:00 21691.550000 21723.000000 21631.910000 \n",
- "std NaN 325.066922 325.563767 324.575912 \n",
- "\n",
- " Close Volume Close_time \\\n",
- "count 1440.000000 1440.000000 1440 \n",
- "mean 21014.458083 72.479435 2022-06-21 12:00:29.999000320 \n",
- "min 20377.850000 5.391420 2022-06-21 00:00:59.999000 \n",
- "25% 20737.970000 34.139227 2022-06-21 06:00:44.999000064 \n",
- "50% 21073.590000 52.615730 2022-06-21 12:00:29.999000064 \n",
- "75% 21241.467500 82.058207 2022-06-21 18:00:14.999000064 \n",
- "max 21691.550000 732.181400 2022-06-21 23:59:59.999000 \n",
- "std 324.952908 71.230479 NaN \n",
- "\n",
- " Quote_asset_volume Number_of_trades Taker_buy_base_asset_volume \\\n",
- "count 1.440000e+03 1440.000000 1440.000000 \n",
- "mean 1.526793e+06 1052.264583 36.245208 \n",
- "min 1.128460e+05 227.000000 1.977960 \n",
- "25% 7.153174e+05 636.000000 15.905650 \n",
- "50% 1.100389e+06 859.000000 24.948495 \n",
- "75% 1.718243e+06 1225.250000 39.859655 \n",
- "max 1.571181e+07 8776.000000 471.933210 \n",
- "std 1.511238e+06 736.290480 41.559421 \n",
- "\n",
- " Taker_buy_quote_asset_volume Ignore \n",
- "count 1.440000e+03 1440.0 \n",
- "mean 7.635009e+05 0.0 \n",
- "min 4.127662e+04 0.0 \n",
- "25% 3.315046e+05 0.0 \n",
- "50% 5.249121e+05 0.0 \n",
- "75% 8.356794e+05 0.0 \n",
- "max 1.013001e+07 0.0 \n",
- "std 8.819089e+05 0.0 "
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "btcusdt_df.describe(datetime_is_numeric=True)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Step 2: Transform data\n",
- "\n",
- "Calculate __1-hour OHLCV__ candles:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Open | \n",
- " High | \n",
- " Low | \n",
- " Close | \n",
- " Volume | \n",
- " Close_time | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 20573.90 | \n",
- " 20705.74 | \n",
- " 20396.77 | \n",
- " 20672.30 | \n",
- " 4235.77392 | \n",
- " 2022-06-21 00:59:59.999 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 20672.30 | \n",
- " 20783.99 | \n",
- " 20504.89 | \n",
- " 20670.88 | \n",
- " 3892.91412 | \n",
- " 2022-06-21 01:59:59.999 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 20670.87 | \n",
- " 20699.93 | \n",
- " 20348.40 | \n",
- " 20433.49 | \n",
- " 2876.88928 | \n",
- " 2022-06-21 02:59:59.999 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 20433.49 | \n",
- " 20665.26 | \n",
- " 20365.00 | \n",
- " 20614.04 | \n",
- " 3306.77018 | \n",
- " 2022-06-21 03:59:59.999 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 20614.04 | \n",
- " 20740.72 | \n",
- " 20474.41 | \n",
- " 20656.17 | \n",
- " 2925.33542 | \n",
- " 2022-06-21 04:59:59.999 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 20656.17 | \n",
- " 21029.93 | \n",
- " 20621.14 | \n",
- " 20890.77 | \n",
- " 6516.65611 | \n",
- " 2022-06-21 05:59:59.999 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 20890.77 | \n",
- " 21202.00 | \n",
- " 20890.77 | \n",
- " 21192.08 | \n",
- " 6114.51662 | \n",
- " 2022-06-21 06:59:59.999 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 21192.08 | \n",
- " 21333.00 | \n",
- " 20952.46 | \n",
- " 21120.28 | \n",
- " 5433.08603 | \n",
- " 2022-06-21 07:59:59.999 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 21120.28 | \n",
- " 21500.01 | \n",
- " 21051.25 | \n",
- " 21356.32 | \n",
- " 6241.36801 | \n",
- " 2022-06-21 08:59:59.999 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 21356.32 | \n",
- " 21470.00 | \n",
- " 21166.94 | \n",
- " 21200.00 | \n",
- " 4961.57496 | \n",
- " 2022-06-21 09:59:59.999 | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " 21200.01 | \n",
- " 21307.83 | \n",
- " 21061.54 | \n",
- " 21299.27 | \n",
- " 3982.47578 | \n",
- " 2022-06-21 10:59:59.999 | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " 21299.02 | \n",
- " 21361.03 | \n",
- " 20911.13 | \n",
- " 20962.42 | \n",
- " 4685.42524 | \n",
- " 2022-06-21 11:59:59.999 | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " 20962.42 | \n",
- " 21163.24 | \n",
- " 20853.36 | \n",
- " 21106.20 | \n",
- " 5596.26303 | \n",
- " 2022-06-21 12:59:59.999 | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " 21106.19 | \n",
- " 21650.00 | \n",
- " 20995.64 | \n",
- " 21619.31 | \n",
- " 8667.59080 | \n",
- " 2022-06-21 13:59:59.999 | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " 21619.31 | \n",
- " 21723.00 | \n",
- " 21427.82 | \n",
- " 21590.79 | \n",
- " 6295.02429 | \n",
- " 2022-06-21 14:59:59.999 | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " 21590.79 | \n",
- " 21604.27 | \n",
- " 21339.07 | \n",
- " 21392.19 | \n",
- " 3809.54622 | \n",
- " 2022-06-21 15:59:59.999 | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " 21392.18 | \n",
- " 21550.39 | \n",
- " 21355.77 | \n",
- " 21401.52 | \n",
- " 2421.77629 | \n",
- " 2022-06-21 16:59:59.999 | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " 21401.52 | \n",
- " 21457.82 | \n",
- " 21195.70 | \n",
- " 21242.94 | \n",
- " 3755.82919 | \n",
- " 2022-06-21 17:59:59.999 | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " 21242.93 | \n",
- " 21256.99 | \n",
- " 21076.48 | \n",
- " 21100.01 | \n",
- " 2820.40675 | \n",
- " 2022-06-21 18:59:59.999 | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " 21100.00 | \n",
- " 21306.51 | \n",
- " 20870.01 | \n",
- " 20888.64 | \n",
- " 4015.33528 | \n",
- " 2022-06-21 19:59:59.999 | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " 20888.63 | \n",
- " 20987.38 | \n",
- " 20666.00 | \n",
- " 20859.86 | \n",
- " 4442.87596 | \n",
- " 2022-06-21 20:59:59.999 | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " 20859.86 | \n",
- " 21054.99 | \n",
- " 20808.00 | \n",
- " 20972.91 | \n",
- " 1813.56236 | \n",
- " 2022-06-21 21:59:59.999 | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " 20972.91 | \n",
- " 21003.70 | \n",
- " 20741.03 | \n",
- " 20897.00 | \n",
- " 2945.61650 | \n",
- " 2022-06-21 22:59:59.999 | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " 20897.00 | \n",
- " 20943.17 | \n",
- " 20551.00 | \n",
- " 20723.52 | \n",
- " 2613.77441 | \n",
- " 2022-06-21 23:59:59.999 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Open High Low Close Volume Close_time\n",
- "0 20573.90 20705.74 20396.77 20672.30 4235.77392 2022-06-21 00:59:59.999\n",
- "1 20672.30 20783.99 20504.89 20670.88 3892.91412 2022-06-21 01:59:59.999\n",
- "2 20670.87 20699.93 20348.40 20433.49 2876.88928 2022-06-21 02:59:59.999\n",
- "3 20433.49 20665.26 20365.00 20614.04 3306.77018 2022-06-21 03:59:59.999\n",
- "4 20614.04 20740.72 20474.41 20656.17 2925.33542 2022-06-21 04:59:59.999\n",
- "5 20656.17 21029.93 20621.14 20890.77 6516.65611 2022-06-21 05:59:59.999\n",
- "6 20890.77 21202.00 20890.77 21192.08 6114.51662 2022-06-21 06:59:59.999\n",
- "7 21192.08 21333.00 20952.46 21120.28 5433.08603 2022-06-21 07:59:59.999\n",
- "8 21120.28 21500.01 21051.25 21356.32 6241.36801 2022-06-21 08:59:59.999\n",
- "9 21356.32 21470.00 21166.94 21200.00 4961.57496 2022-06-21 09:59:59.999\n",
- "10 21200.01 21307.83 21061.54 21299.27 3982.47578 2022-06-21 10:59:59.999\n",
- "11 21299.02 21361.03 20911.13 20962.42 4685.42524 2022-06-21 11:59:59.999\n",
- "12 20962.42 21163.24 20853.36 21106.20 5596.26303 2022-06-21 12:59:59.999\n",
- "13 21106.19 21650.00 20995.64 21619.31 8667.59080 2022-06-21 13:59:59.999\n",
- "14 21619.31 21723.00 21427.82 21590.79 6295.02429 2022-06-21 14:59:59.999\n",
- "15 21590.79 21604.27 21339.07 21392.19 3809.54622 2022-06-21 15:59:59.999\n",
- "16 21392.18 21550.39 21355.77 21401.52 2421.77629 2022-06-21 16:59:59.999\n",
- "17 21401.52 21457.82 21195.70 21242.94 3755.82919 2022-06-21 17:59:59.999\n",
- "18 21242.93 21256.99 21076.48 21100.01 2820.40675 2022-06-21 18:59:59.999\n",
- "19 21100.00 21306.51 20870.01 20888.64 4015.33528 2022-06-21 19:59:59.999\n",
- "20 20888.63 20987.38 20666.00 20859.86 4442.87596 2022-06-21 20:59:59.999\n",
- "21 20859.86 21054.99 20808.00 20972.91 1813.56236 2022-06-21 21:59:59.999\n",
- "22 20972.91 21003.70 20741.03 20897.00 2945.61650 2022-06-21 22:59:59.999\n",
- "23 20897.00 20943.17 20551.00 20723.52 2613.77441 2022-06-21 23:59:59.999"
- ]
- },
- "execution_count": 7,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "def calculate_ohclv(df: pd.DataFrame) -> pd.DataFrame:\n",
- " df['hour'] = df['Close_time'].apply(lambda t: t.hour)\n",
- "\n",
- " return (\n",
- " df\n",
- " .groupby(['hour'])\n",
- " .agg(\n",
- " {\n",
- " 'Open': 'first',\n",
- " 'High': max,\n",
- " 'Low': min,\n",
- " 'Close': 'last',\n",
- " 'Volume': sum,\n",
- " 'Close_time': max\n",
- " }\n",
- " )\n",
- " .reset_index()\n",
- " .drop(columns=['hour'])\n",
- " )\n",
- "\n",
- "btcusdt_1h_df = calculate_ohclv(btcusdt_df)\n",
- "\n",
- "btcusdt_1h_df"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Data validation is very important. Let's write domain-driven asserts:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "assert(\n",
- " isinstance(btcusdt_1h_df, pd.DataFrame)\n",
- " and btcusdt_1h_df.shape == (24, 6)\n",
- " and not btcusdt_1h_df.isnull().any().any()\n",
- " and btcusdt_1h_df.iloc[:, 0:5].ge(0).all().all()\n",
- " )"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Step 3: Expand the dataset with information about `BTC/USDC` \n",
- "\n",
- "Download `BTC/USDC` 1-minute candles and transform it to 1-hour candles:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Open | \n",
- " High | \n",
- " Low | \n",
- " Close | \n",
- " Volume | \n",
- " Close_time | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 20549.65 | \n",
- " 20703.08 | \n",
- " 20371.75 | \n",
- " 20647.35 | \n",
- " 284.73521 | \n",
- " 2022-06-21 00:59:59.999 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 20648.06 | \n",
- " 20771.07 | \n",
- " 20482.83 | \n",
- " 20646.88 | \n",
- " 192.50513 | \n",
- " 2022-06-21 01:59:59.999 | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 20644.78 | \n",
- " 20672.98 | \n",
- " 20331.36 | \n",
- " 20406.71 | \n",
- " 195.67023 | \n",
- " 2022-06-21 02:59:59.999 | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 20402.27 | \n",
- " 20649.99 | \n",
- " 20331.48 | \n",
- " 20585.98 | \n",
- " 290.39210 | \n",
- " 2022-06-21 03:59:59.999 | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 20586.63 | \n",
- " 20721.10 | \n",
- " 20449.57 | \n",
- " 20632.33 | \n",
- " 205.78459 | \n",
- " 2022-06-21 04:59:59.999 | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 20640.33 | \n",
- " 20999.00 | \n",
- " 20594.58 | \n",
- " 20866.07 | \n",
- " 412.42477 | \n",
- " 2022-06-21 05:59:59.999 | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 20873.25 | \n",
- " 21178.00 | \n",
- " 20873.25 | \n",
- " 21169.64 | \n",
- " 524.25894 | \n",
- " 2022-06-21 06:59:59.999 | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 21166.58 | \n",
- " 21300.00 | \n",
- " 20913.40 | \n",
- " 21097.44 | \n",
- " 304.65113 | \n",
- " 2022-06-21 07:59:59.999 | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 21097.20 | \n",
- " 21471.91 | \n",
- " 21023.64 | \n",
- " 21327.56 | \n",
- " 366.29201 | \n",
- " 2022-06-21 08:59:59.999 | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 21342.76 | \n",
- " 21448.22 | \n",
- " 21144.24 | \n",
- " 21182.12 | \n",
- " 350.77543 | \n",
- " 2022-06-21 09:59:59.999 | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " 21175.75 | \n",
- " 21298.52 | \n",
- " 21038.30 | \n",
- " 21270.98 | \n",
- " 526.66602 | \n",
- " 2022-06-21 10:59:59.999 | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " 21273.73 | \n",
- " 21336.94 | \n",
- " 20887.17 | \n",
- " 20948.96 | \n",
- " 579.00200 | \n",
- " 2022-06-21 11:59:59.999 | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " 20936.59 | \n",
- " 21143.99 | \n",
- " 20800.00 | \n",
- " 21079.42 | \n",
- " 452.07214 | \n",
- " 2022-06-21 12:59:59.999 | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " 21079.41 | \n",
- " 21629.36 | \n",
- " 20968.21 | \n",
- " 21592.69 | \n",
- " 507.91190 | \n",
- " 2022-06-21 13:59:59.999 | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " 21595.13 | \n",
- " 21699.98 | \n",
- " 21394.05 | \n",
- " 21572.00 | \n",
- " 445.73978 | \n",
- " 2022-06-21 14:59:59.999 | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " 21571.96 | \n",
- " 21671.34 | \n",
- " 21314.94 | \n",
- " 21370.87 | \n",
- " 435.99237 | \n",
- " 2022-06-21 15:59:59.999 | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " 21370.08 | \n",
- " 21533.14 | \n",
- " 21330.00 | \n",
- " 21377.52 | \n",
- " 243.10368 | \n",
- " 2022-06-21 16:59:59.999 | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " 21377.85 | \n",
- " 21434.58 | \n",
- " 21168.59 | \n",
- " 21220.14 | \n",
- " 291.46137 | \n",
- " 2022-06-21 17:59:59.999 | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " 21220.14 | \n",
- " 21233.94 | \n",
- " 21054.72 | \n",
- " 21074.20 | \n",
- " 423.05836 | \n",
- " 2022-06-21 18:59:59.999 | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " 21074.81 | \n",
- " 21279.52 | \n",
- " 20851.10 | \n",
- " 20866.39 | \n",
- " 266.46488 | \n",
- " 2022-06-21 19:59:59.999 | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " 20864.31 | \n",
- " 20960.98 | \n",
- " 20645.03 | \n",
- " 20838.52 | \n",
- " 330.79569 | \n",
- " 2022-06-21 20:59:59.999 | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " 20838.51 | \n",
- " 21057.01 | \n",
- " 20780.29 | \n",
- " 20958.22 | \n",
- " 99.09836 | \n",
- " 2022-06-21 21:59:59.999 | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " 20950.07 | \n",
- " 20975.92 | \n",
- " 20719.02 | \n",
- " 20875.37 | \n",
- " 177.08203 | \n",
- " 2022-06-21 22:59:59.999 | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " 20880.71 | \n",
- " 20916.85 | \n",
- " 20527.90 | \n",
- " 20699.78 | \n",
- " 173.22797 | \n",
- " 2022-06-21 23:59:59.999 | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Open High Low Close Volume Close_time\n",
- "0 20549.65 20703.08 20371.75 20647.35 284.73521 2022-06-21 00:59:59.999\n",
- "1 20648.06 20771.07 20482.83 20646.88 192.50513 2022-06-21 01:59:59.999\n",
- "2 20644.78 20672.98 20331.36 20406.71 195.67023 2022-06-21 02:59:59.999\n",
- "3 20402.27 20649.99 20331.48 20585.98 290.39210 2022-06-21 03:59:59.999\n",
- "4 20586.63 20721.10 20449.57 20632.33 205.78459 2022-06-21 04:59:59.999\n",
- "5 20640.33 20999.00 20594.58 20866.07 412.42477 2022-06-21 05:59:59.999\n",
- "6 20873.25 21178.00 20873.25 21169.64 524.25894 2022-06-21 06:59:59.999\n",
- "7 21166.58 21300.00 20913.40 21097.44 304.65113 2022-06-21 07:59:59.999\n",
- "8 21097.20 21471.91 21023.64 21327.56 366.29201 2022-06-21 08:59:59.999\n",
- "9 21342.76 21448.22 21144.24 21182.12 350.77543 2022-06-21 09:59:59.999\n",
- "10 21175.75 21298.52 21038.30 21270.98 526.66602 2022-06-21 10:59:59.999\n",
- "11 21273.73 21336.94 20887.17 20948.96 579.00200 2022-06-21 11:59:59.999\n",
- "12 20936.59 21143.99 20800.00 21079.42 452.07214 2022-06-21 12:59:59.999\n",
- "13 21079.41 21629.36 20968.21 21592.69 507.91190 2022-06-21 13:59:59.999\n",
- "14 21595.13 21699.98 21394.05 21572.00 445.73978 2022-06-21 14:59:59.999\n",
- "15 21571.96 21671.34 21314.94 21370.87 435.99237 2022-06-21 15:59:59.999\n",
- "16 21370.08 21533.14 21330.00 21377.52 243.10368 2022-06-21 16:59:59.999\n",
- "17 21377.85 21434.58 21168.59 21220.14 291.46137 2022-06-21 17:59:59.999\n",
- "18 21220.14 21233.94 21054.72 21074.20 423.05836 2022-06-21 18:59:59.999\n",
- "19 21074.81 21279.52 20851.10 20866.39 266.46488 2022-06-21 19:59:59.999\n",
- "20 20864.31 20960.98 20645.03 20838.52 330.79569 2022-06-21 20:59:59.999\n",
- "21 20838.51 21057.01 20780.29 20958.22 99.09836 2022-06-21 21:59:59.999\n",
- "22 20950.07 20975.92 20719.02 20875.37 177.08203 2022-06-21 22:59:59.999\n",
- "23 20880.71 20916.85 20527.90 20699.78 173.22797 2022-06-21 23:59:59.999"
- ]
- },
- "execution_count": 9,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "btcusdc_df = get_data('BTCUSDC') # download data\n",
- "btcusdc_df = set_column_names(btcusdc_df) # set column names\n",
- "btcusdc_df['Close_time'] = btcusdc_df.iloc[:, 6].apply(lambda t: datetime.fromtimestamp(t/1000)) # convert timestamp to date+time\n",
- "\n",
- "btcusdc_1h_df = calculate_ohclv(btcusdc_df) # calculate 1h OHCLV candles\n",
- "btcusdc_1h_df"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Join altogether:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- "\n",
- "\n",
- "
\n",
- " \n",
- " \n",
- " | \n",
- " Open | \n",
- " High | \n",
- " Low | \n",
- " Close | \n",
- " Volume | \n",
- " Close_time | \n",
- " pair | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " 20573.90 | \n",
- " 20705.74 | \n",
- " 20396.77 | \n",
- " 20672.30 | \n",
- " 4235.77392 | \n",
- " 2022-06-21 00:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 0 | \n",
- " 20549.65 | \n",
- " 20703.08 | \n",
- " 20371.75 | \n",
- " 20647.35 | \n",
- " 284.73521 | \n",
- " 2022-06-21 00:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 20648.06 | \n",
- " 20771.07 | \n",
- " 20482.83 | \n",
- " 20646.88 | \n",
- " 192.50513 | \n",
- " 2022-06-21 01:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " 20672.30 | \n",
- " 20783.99 | \n",
- " 20504.89 | \n",
- " 20670.88 | \n",
- " 3892.91412 | \n",
- " 2022-06-21 01:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 20670.87 | \n",
- " 20699.93 | \n",
- " 20348.40 | \n",
- " 20433.49 | \n",
- " 2876.88928 | \n",
- " 2022-06-21 02:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 2 | \n",
- " 20644.78 | \n",
- " 20672.98 | \n",
- " 20331.36 | \n",
- " 20406.71 | \n",
- " 195.67023 | \n",
- " 2022-06-21 02:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 20433.49 | \n",
- " 20665.26 | \n",
- " 20365.00 | \n",
- " 20614.04 | \n",
- " 3306.77018 | \n",
- " 2022-06-21 03:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 3 | \n",
- " 20402.27 | \n",
- " 20649.99 | \n",
- " 20331.48 | \n",
- " 20585.98 | \n",
- " 290.39210 | \n",
- " 2022-06-21 03:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 20614.04 | \n",
- " 20740.72 | \n",
- " 20474.41 | \n",
- " 20656.17 | \n",
- " 2925.33542 | \n",
- " 2022-06-21 04:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 4 | \n",
- " 20586.63 | \n",
- " 20721.10 | \n",
- " 20449.57 | \n",
- " 20632.33 | \n",
- " 205.78459 | \n",
- " 2022-06-21 04:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 20656.17 | \n",
- " 21029.93 | \n",
- " 20621.14 | \n",
- " 20890.77 | \n",
- " 6516.65611 | \n",
- " 2022-06-21 05:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 5 | \n",
- " 20640.33 | \n",
- " 20999.00 | \n",
- " 20594.58 | \n",
- " 20866.07 | \n",
- " 412.42477 | \n",
- " 2022-06-21 05:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 20890.77 | \n",
- " 21202.00 | \n",
- " 20890.77 | \n",
- " 21192.08 | \n",
- " 6114.51662 | \n",
- " 2022-06-21 06:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 6 | \n",
- " 20873.25 | \n",
- " 21178.00 | \n",
- " 20873.25 | \n",
- " 21169.64 | \n",
- " 524.25894 | \n",
- " 2022-06-21 06:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 21192.08 | \n",
- " 21333.00 | \n",
- " 20952.46 | \n",
- " 21120.28 | \n",
- " 5433.08603 | \n",
- " 2022-06-21 07:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 7 | \n",
- " 21166.58 | \n",
- " 21300.00 | \n",
- " 20913.40 | \n",
- " 21097.44 | \n",
- " 304.65113 | \n",
- " 2022-06-21 07:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 21097.20 | \n",
- " 21471.91 | \n",
- " 21023.64 | \n",
- " 21327.56 | \n",
- " 366.29201 | \n",
- " 2022-06-21 08:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 8 | \n",
- " 21120.28 | \n",
- " 21500.01 | \n",
- " 21051.25 | \n",
- " 21356.32 | \n",
- " 6241.36801 | \n",
- " 2022-06-21 08:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 21342.76 | \n",
- " 21448.22 | \n",
- " 21144.24 | \n",
- " 21182.12 | \n",
- " 350.77543 | \n",
- " 2022-06-21 09:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 9 | \n",
- " 21356.32 | \n",
- " 21470.00 | \n",
- " 21166.94 | \n",
- " 21200.00 | \n",
- " 4961.57496 | \n",
- " 2022-06-21 09:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " 21175.75 | \n",
- " 21298.52 | \n",
- " 21038.30 | \n",
- " 21270.98 | \n",
- " 526.66602 | \n",
- " 2022-06-21 10:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 10 | \n",
- " 21200.01 | \n",
- " 21307.83 | \n",
- " 21061.54 | \n",
- " 21299.27 | \n",
- " 3982.47578 | \n",
- " 2022-06-21 10:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " 21273.73 | \n",
- " 21336.94 | \n",
- " 20887.17 | \n",
- " 20948.96 | \n",
- " 579.00200 | \n",
- " 2022-06-21 11:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 11 | \n",
- " 21299.02 | \n",
- " 21361.03 | \n",
- " 20911.13 | \n",
- " 20962.42 | \n",
- " 4685.42524 | \n",
- " 2022-06-21 11:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " 20936.59 | \n",
- " 21143.99 | \n",
- " 20800.00 | \n",
- " 21079.42 | \n",
- " 452.07214 | \n",
- " 2022-06-21 12:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 12 | \n",
- " 20962.42 | \n",
- " 21163.24 | \n",
- " 20853.36 | \n",
- " 21106.20 | \n",
- " 5596.26303 | \n",
- " 2022-06-21 12:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " 21079.41 | \n",
- " 21629.36 | \n",
- " 20968.21 | \n",
- " 21592.69 | \n",
- " 507.91190 | \n",
- " 2022-06-21 13:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 13 | \n",
- " 21106.19 | \n",
- " 21650.00 | \n",
- " 20995.64 | \n",
- " 21619.31 | \n",
- " 8667.59080 | \n",
- " 2022-06-21 13:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " 21619.31 | \n",
- " 21723.00 | \n",
- " 21427.82 | \n",
- " 21590.79 | \n",
- " 6295.02429 | \n",
- " 2022-06-21 14:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 14 | \n",
- " 21595.13 | \n",
- " 21699.98 | \n",
- " 21394.05 | \n",
- " 21572.00 | \n",
- " 445.73978 | \n",
- " 2022-06-21 14:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " 21571.96 | \n",
- " 21671.34 | \n",
- " 21314.94 | \n",
- " 21370.87 | \n",
- " 435.99237 | \n",
- " 2022-06-21 15:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 15 | \n",
- " 21590.79 | \n",
- " 21604.27 | \n",
- " 21339.07 | \n",
- " 21392.19 | \n",
- " 3809.54622 | \n",
- " 2022-06-21 15:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " 21370.08 | \n",
- " 21533.14 | \n",
- " 21330.00 | \n",
- " 21377.52 | \n",
- " 243.10368 | \n",
- " 2022-06-21 16:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 16 | \n",
- " 21392.18 | \n",
- " 21550.39 | \n",
- " 21355.77 | \n",
- " 21401.52 | \n",
- " 2421.77629 | \n",
- " 2022-06-21 16:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " 21377.85 | \n",
- " 21434.58 | \n",
- " 21168.59 | \n",
- " 21220.14 | \n",
- " 291.46137 | \n",
- " 2022-06-21 17:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 17 | \n",
- " 21401.52 | \n",
- " 21457.82 | \n",
- " 21195.70 | \n",
- " 21242.94 | \n",
- " 3755.82919 | \n",
- " 2022-06-21 17:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " 21242.93 | \n",
- " 21256.99 | \n",
- " 21076.48 | \n",
- " 21100.01 | \n",
- " 2820.40675 | \n",
- " 2022-06-21 18:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 18 | \n",
- " 21220.14 | \n",
- " 21233.94 | \n",
- " 21054.72 | \n",
- " 21074.20 | \n",
- " 423.05836 | \n",
- " 2022-06-21 18:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " 21074.81 | \n",
- " 21279.52 | \n",
- " 20851.10 | \n",
- " 20866.39 | \n",
- " 266.46488 | \n",
- " 2022-06-21 19:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 19 | \n",
- " 21100.00 | \n",
- " 21306.51 | \n",
- " 20870.01 | \n",
- " 20888.64 | \n",
- " 4015.33528 | \n",
- " 2022-06-21 19:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " 20864.31 | \n",
- " 20960.98 | \n",
- " 20645.03 | \n",
- " 20838.52 | \n",
- " 330.79569 | \n",
- " 2022-06-21 20:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 20 | \n",
- " 20888.63 | \n",
- " 20987.38 | \n",
- " 20666.00 | \n",
- " 20859.86 | \n",
- " 4442.87596 | \n",
- " 2022-06-21 20:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " 20838.51 | \n",
- " 21057.01 | \n",
- " 20780.29 | \n",
- " 20958.22 | \n",
- " 99.09836 | \n",
- " 2022-06-21 21:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 21 | \n",
- " 20859.86 | \n",
- " 21054.99 | \n",
- " 20808.00 | \n",
- " 20972.91 | \n",
- " 1813.56236 | \n",
- " 2022-06-21 21:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " 20950.07 | \n",
- " 20975.92 | \n",
- " 20719.02 | \n",
- " 20875.37 | \n",
- " 177.08203 | \n",
- " 2022-06-21 22:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- " 22 | \n",
- " 20972.91 | \n",
- " 21003.70 | \n",
- " 20741.03 | \n",
- " 20897.00 | \n",
- " 2945.61650 | \n",
- " 2022-06-21 22:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " 20897.00 | \n",
- " 20943.17 | \n",
- " 20551.00 | \n",
- " 20723.52 | \n",
- " 2613.77441 | \n",
- " 2022-06-21 23:59:59.999 | \n",
- " BTC-USDT | \n",
- "
\n",
- " \n",
- " 23 | \n",
- " 20880.71 | \n",
- " 20916.85 | \n",
- " 20527.90 | \n",
- " 20699.78 | \n",
- " 173.22797 | \n",
- " 2022-06-21 23:59:59.999 | \n",
- " BTC-USDC | \n",
- "
\n",
- " \n",
- "
\n",
- "
"
- ],
- "text/plain": [
- " Open High Low Close Volume \\\n",
- "0 20573.90 20705.74 20396.77 20672.30 4235.77392 \n",
- "0 20549.65 20703.08 20371.75 20647.35 284.73521 \n",
- "1 20648.06 20771.07 20482.83 20646.88 192.50513 \n",
- "1 20672.30 20783.99 20504.89 20670.88 3892.91412 \n",
- "2 20670.87 20699.93 20348.40 20433.49 2876.88928 \n",
- "2 20644.78 20672.98 20331.36 20406.71 195.67023 \n",
- "3 20433.49 20665.26 20365.00 20614.04 3306.77018 \n",
- "3 20402.27 20649.99 20331.48 20585.98 290.39210 \n",
- "4 20614.04 20740.72 20474.41 20656.17 2925.33542 \n",
- "4 20586.63 20721.10 20449.57 20632.33 205.78459 \n",
- "5 20656.17 21029.93 20621.14 20890.77 6516.65611 \n",
- "5 20640.33 20999.00 20594.58 20866.07 412.42477 \n",
- "6 20890.77 21202.00 20890.77 21192.08 6114.51662 \n",
- "6 20873.25 21178.00 20873.25 21169.64 524.25894 \n",
- "7 21192.08 21333.00 20952.46 21120.28 5433.08603 \n",
- "7 21166.58 21300.00 20913.40 21097.44 304.65113 \n",
- "8 21097.20 21471.91 21023.64 21327.56 366.29201 \n",
- "8 21120.28 21500.01 21051.25 21356.32 6241.36801 \n",
- "9 21342.76 21448.22 21144.24 21182.12 350.77543 \n",
- "9 21356.32 21470.00 21166.94 21200.00 4961.57496 \n",
- "10 21175.75 21298.52 21038.30 21270.98 526.66602 \n",
- "10 21200.01 21307.83 21061.54 21299.27 3982.47578 \n",
- "11 21273.73 21336.94 20887.17 20948.96 579.00200 \n",
- "11 21299.02 21361.03 20911.13 20962.42 4685.42524 \n",
- "12 20936.59 21143.99 20800.00 21079.42 452.07214 \n",
- "12 20962.42 21163.24 20853.36 21106.20 5596.26303 \n",
- "13 21079.41 21629.36 20968.21 21592.69 507.91190 \n",
- "13 21106.19 21650.00 20995.64 21619.31 8667.59080 \n",
- "14 21619.31 21723.00 21427.82 21590.79 6295.02429 \n",
- "14 21595.13 21699.98 21394.05 21572.00 445.73978 \n",
- "15 21571.96 21671.34 21314.94 21370.87 435.99237 \n",
- "15 21590.79 21604.27 21339.07 21392.19 3809.54622 \n",
- "16 21370.08 21533.14 21330.00 21377.52 243.10368 \n",
- "16 21392.18 21550.39 21355.77 21401.52 2421.77629 \n",
- "17 21377.85 21434.58 21168.59 21220.14 291.46137 \n",
- "17 21401.52 21457.82 21195.70 21242.94 3755.82919 \n",
- "18 21242.93 21256.99 21076.48 21100.01 2820.40675 \n",
- "18 21220.14 21233.94 21054.72 21074.20 423.05836 \n",
- "19 21074.81 21279.52 20851.10 20866.39 266.46488 \n",
- "19 21100.00 21306.51 20870.01 20888.64 4015.33528 \n",
- "20 20864.31 20960.98 20645.03 20838.52 330.79569 \n",
- "20 20888.63 20987.38 20666.00 20859.86 4442.87596 \n",
- "21 20838.51 21057.01 20780.29 20958.22 99.09836 \n",
- "21 20859.86 21054.99 20808.00 20972.91 1813.56236 \n",
- "22 20950.07 20975.92 20719.02 20875.37 177.08203 \n",
- "22 20972.91 21003.70 20741.03 20897.00 2945.61650 \n",
- "23 20897.00 20943.17 20551.00 20723.52 2613.77441 \n",
- "23 20880.71 20916.85 20527.90 20699.78 173.22797 \n",
- "\n",
- " Close_time pair \n",
- "0 2022-06-21 00:59:59.999 BTC-USDT \n",
- "0 2022-06-21 00:59:59.999 BTC-USDC \n",
- "1 2022-06-21 01:59:59.999 BTC-USDC \n",
- "1 2022-06-21 01:59:59.999 BTC-USDT \n",
- "2 2022-06-21 02:59:59.999 BTC-USDT \n",
- "2 2022-06-21 02:59:59.999 BTC-USDC \n",
- "3 2022-06-21 03:59:59.999 BTC-USDT \n",
- "3 2022-06-21 03:59:59.999 BTC-USDC \n",
- "4 2022-06-21 04:59:59.999 BTC-USDT \n",
- "4 2022-06-21 04:59:59.999 BTC-USDC \n",
- "5 2022-06-21 05:59:59.999 BTC-USDT \n",
- "5 2022-06-21 05:59:59.999 BTC-USDC \n",
- "6 2022-06-21 06:59:59.999 BTC-USDT \n",
- "6 2022-06-21 06:59:59.999 BTC-USDC \n",
- "7 2022-06-21 07:59:59.999 BTC-USDT \n",
- "7 2022-06-21 07:59:59.999 BTC-USDC \n",
- "8 2022-06-21 08:59:59.999 BTC-USDC \n",
- "8 2022-06-21 08:59:59.999 BTC-USDT \n",
- "9 2022-06-21 09:59:59.999 BTC-USDC \n",
- "9 2022-06-21 09:59:59.999 BTC-USDT \n",
- "10 2022-06-21 10:59:59.999 BTC-USDC \n",
- "10 2022-06-21 10:59:59.999 BTC-USDT \n",
- "11 2022-06-21 11:59:59.999 BTC-USDC \n",
- "11 2022-06-21 11:59:59.999 BTC-USDT \n",
- "12 2022-06-21 12:59:59.999 BTC-USDC \n",
- "12 2022-06-21 12:59:59.999 BTC-USDT \n",
- "13 2022-06-21 13:59:59.999 BTC-USDC \n",
- "13 2022-06-21 13:59:59.999 BTC-USDT \n",
- "14 2022-06-21 14:59:59.999 BTC-USDT \n",
- "14 2022-06-21 14:59:59.999 BTC-USDC \n",
- "15 2022-06-21 15:59:59.999 BTC-USDC \n",
- "15 2022-06-21 15:59:59.999 BTC-USDT \n",
- "16 2022-06-21 16:59:59.999 BTC-USDC \n",
- "16 2022-06-21 16:59:59.999 BTC-USDT \n",
- "17 2022-06-21 17:59:59.999 BTC-USDC \n",
- "17 2022-06-21 17:59:59.999 BTC-USDT \n",
- "18 2022-06-21 18:59:59.999 BTC-USDT \n",
- "18 2022-06-21 18:59:59.999 BTC-USDC \n",
- "19 2022-06-21 19:59:59.999 BTC-USDC \n",
- "19 2022-06-21 19:59:59.999 BTC-USDT \n",
- "20 2022-06-21 20:59:59.999 BTC-USDC \n",
- "20 2022-06-21 20:59:59.999 BTC-USDT \n",
- "21 2022-06-21 21:59:59.999 BTC-USDC \n",
- "21 2022-06-21 21:59:59.999 BTC-USDT \n",
- "22 2022-06-21 22:59:59.999 BTC-USDC \n",
- "22 2022-06-21 22:59:59.999 BTC-USDT \n",
- "23 2022-06-21 23:59:59.999 BTC-USDT \n",
- "23 2022-06-21 23:59:59.999 BTC-USDC "
- ]
- },
- "execution_count": 10,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "btcusdt_1h_df['pair'] = 'BTC-USDT'\n",
- "btcusdc_1h_df['pair'] = 'BTC-USDC'\n",
- "\n",
- "# Join datasets\n",
- "candles_1h_df = pd.concat([btcusdt_1h_df, btcusdc_1h_df])\n",
- "\n",
- "# Validate result\n",
- "assert(\n",
- " isinstance(candles_1h_df, pd.DataFrame)\n",
- " and candles_1h_df.shape == (48, 7)\n",
- " and (candles_1h_df['pair'].unique() == ['BTC-USDT', 'BTC-USDC']).all()\n",
- ")\n",
- "\n",
- "# Sort output by Close_time\n",
- "candles_1h_df.sort_values('Close_time')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Step 4: Advanced analytics and visualization\n",
- "\n",
- "Great! We have a dataset with 2 pairs. Let's think about what interesting things can be found there :bulb: and try to visualize it.\n",
- "Feel free to use your favorite framework(s) for visualization."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Conclusion\n",
- "\n",
- "Great job! Thanks for your work and ideas. I hope it was an exciting journey!"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3.9.13 ('base')",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.9.13"
- },
- "orig_nbformat": 4,
- "vscode": {
- "interpreter": {
- "hash": "6fd7ff10be7e3a66c1b3745c4cbc00041a2589eb74ab4be46a3698a7b56001aa"
- }
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}