Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/data_collector/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class BaseCollector(abc.ABC):

DEFAULT_START_DATETIME_1D = pd.Timestamp("2000-01-01")
DEFAULT_START_DATETIME_1MIN = pd.Timestamp(datetime.datetime.now() - pd.Timedelta(days=5 * 6 - 1)).date()
DEFAULT_START_DATETIME_5MIN = DEFAULT_START_DATETIME_1MIN
DEFAULT_END_DATETIME_1D = pd.Timestamp(datetime.datetime.now() + pd.Timedelta(days=1)).date()
DEFAULT_END_DATETIME_1MIN = DEFAULT_END_DATETIME_1D
DEFAULT_END_DATETIME_5MIN = DEFAULT_END_DATETIME_1MIN

INTERVAL_1min = "1min"
INTERVAL_5min = "5min"
INTERVAL_1d = "1d"

def __init__(
Expand Down
30 changes: 30 additions & 0 deletions tests/test_data_collector_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import sys
from pathlib import Path

import pandas as pd


sys.path.append(str(Path(__file__).resolve().parent.parent.joinpath("scripts")))

from data_collector.base import BaseCollector


class DummyCollector(BaseCollector):
def get_instrument_list(self):
return []

def normalize_symbol(self, symbol: str):
return symbol

def get_data(self, symbol: str, interval: str, start_datetime: pd.Timestamp, end_datetime: pd.Timestamp):
return pd.DataFrame()


def test_base_collector_supports_default_5min_date_range(tmp_path):
collector = DummyCollector(save_dir=tmp_path, interval="5min")

assert collector.start_datetime == DummyCollector.DEFAULT_START_DATETIME_5MIN
assert collector.end_datetime == DummyCollector.DEFAULT_END_DATETIME_5MIN