Beispiel #1
0
    def build(cls, lean_config: Dict[str, Any],
              logger: Logger) -> LeanConfigConfigurer:
        logger.info(
            "The IQFeed data feed requires an IQFeed developer account and a locally installed IQFeed client."
        )

        default_binary = cls._get_default(lean_config, "iqfeed-iqconnect")
        if default_binary is not None:
            default_binary = Path(default_binary)
        else:
            default_binary = Path(
                "C:/Program Files (x86)/DTN/IQFeed/iqconnect.exe")
            if not default_binary.is_file():
                default_binary = None

        iqconnect = click.prompt("IQConnect binary location",
                                 type=PathParameter(exists=True,
                                                    file_okay=True,
                                                    dir_okay=False),
                                 default=default_binary)

        username = click.prompt(
            "Username", cls._get_default(lean_config, "iqfeed-username"))
        password = logger.prompt_password(
            "Password", cls._get_default(lean_config, "iqfeed-password"))
        product_name = click.prompt(
            "Product id", cls._get_default(lean_config, "iqfeed-productName"))
        version = click.prompt("Product version",
                               cls._get_default(lean_config, "iqfeed-version"))

        return IQFeedDataFeed(iqconnect, username, password, product_name,
                              version)
Beispiel #2
0
def test_path_parameter_fails_when_input_not_existent_and_exists_required(
) -> None:
    @click.command()
    @click.argument("arg",
                    type=PathParameter(exists=True,
                                       file_okay=True,
                                       dir_okay=True))
    def command(arg: Path) -> None:
        pass

    result = CliRunner().invoke(command, ["fake-file.txt"])

    assert result.exit_code != 0
Beispiel #3
0
def test_path_parameter_fails_when_input_is_file_and_file_not_okay() -> None:
    @click.command()
    @click.argument("arg",
                    type=PathParameter(exists=True,
                                       file_okay=False,
                                       dir_okay=True))
    def command(arg: Path) -> None:
        pass

    (Path.cwd() / "empty-file.txt").touch()

    result = CliRunner().invoke(command, ["empty-file.txt"])

    assert result.exit_code != 0
Beispiel #4
0
def test_path_parameter_fails_when_input_is_directory_and_directory_not_okay(
) -> None:
    @click.command()
    @click.argument("arg",
                    type=PathParameter(exists=True,
                                       file_okay=True,
                                       dir_okay=False))
    def command(arg: Path) -> None:
        pass

    (Path.cwd() / "Empty Directory").mkdir()

    result = CliRunner().invoke(command, ["Empty Directory"])

    assert result.exit_code != 0
Beispiel #5
0
def test_path_parameter_fails_when_input_not_valid_path() -> None:
    @click.command()
    @click.argument("arg",
                    type=PathParameter(exists=False,
                                       file_okay=True,
                                       dir_okay=True))
    def command(arg: Path) -> None:
        pass

    path_validator = mock.Mock()
    path_validator.is_path_valid.return_value = False
    container.path_validator.override(Object(path_validator))

    result = CliRunner().invoke(command, ["invalid-path.txt"])

    assert result.exit_code != 0
Beispiel #6
0
    def _build(cls, lean_config: Dict[str, Any], logger: Logger) -> LocalBrokerage:
        api_client = container.api_client()

        organizations = api_client.organizations.get_all()
        options = [Option(id=organization.id, label=organization.name) for organization in organizations]

        organization_id = logger.prompt_list("Select the organization with the Terminal Link module subscription", options)

        environment = click.prompt("Environment",
                                   cls._get_default(lean_config, "bloomberg-environment"),
                                   type=click.Choice(["Production", "Beta"], case_sensitive=False))

        server_host = click.prompt("Server host", cls._get_default(lean_config, "bloomberg-server-host"))
        server_port = click.prompt("Server port", cls._get_default(lean_config, "bloomberg-server-port"), type=int)

        symbol_map_file = click.prompt("Path to symbol map file",
                                       cls._get_default(lean_config, "bloomberg-symbol-map-file") or "",
                                       type=PathParameter(exists=True, file_okay=True, dir_okay=False))

        emsx_broker = click.prompt("EMSX broker", cls._get_default(lean_config, "bloomberg-emsx-broker"))
        emsx_user_time_zone = click.prompt("EMSX user timezone",
                                           cls._get_default(lean_config, "bloomberg-emsx-user-time-zone") or "UTC")
        emsx_account = click.prompt("EMSX account", cls._get_default(lean_config, "bloomberg-emsx-account") or "")
        emsx_strategy = click.prompt("EMSX strategy", cls._get_default(lean_config, "bloomberg-emsx-strategy") or "")
        emsx_notes = click.prompt("EMSX notes", cls._get_default(lean_config, "bloomberg-emsx-notes") or "")
        emsx_handling = click.prompt("EMSX handling", cls._get_default(lean_config, "bloomberg-emsx-handling") or "")

        allow_modification = click.prompt("Allow modification (yes/no)",
                                          cls._get_default(lean_config, "bloomberg-allow-modification"),
                                          type=bool)

        return TerminalLinkBrokerage(organization_id,
                                     environment,
                                     server_host,
                                     server_port,
                                     symbol_map_file,
                                     emsx_broker,
                                     emsx_user_time_zone,
                                     emsx_account,
                                     emsx_strategy,
                                     emsx_notes,
                                     emsx_handling,
                                     allow_modification)
Beispiel #7
0
    if not no_local and shutil.which("pip") is not None:
        logger.info(
            f"Installing {name} {version} in local Python environment to provide local autocomplete"
        )

        process = subprocess.run(["pip", "install", f"{name}=={version}"])

        if process.returncode != 0:
            raise RuntimeError(
                f"Something went wrong while installing {name} {version} locally, see the logs above for more information"
            )


@click.command(cls=LeanCommand)
@click.argument("project",
                type=PathParameter(exists=True, file_okay=False,
                                   dir_okay=True))
@click.argument("name", type=str)
@click.option(
    "--version",
    type=str,
    help=
    "The version of the library to add (defaults to latest compatible version)"
)
@click.option("--no-local",
              is_flag=True,
              default=False,
              help="Skip making changes to your local environment")
def add(project: Path, name: str, version: Optional[str],
        no_local: bool) -> None:
    """Add a custom library to a project.
Beispiel #8
0
import webbrowser
from pathlib import Path
from typing import Optional

import click
from docker.errors import APIError
from docker.types import Mount

from lean.click import LeanCommand, PathParameter
from lean.constants import DEFAULT_RESEARCH_IMAGE
from lean.container import container


@click.command(cls=LeanCommand, requires_lean_config=True, requires_docker=True)
@click.argument("project", type=PathParameter(exists=True, file_okay=False, dir_okay=True))
@click.option("--port", type=int, default=8888, help="The port to run Jupyter Lab on (defaults to 8888)")
@click.option("--image",
              type=str,
              help=f"The LEAN research image to use (defaults to {DEFAULT_RESEARCH_IMAGE})")
@click.option("--update",
              is_flag=True,
              default=False,
              help="Pull the LEAN research image before starting the research environment")
def research(project: Path, port: int, image: Optional[str], update: bool) -> None:
    """Run a Jupyter Lab environment locally using Docker.

    By default the official LEAN research image is used.
    You can override this using the --image option.
    Alternatively you can set the default research image using `lean config set research-image <image>`.
    """