예제 #1
0
def test_prompt_list_displays_all_options(prompt: mock.Mock, capsys: CaptureFixture) -> None:
    logger = Logger()
    options = [Option(id=1, label="Option 1"), Option(id=2, label="Option 2"), Option(id=3, label="Option 3")]

    prompt.return_value = 3
    logger.prompt_list("Select an option", options)

    stdout, stderr = capsys.readouterr()
    assert "Option 1" in stdout
    assert "Option 2" in stdout
    assert "Option 3" in stdout
예제 #2
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 Atreyu module subscription", options)

        host = click.prompt("Host", cls._get_default(lean_config, "atreyu-host"))
        req_port = click.prompt("Request port", cls._get_default(lean_config, "atreyu-req-port"), type=int)
        sub_port = click.prompt("Subscribe port", cls._get_default(lean_config, "atreyu-sub-port"), type=int)

        username = click.prompt("Username", cls._get_default(lean_config, "atreyu-username"))
        password = logger.prompt_password("Password", cls._get_default(lean_config, "atreyu-password"))
        client_id = click.prompt("Client id", cls._get_default(lean_config, "atreyu-client-id"))
        broker_mpid = click.prompt("Broker MPID", cls._get_default(lean_config, "atreyu-broker-mpid"))
        locate_rqd = click.prompt("Locate rqd", cls._get_default(lean_config, "atreyu-locate-rqd"))

        return AtreyuBrokerage(organization_id,
                               host,
                               req_port,
                               sub_port,
                               username,
                               password,
                               client_id,
                               broker_mpid,
                               locate_rqd)
예제 #3
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 {} module subscription".format(
                cls.get_name()), options)

        logger.info("""
Create an API key by logging in and accessing the Binance API Management page (https://www.binance.com/en/my/settings/api-management).
        """.strip())

        api_key = click.prompt(
            "API key", cls._get_default(lean_config, "binance-api-key"))
        api_secret = logger.prompt_password(
            "API secret", cls._get_default(lean_config, "binance-api-secret"))
        testnet = click.confirm("Use the testnet?")

        return BinanceBrokerage(organization_id, api_key, api_secret, testnet)
예제 #4
0
def test_prompt_returns_single_option_without_prompting_with_display_of_value(capsys: CaptureFixture) -> None:
    logger = Logger()
    options = [Option(id=1, label="Option 1")]

    selected_option = logger.prompt_list("Select an option", options)

    assert selected_option == 1

    stdout, stderr = capsys.readouterr()
    assert "Select an option: Option 1" in stdout
예제 #5
0
def test_prompt_list_returns_id_of_selected_option(prompt: mock.Mock, capsys: CaptureFixture) -> None:
    logger = Logger()
    options = [Option(id=1, label="Option 1"), Option(id=2, label="Option 2"), Option(id=3, label="Option 3")]

    prompt.return_value = 3
    selected_option = logger.prompt_list("Select an option", options)

    assert selected_option == 3

    capsys.readouterr()
예제 #6
0
def _configure_brokerage(logger: Logger) -> CloudBrokerage:
    """Interactively configures the brokerage to use.

    :param logger: the logger to use
    :return: the cloud brokerage the user configured
    """
    brokerage_options = [
        Option(id=b, label=b.get_name()) for b in all_cloud_brokerages
    ]
    return logger.prompt_list("Select a brokerage",
                              brokerage_options).build(logger)
예제 #7
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 {} module subscription".format(
                cls.get_name()), options)

        exchange_name = click.prompt(
            "FTX Exchange [FTX|FTXUS]",
            cls._get_default(lean_config, "ftx-exchange-name"))
        exchange = FTXExchange() if exchange_name.casefold() == "FTX".casefold(
        ) else FTXUSExchange()

        logger.info("""
Create an API key by logging in and accessing the {} Profile page (https://{}/profile).
        """.format(exchange.get_name(), exchange.get_domain()).strip())

        prefix = exchange.prefix()
        api_key = click.prompt(
            "API key", cls._get_default(lean_config, f'{prefix}-api-key'))
        api_secret = logger.prompt_password(
            "API secret", cls._get_default(lean_config,
                                           f'{prefix}-api-secret'))

        account_tier = logger.prompt_list(
            "Select the Account Tier", exchange.account_tier_options(),
            cls._get_default(lean_config, f'{prefix}-account-tier'))

        return FTXBrokerage(organization_id, api_key, api_secret, account_tier,
                            exchange_name)
예제 #8
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 Kraken module subscription",
            options
        )

        logger.info("""
Create an API key by logging in and accessing the Kraken API Management page (https://www.kraken.com/u/security/api).
        """.strip())

        api_key = click.prompt("API key", cls._get_default(lean_config, "kraken-api-key"))
        api_secret = logger.prompt_password("API secret", cls._get_default(lean_config, "kraken-api-secret"))

        verification_tier = logger.prompt_list("Select the Verification Tier",
            [Option(id="Starter", label="Starter"), Option(id="Intermediate", label="Intermediate"), Option(id="Pro", label="Pro")],
            cls._get_default(lean_config, "kraken-verification-tier")
        )

        return KrakenBrokerage(organization_id, api_key, api_secret, verification_tier)
예제 #9
0
    def build(cls, lean_config: Dict[str, Any],
              logger: Logger) -> LeanConfigConfigurer:
        api_client = container.api_client()

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

        logger = container.logger()
        organization_id = logger.prompt_list(
            "Select the organization to purchase and download data with",
            options)

        return QuantConnectDataProvider(organization_id)
