Exemple #1
0
        def create_cut_label(hours, minutes, display_name, description,
                             time_zone, code_dict):
            # Create the time for the cut label
            time = models.CutLocalTime(hours=hours, minutes=minutes)

            # Define the parameters of the cut label in a request
            request = models.CutLabelDefinition(code=display_name + "-" +
                                                get_guid(),
                                                description=description,
                                                display_name=display_name,
                                                cut_local_time=time,
                                                time_zone=time_zone)

            # Add the codes of our cut labels to our dictionary
            code_dict[request.display_name] = request.code

            # Send the request to LUSID to create the cut label
            result = self.cut_labels.create_cut_label_definition(
                create_request=request)

            # Check that result gives same details as input
            self.assertEqual(result.display_name, display_name)
            self.assertEqual(result.description, description)
            self.assertEqual(result.cut_local_time, time)
            self.assertEqual(result.time_zone, time_zone)
Exemple #2
0
def create_cut_labels(api_factory, exchange_names, cut_label_type):
    """
    This function creates cut labels for the open or close of a short list
    of known stock exchanges. It is idempotent in that it will check if the cut
    label already exists before creating it. If it does already exist it will delete it
    first before attempting creation. 
    
    param (lusid.utilities.ClientApiFactory) api_factory: The LUSID api factory to use
    param (list[str]) exchange_names: The list of exchanges to create cut labels for
    param (str) cut_label_type: The type of cut label to create, options are currently
    'market open' or 'market close'.
    
    return (list[lusid.models.cutlabelresponse]) responses: The responses from creating the cut labels
    """

    # The available cut labels and exchanges
    available_cut_labels = ["market_open", "market_close"]

    exchange_info = {
        "LSE": {
            "time_zone": "GB",
            "hour": 16,
            "minutes": 30
        },
        "NYSE": {
            "time_zone": "America/New_York",
            "hour": 16,
            "minutes": 0
        },
    }

    # Validation of the types and the values
    if type(exchange_names) is not list:
        raise TypeError(
            f"The exchange_names variable is of type {type(exchange_names)}. It must be a list of strings"
        )

    if len(exchange_names) < 1:
        raise ValueError(
            f"No exchanges were provided, please provide a non-empty list for the variable exchange_names"
        )

    if cut_label_type not in available_cut_labels:
        raise ValueError(
            "The provided cut_label_type is not currently supported, please provide one"
            + f"of the following {', '.join(available_cut_labels)}")

    if not set(exchange_names).issubset(set(exchange_info.keys())):
        raise ValueError(
            "One or more of the provided exchange_names is not currently supported, please provide a subset"
            + f"of the following {', '.join(available_exchanges)}")

    # Delete each cut label if it already exists
    for exchange in exchange_names:
        exchange_code = exchange + "_" + cut_label_type
        try:
            response = api_factory.build(
                lusid.api.CutLabelDefinitionsApi).get_cut_label_definition(
                    code=exchange_code)
            response = api_factory.build(
                lusid.api.CutLabelDefinitionsApi).delete_cut_label_definition(
                    code=exchange_code)
        except lusid.ApiException as e:
            pass

    responses = []

    for exchange in exchange_names:
        exchange_code = exchange + "_" + cut_label_type
        exchange_time = models.CutLocalTime(exchange_info[exchange]["hour"],
                                            exchange_info[exchange]["minutes"])
        request = models.CutLabelDefinition(
            code=exchange_code,
            description=
            f"{exchange_code} which is at {exchange_info[exchange]['hour']}:{exchange_info[exchange]['minutes']} local time",
            display_name=exchange_code,
            cut_local_time=exchange_time,
            time_zone=exchange_info[exchange]["time_zone"],
        )
        try:
            response = api_factory.build(
                lusid.api.CutLabelDefinitionsApi).create_cut_label_definition(
                    create_cut_label_definition_request=request)
            responses.append(response)
        except lusid.ApiException as e:
            pass

    return responses