Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Add test test_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
InsonusK committed Dec 24, 2022
1 parent 9ab8390 commit 9cada6a
Show file tree
Hide file tree
Showing 29 changed files with 713 additions and 178 deletions.
209 changes: 209 additions & 0 deletions jnotebook/test_cache.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import logging\n",
"\n",
"logging.basicConfig(format='\\033[93m%(asctime)s %(levelname)s %(name)s:\\033[0m %(message)s', level=logging.INFO, datefmt='%I:%M:%S')\n",
"import warnings\n",
"import pandas as pd\n",
"\n",
"warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)\n",
"warnings.simplefilter(action=\"ignore\", category=pd.errors.SettingWithCopyWarning)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"from src.cache import FileCache\n",
"from src.config import QuoteRequest, ChartConfig, LoadRequest,Source\n",
"from NNTrade.common import TimeFrame\n",
"from datetime import date\n",
"from src.loader import YahooStockQuoteLoader"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"impl = FileCache(\"./output_files\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"expected_request = QuoteRequest(ChartConfig(\"EURUSD=X\",TimeFrame.D), date(2020,2,3), date(2020,2,6))\n",
"expected_load_request = LoadRequest(Source.Yahoo, expected_request)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[93m11:52:01 INFO FileCache:\u001b[0m Load df from file ./output_files/Yahoo__EURUSD=X__Day__2020-02-03__2020-02-06.csv\n"
]
}
],
"source": [
"asserted_df = impl.load_df(expected_load_request)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.1065618991851809"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asserted_df[\"high\"][1]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2020-02-03 1.108906\n",
"2020-02-04 1.106562\n",
"2020-02-05 1.104850\n",
"Name: high, dtype: float64"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"asserted_df[\"high\"]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[93m11:52:44 WARNING AbsStockQuoteLoader:\u001b[0m use_cache is True, but cache_logger is None\n",
"\u001b[93m11:52:44 INFO func yahoo_loader.load_stock_candles:\u001b[0m Start download from yahoo finance\n",
"\u001b[93m11:52:44 INFO func yahoo_loader.load_stock_candles:\u001b[0m Download stock EURUSD=X timeframe DAY\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[*********************100%***********************] 1 of 1 completed\n"
]
}
],
"source": [
"expected_df = YahooStockQuoteLoader().download(expected_request)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.1065618991851807"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"expected_df[\"high\"][1]"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"start_date_time\n",
"2020-02-03 1.108906\n",
"2020-02-04 1.106562\n",
"2020-02-05 1.104850\n",
"Name: high, dtype: float64"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"expected_df[\"high\"]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.11.1"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "949777d72b0d2535278d3dc13498b2535136f6dfe0678499012e853ee9abcab1"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 9cada6a

Please sign in to comment.