Ejemplo n.º 1
0
def ip_return(connection):
    #
    # Check if we have connections
    #
    request_ip_return = TQRequests.request_ip_return()
    message = connection.send_web(request_ip_return)
    return make_results(message, connection)
Ejemplo n.º 2
0
def account_status(connection, user_email):
    #
    # check the status of the account
    #
    request_account_create = TQRequests.request_account_status(user_email)
    message = connection.send_web(request_account_create)
    return make_results(message, connection)
Ejemplo n.º 3
0
def account_token_generate(connection, email):
    #
    # sends (resends) activation key
    #
    request_account_token_create = TQRequests.request_account_token_create(
        email)
    message = connection.send_web(request_account_token_create)
    return make_results(message, connection)
Ejemplo n.º 4
0
def account_send_activation_key(connection, user_email, callback_url, is_test):
    #
    # sends (resends) activation key
    #
    request_account_send_activation_key = TQRequests.request_account_send_activation_key(
        user_email, callback_url, is_test)
    message = connection.send_web(request_account_send_activation_key)
    return make_results(message, connection)
Ejemplo n.º 5
0
def account_activate(connection, activation_key, is_test):
    #
    # Activates a  (disabled) account
    #
    request_account_activate = TQRequests.request_account_activate(
        activation_key, is_test)
    message = connection.send_web(request_account_activate)
    return make_results(message, connection)
Ejemplo n.º 6
0
def account_activation_key_status(connection, activation_key):
    #
    # Activates a  (disabled) account
    #
    request_account_activation_key_status = TQRequests.request_account_activation_key_status(
        activation_key)
    message = connection.send_web(request_account_activation_key_status)
    return make_results(message, connection)
Ejemplo n.º 7
0
def account_profile(connection, user_email, password):
    #
    # Changes/resets the password
    #
    request_account_profile_dict = TQRequests.request_account_profile(
        user_email, password)
    message = connection.send_web(request_account_profile_dict)
    return make_results(message, connection)
Ejemplo n.º 8
0
def account_password_reset(connection, activation_key, new_password, is_test):
    #
    # Changes/resets the password
    #
    request_account_password_reset_dict = TQRequests.request_account_password_reset(
        activation_key, new_password, is_test)
    message = connection.send_web(request_account_password_reset_dict)
    return make_results(message, connection)
Ejemplo n.º 9
0
def account_ip_change(connection, user_email, password, _ip, is_test):
    #
    # Changes the registered IP
    #
    request_account_ip_change = TQRequests.request_account_ip_change(
        user_email, password, _ip, is_test)
    message = connection.send_web(request_account_ip_change)
    return make_results(message, connection)
Ejemplo n.º 10
0
def account_password_change(connection, user_email, password, new_password,
                            is_test):
    #
    # Changes the existing password
    #
    request_account_password_change = TQRequests.request_account_password_change(
        user_email, password, new_password, is_test)
    message = connection.send_web(request_account_password_change)
    return make_results(message, connection)
Ejemplo n.º 11
0
def account_create(connection, user_email, user_password, user_ip,
                   callback_url, is_test):
    #
    # Creates a  account
    #
    request_account_create = TQRequests.request_account_create(
        user_email, user_password, user_ip, callback_url, is_test)
    message = connection.send_web(request_account_create)
    return make_results(message, connection)
Ejemplo n.º 12
0
def account_password_ip_change(connection, user_email, password, new_password,
                               new_ip, is_test):
    #
    # Changes password and IP at the same time
    #
    request_account_password_ip_change = TQRequests.request_account_password_ip_change(
        user_email, password, new_password, new_ip, is_test)
    message = connection.send_web(request_account_password_ip_change)
    return make_results(message, connection)
Ejemplo n.º 13
0
def formatted_grid_swap_rates(connection, from_date, to_date, currency,
                              tenors):
    #
    # Creates a grid of swap rates
    #
    request_formatted_grid_swap_rates = TQRequests.request_function_formatted_grid_swap_rates(
        from_date, to_date, currency)
    # todo: Shahram to remove below after TQapis version 0.12.5
    if 'tenors' not in request_formatted_grid_swap_rates.params:
        request_formatted_grid_swap_rates.params[
            'tenors'] = utility_common.list_to_csv(tenors)
    # end todo

    message = connection.send(request_formatted_grid_swap_rates)
    return make_results(message, connection)
Ejemplo n.º 14
0
def utility_download_formatted_grid_swap_rates(connection, currencies, tenors,
                                               folder):
    try:
        if not apis.connection_is_ok(connection):
            return (False, {
                'utility_download_formatted_grid_swap_rates':
                'failed on connection_is_ok(connection)'
            })
        #
        # Obtain all available dates
        #
        request_describe = TQRequests.request_function_show_available(
            "asof_dates")
        message = connection.send_web(request_describe)
        print(message.content)
        if not message.is_OK:
            return False, {
                'utility_download_formatted_grid_swap_rates': message.content
            }
        asof_dates = connection.response.results
        if len(asof_dates) < 2:
            return (False, {
                'utility_download_formatted_grid_swap_rates':
                'too few dates'
            })

        #
        # pick the two most available dates
        #
        # initialize the two dates
        to_date = '19000101'
        from_date = to_date

        for key, value in asof_dates.items():
            if value > to_date:
                to_date = value
            elif value < to_date and value > from_date:
                from_date = value

        #
        # Create a grid for each currency and sage it in a csv file
        #
        for currency in currencies:

            status, results = apis.formatted_grid_swap_rates(
                connection, from_date, to_date, currency, tenors)

            if not status:
                return (False, {
                    'utility_download_formatted_grid_swap_rates':
                    ' failed with from_date={}, to_date={} and currency={}'.
                    format(from_date, to_date, currency)
                })
            lines = []

            grid = Grid()
            path = os.path.join(folder, currency.upper() + ".csv")
            grid.headings.append("headings")
            for key, value in results.items():
                if 'title' in key:
                    grid.title = value
                elif 'headings' in key:
                    grid.headings.append(value)
                else:
                    tokens = value.split(",")
                    grid.tenors.append(key)
                    grid.y1.append(tokens[0])
                    grid.y2.append(tokens[1])
                    grid.y3.append(tokens[2])
            status, message = grid.save_as(path)
            if not status:
                return (False, {
                    'utility_download_formatted_grid_fx':
                    'failed while saving file with base_currency={} and folder={}. Exception was {}'
                    .format(currency, folder, message)
                })

    except Exception as e:
        return (False, {
            'utility_download_formatted_grid_swap_rates':
            'failed with the following exception {}'.format(e)
        })

    return (True, dict())