# Path: quantrocket/houston.py
# CANNOT_CONNECT_TO_HOUSTON_ERROR_LOCAL = """{error}
# 
# Could not connect to houston at {scheme}://{netloc}
# 
# Please verify that houston is running and bound to port {port} by checking the output of:
# 
#     docker ps
# 
# The output should resemble:
# 
#     quantrocket/houston ... 0.0.0.0:{port}->80/tcp ... quantrocket_houston_1
#     ...
# 
# If not running you can deploy it with:
# 
#     docker-compose -p quantrocket up -d
# """
# CANNOT_CONNECT_TO_HOUSTON_ERROR_CLOUD = """{error}
# 
# Could not connect to houston at {scheme}://{netloc}
# 
# Please verify that the URL is correct and houston is running.
# """
#     DEFAULT_TIMEOUT = 120
# def _get_force_timeout():
#     def __init__(self):
#     def base_url(self):
#     def _set_base_url(self):
#     def request(self, method, url, *args, **kwargs):
#     def raise_for_status_with_json(response):
# def ping():
# def _cli_ping():
# class Houston(requests.Session):
# 
# Path: quantrocket/cli/utils/output.py
# def json_to_cli(func, *args, **kwargs):
#     """
#     Converts a JSON response to a more appropriate CLI response.
# 
#     If JSON is preferred, the response will be returned as-is. Otherwise:
# 
#     - If the JSON is a list of scalars, the output will be simplified to a
#     string of newline-separated values suitable for the command line (unless
#     simplify_lists is False).
# 
#     - If the JSON is empty, nothing will be returned.
# 
#     - YAML will be returned.
#     """
#     exit_code = 0
#     simplify_list = kwargs.pop("simplify_list", True)
#     try:
#         json_response = func(*args, **kwargs)
#     except requests.exceptions.HTTPError as e:
#         # use json response from service, if available
#         json_response = getattr(e, "json_response", {}) or {"status": "error", "msg": repr(e)}
#         exit_code = 1
#     if not json_response:
#         return None, exit_code
#     if os.environ.get("QUANTROCKET_CLI_OUTPUT_FORMAT", "").lower() == "json":
#         return json.dumps(json_response), exit_code
#     if simplify_list and isinstance(json_response, list) and not any([
#         isinstance(item, (dict, list, tuple, set)) for item in json_response]):
#         return "\n".join([str(item) for item in json_response]), exit_code
#     return yaml.safe_dump(json_response, default_flow_style=False).strip(), exit_code


import os
import getpass
from quantrocket.houston import houston
from quantrocket.cli.utils.output import json_to_cli

    response = houston.get("/ibgrouter/gateways", params=params)
    houston.raise_for_status_with_json(response)
    return response.json()

def _cli_list_gateway_statuses(*args, **kwargs):
    return json_to_cli(list_gateway_statuses, *args, **kwargs)

def start_gateways(gateways=None, wait=False):
    """
    Start one or more IB Gateways.

    Parameters
    ----------
    gateways : list of str, optional
        limit to these IB Gateways

    wait: bool
        wait for the IB Gateway to start before returning (default is to start
        the gateways asynchronously)

    Returns
    -------
    dict
        status message
    """
    params = {"wait": wait}
    if gateways:
        params["gateways"] = gateways


# Path: quantrocket/houston.py
# CANNOT_CONNECT_TO_HOUSTON_ERROR_LOCAL = """{error}
# 
# Could not connect to houston at {scheme}://{netloc}
# 
# Please verify that houston is running and bound to port {port} by checking the output of:
# 
#     docker ps
# 
# The output should resemble:
# 
#     quantrocket/houston ... 0.0.0.0:{port}->80/tcp ... quantrocket_houston_1
#     ...
# 
# If not running you can deploy it with:
# 
#     docker-compose -p quantrocket up -d
# """
# CANNOT_CONNECT_TO_HOUSTON_ERROR_CLOUD = """{error}
# 
# Could not connect to houston at {scheme}://{netloc}
# 
# Please verify that the URL is correct and houston is running.
# """
#     DEFAULT_TIMEOUT = 120
# def _get_force_timeout():
#     def __init__(self):
#     def base_url(self):
#     def _set_base_url(self):
#     def request(self, method, url, *args, **kwargs):
#     def raise_for_status_with_json(response):
# def ping():
# def _cli_ping():
# class Houston(requests.Session):
# 
# Path: quantrocket/cli/utils/output.py
# def json_to_cli(func, *args, **kwargs):
#     """
#     Converts a JSON response to a more appropriate CLI response.
# 
#     If JSON is preferred, the response will be returned as-is. Otherwise:
# 
#     - If the JSON is a list of scalars, the output will be simplified to a
#     string of newline-separated values suitable for the command line (unless
#     simplify_lists is False).
# 
#     - If the JSON is empty, nothing will be returned.
# 
#     - YAML will be returned.
#     """
#     exit_code = 0
#     simplify_list = kwargs.pop("simplify_list", True)
#     try:
#         json_response = func(*args, **kwargs)
#     except requests.exceptions.HTTPError as e:
#         # use json response from service, if available
#         json_response = getattr(e, "json_response", {}) or {"status": "error", "msg": repr(e)}
#         exit_code = 1
#     if not json_response:
#         return None, exit_code
#     if os.environ.get("QUANTROCKET_CLI_OUTPUT_FORMAT", "").lower() == "json":
#         return json.dumps(json_response), exit_code
#     if simplify_list and isinstance(json_response, list) and not any([
#         isinstance(item, (dict, list, tuple, set)) for item in json_response]):
#         return "\n".join([str(item) for item in json_response]), exit_code
#     return yaml.safe_dump(json_response, default_flow_style=False).strip(), exit_code


# Path: quantrocket/ibg.py
import os
import getpass
from quantrocket.houston import houston
from quantrocket.cli.utils.output import json_to_cli


    response = houston.get("/ibgrouter/gateways", params=params)
    houston.raise_for_status_with_json(response)
    return response.json()

def _cli_list_gateway_statuses(*args, **kwargs):
    return json_to_cli(list_gateway_statuses, *args, **kwargs)

def start_gateways(gateways=None, wait=False):
    """
    Start one or more IB Gateways.

    Parameters
    ----------
    gateways : list of str, optional
        limit to these IB Gateways

    wait: bool
        wait for the IB Gateway to start before returning (default is to start
        the gateways asynchronously)

    Returns
    -------
    dict
        status message
    """
    params = {"wait": wait}
    if gateways:
        params["gateways"] = gateways


    response = houston.post("/ibgrouter/gateways", params=params, timeout=120)