예제 #10
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 Samco module subscription",
            options)

        client_id = click.prompt(
            "Client ID", cls._get_default(lean_config, "samco-client-id"))
        client_password = logger.prompt_password(
            "Client Password",
            cls._get_default(lean_config, "samco-client-password"))
        year_of_birth = click.prompt(
            "Year of Birth",
            cls._get_default(lean_config, "samco-year-of-birth"))

        logger.info("""
The product type must be set to MIS if you are targeting intraday products, CNC if you are targeting delivery products or NRML if you are targeting carry forward products.
        """.strip())

        product_type = click.prompt("Product type",
                                    cls._get_default(lean_config,
                                                     "samco-product-type"),
                                    type=click.Choice(["MIS", "CNC", "NRML"],
                                                      case_sensitive=False))

        logger.info("""
The trading segment must be set to EQUITY if you are trading equities on NSE or BSE, or COMMODITY if you are trading commodities on MCX.
        """.strip())

        trading_segment = click.prompt(
            "Trading segment",
            cls._get_default(lean_config, "samco-trading-segment"),
            type=click.Choice(["EQUITY", "COMMODITY"], case_sensitive=False))

        return SamcoBrokerage(organization_id, client_id, client_password,
                              year_of_birth, product_type, trading_segment)
예제 #11
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)
예제 #12
0
def _configure_live_node(logger: Logger, api_client: APIClient,
                         cloud_project: QCProject) -> QCNode:
    """Interactively configures the live node to use.

    :param logger: the logger to use
    :param api_client: the API client to make API requests with
    :param cloud_project: the cloud project the user wants to start live trading for
    :return: the live node the user wants to start live trading on
    """
    nodes = api_client.nodes.get_all(cloud_project.organizationId)

    live_nodes = [node for node in nodes.live if not node.busy]
    if len(live_nodes) == 0:
        raise RuntimeError(
            f"You don't have any live nodes available, you can manage your nodes on https://www.quantconnect.com/organization/{cloud_project.organizationId}/resources"
        )

    node_options = [
        Option(id=node, label=f"{node.name} - {node.description}")
        for node in live_nodes
    ]
    return logger.prompt_list("Select a node", node_options)
예제 #13
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 Zerodha module subscription",
            options
        )

        logger.info("You need API credentials for Kite Connect (https://kite.trade/) to use the Zerodha brokerage.")

        api_key = click.prompt("API key", cls._get_default(lean_config, "zerodha-api-key"))
        access_token = logger.prompt_password("Access token", cls._get_default(lean_config, "zerodha-access-token"))

        logger.info("""
The product type must be set to MIS if you are targeting intraday products, CNC if you are targeting delivery products or NRML if you are targeting carry forward products.
        """.strip())

        product_type = click.prompt(
            "Product type",
            cls._get_default(lean_config, "zerodha-product-type"),
            type=click.Choice(["MIS", "CNC", "NRML"], case_sensitive=False)
        )

        logger.info("""
The trading segment must be set to EQUITY if you are trading equities on NSE or BSE, or COMMODITY if you are trading commodities on MCX.
        """.strip())

        trading_segment = click.prompt(
            "Trading segment",
            cls._get_default(lean_config, "zerodha-trading-segment"),
            type=click.Choice(["EQUITY", "COMMODITY"], case_sensitive=False)
        )

        return ZerodhaBrokerage(organization_id, api_key, access_token, product_type, trading_segment)
예제 #14
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 Trading Technologies module subscription",
            options)

        user_name = click.prompt("User name",
                                 cls._get_default(lean_config, "tt-user-name"))
        session_password = logger.prompt_password(
            "Session password",
            cls._get_default(lean_config, "tt-session-password"))
        account_name = click.prompt(
            "Account name", cls._get_default(lean_config, "tt-account-name"))

        rest_app_key = click.prompt(
            "REST app key", cls._get_default(lean_config, "tt-rest-app-key"))
        rest_app_secret = logger.prompt_password(
            "REST app secret",
            cls._get_default(lean_config, "tt-rest-app-secret"))
        rest_environment = click.prompt(
            "REST environment",
            cls._get_default(lean_config, "tt-rest-environment"))

        market_data_sender_comp_id = click.prompt(
            "Market data sender comp id",
            cls._get_default(lean_config, "tt-market-data-sender-comp-id"))
        market_data_target_comp_id = click.prompt(
            "Market data target comp id",
            cls._get_default(lean_config, "tt-market-data-target-comp-id"))
        market_data_host = click.prompt(
            "Market data host",
            cls._get_default(lean_config, "tt-market-data-host"))
        market_data_port = click.prompt(
            "Market data port",
            cls._get_default(lean_config, "tt-market-data-port"))

        order_routing_sender_comp_id = click.prompt(
            "Order routing sender comp id",
            cls._get_default(lean_config, "tt-order-routing-sender-comp-id"))
        order_routing_target_comp_id = click.prompt(
            "Order routing target comp id",
            cls._get_default(lean_config, "tt-order-routing-target-comp-id"))
        order_routing_host = click.prompt(
            "Order routing host",
            cls._get_default(lean_config, "tt-order-routing-host"))
        order_routing_port = click.prompt(
            "Order routing port",
            cls._get_default(lean_config, "tt-order-routing-port"))

        log_fix_messages = click.prompt("Log FIX messages (yes/no)",
                                        cls._get_default(
                                            lean_config,
                                            "tt-log-fix-messages"),
                                        type=bool)

        return TradingTechnologiesBrokerage(
            organization_id, user_name, session_password, account_name,
            rest_app_key, rest_app_secret, rest_environment,
            market_data_sender_comp_id, market_data_target_comp_id,
            market_data_host, market_data_port, order_routing_sender_comp_id,
            order_routing_target_comp_id, order_routing_host,
            order_routing_port, log_fix_messages)