Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: data-type Open Interest with spacing #455

Merged
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
25 changes: 22 additions & 3 deletions lean/commands/data/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def _select_products_interactive(organization: QCFullOrganization, datasets: Lis

while True:
category = logger.prompt_list("Select a category", category_options)

available_datasets = sorted((d for d in datasets if category in d.categories), key=lambda d: d.name)
dataset: Dataset = logger.prompt_list("Select a dataset",
[Option(id=d, label=d.name) for d in available_datasets])
Expand All @@ -215,7 +214,6 @@ def _select_products_interactive(organization: QCFullOrganization, datasets: Lis
for dataset_option in dataset.options:
if dataset_option.condition is None or dataset_option.condition.check(option_results):
option_results[dataset_option.id] = dataset_option.configure_interactive()

products.append(Product(dataset=dataset, option_results=option_results))

logger.info("Selected data:")
Expand Down Expand Up @@ -496,6 +494,25 @@ def _configure_date_option(date_value: str, option_id: str, option_label: str) -
return date_option.configure_non_interactive(date_value)


class QCDataTypeCustomChoice(Choice):
def get_metavar(self, param) -> str:
choices_str = "|".join(QCDataType.get_all_members_except('Open Interest'))

# Use square braces to indicate an option or optional argument.
return f"[{choices_str}]"


def _replace_data_type(ctx, param, value):
dataset = ctx.params.get('dataset')
if dataset:
if value == QCDataType.OpenInterest:
return QCDataType.Open_Interest
return value
elif value == QCDataType.Open_Interest:
return QCDataType.OpenInterest
return value


@command(cls=LeanCommand, requires_lean_config=True, allow_unknown_options=True, name="download")
@option("--data-provider-historical",
type=Choice([data_downloader.get_name() for data_downloader in cli_data_downloaders], case_sensitive=False),
Expand All @@ -506,7 +523,9 @@ def _configure_date_option(date_value: str, option_id: str, option_label: str) -
@option("--force", is_flag=True, default=False, hidden=True)
@option("--yes", "-y", "auto_confirm", is_flag=True, default=False,
help="Automatically confirm payment confirmation prompts")
@option("--data-type", type=Choice(QCDataType.get_all_members(), case_sensitive=False), help="Specify the type of historical data")
@option("--data-type", callback=_replace_data_type,
type=QCDataTypeCustomChoice(QCDataType.get_all_members(), case_sensitive=False),
help="Specify the type of historical data")
@option("--resolution", type=Choice(QCResolution.get_all_members(), case_sensitive=False),
help="Specify the resolution of the historical data")
@option("--security-type", type=Choice(QCSecurityType.get_all_members(), case_sensitive=False),
Expand Down
5 changes: 5 additions & 0 deletions lean/models/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ class QCDataType(str, Enum):
Quote = "Quote"
Bulk = "Bulk"
OpenInterest = "OpenInterest"
Open_Interest = "Open Interest"

@classmethod
def get_all_members(cls):
Expand All @@ -428,6 +429,10 @@ def get_all_members(cls):
"""
return list(cls.__members__.values())

@classmethod
def get_all_members_except(cls, skip_value:str):
return [value for value in QCDataType.__members__.values() if value != skip_value]

class QCSecurityType(str, Enum):
Equity = "Equity"
Index = "Index"
Expand Down
Loading