Ejemplo n.º 1
0
def user_editing(username):
    role_options = get_user_profile_option_list()
    insert_case = json.dumps(False)
    user_id = session.get("user_id", None)
    username_databus = get_username(user_id)
    delete_disabled = json.dumps(username == username_databus)

    try:
        with open(get_data_path('RobotFX_Users.json')) as json_file:
            user_data = json.load(json_file)
            if username not in user_data:
                return render_template('404.html')

            response_data = user_data[username]
            response_data['allow_validate'] = json.dumps(response_data['allow_validate'])
            response_data['username'] = username
            override_enabled = json.dumps(user_data[username]['role'] in ('e-sales ndf', 'e-sales spot'))
            change_pwd_enabled = json.dumps(True)

            return render_template(
                'user_insert_edit.html',
                user_data=response_data,
                role_data=role_options,
                insert_case=insert_case,
                delete_disabled=delete_disabled,
                override_enabled=override_enabled,
                change_pwd_enabled=change_pwd_enabled,
                title_contents="Edit User",
            )
    except Exception:
        raise
        return render_template('404.html')
Ejemplo n.º 2
0
def user_own_pwd_edit():
    try:
        user_id = session['user_id']
        user_role = get_user_role(user_id)
        username = get_username(user_id)
        return render_template('user_own_pwd_edit.html', username=username, oldpass='', user_role=user_role)
    except KeyError:
        return render_template('404.html')

    return render_template('404.html')
Ejemplo n.º 3
0
def trading_parameters_ndf():
    trading_parameters = databus.get_dict('TradingParameters')
    engine_parameters = json.dumps(
        trading_parameters["Engine_Global_Parameters"]["FXNDF"])
    currency_keys = json.dumps(trading_parameters["CurrencyKeys"])
    counterparty_list = []
    leg_entities = databus.get_dict('LegalEntities')
    if leg_entities is None:
        leg_entities = {}
    trad_counterparties = trading_parameters['CounterpartyKeys']
    common_cp_keys = tuple(k for k, v in leg_entities.items()
                           if 'FXNDF' in v['Products'])
    for cp_key in common_cp_keys:
        trad_value = trad_counterparties[cp_key]['FXNDF']
        validate_kyc_rule = update_validate_rule(trad_value['ValidateKYC'],
                                                 'KYC', cp_key, True)
        validate_isda_rule = update_validate_rule(trad_value['ValidateISDA'],
                                                  'ISDA', cp_key, True)
        counterparty_list.append({
            'cter_prty_id':
            cp_key,
            'counterparty':
            leg_entities[cp_key]["CounterpartyName"],
            'upper_limit_dc':
            trad_value['UpperLimitDays2Maturity'],
            'automatic_flow':
            trad_value['AutoFlow'],
            'validate_kyc':
            validate_kyc_rule,
            'validate_isda':
            validate_isda_rule,
        })

    with open(get_data_path('RobotFX_Users.json')) as json_file:
        user_data = json.load(json_file)
        user_id = session.get("user_id", None)
        username = get_username(user_id)
        if username not in user_data:
            return render_template('404.html')

        response_data = user_data[username]
        allow_validate = response_data['allow_validate'].lower() == 'yes'

    validate_parameters = get_validate_parameters()

    json_sorted_currencies = get_currencies_sorted()
    return render_template(
        'trading-parameters-ndf.html',
        engine_parameters=engine_parameters,
        currency_keys=currency_keys,
        counterparty_data=json.dumps(counterparty_list),
        sorted_currencies=json_sorted_currencies,
        allow_validate=json.dumps(allow_validate),
        validate_parameters=json.dumps(validate_parameters),
    )
Ejemplo n.º 4
0
def erase_log():
    ping_ip1 = subprocess.run(
        f"cd /var/log && truncate -s 0 rfx-*",
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        shell=True,
        encoding="utf-8",
    )
    user_id = session.get("user_id", None)
    username = get_username(user_id)
    print(f"Log erased by: {username}", flush=True)
    stderr_msg = ping_ip1.stderr
    if not stderr_msg:
        return jsonify({'status': 'success', 'msg': 'Log erased'})
    else:
        return jsonify({'status': 'error', 'msg': 'Error: ' + stderr_msg})
Ejemplo n.º 5
0
def reboot():
    user_id = session.get("user_id", None)
    username = get_username(user_id)
    print(f"REBOOTING by: {username}", flush=True)
    ping_ip1 = subprocess.run(
        f"""sh /opt/robotfx/etc/robotfx.sh restart 'rfx-flask_website
                                                    rfx-legacy_mocks
                                                    rfx-frontend
                                                    rfx-fixserver'""",
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        shell=True,
        encoding="utf-8",
    )
    stdout_msg = ping_ip1.stdout
    stderr_msg = ping_ip1.stderr
    if not stderr_msg:
        return jsonify({'status': 'success', 'msg': stdout_msg})
    else:
        return jsonify({'status': 'error', 'msg': stderr_msg})
Ejemplo n.º 6
0
def user_delete(user_name):
    user_id = session.get("user_id", None)
    username_databus = get_username(user_id)
    try:
        if user_name == username_databus:
            return jsonify({'status': 'error', 'exception': 'Trying to delete the same user...!'})

        with open(get_data_path('RobotFX_Users.json')) as json_file:
            users = json.load(json_file)
            if user_name in users:
                del users[user_name]
            else:
                raise Exception('User: '******' not in json file!')

        with open(get_data_path('RobotFX_Users.json'), 'w') as json_file_out:
            json_file_out.write(json.dumps(users))

        return jsonify({'status': 'ok'})
    except Exception:
        exc_info = sys.exc_info()
        return jsonify({'status': 'error', 'exception': ''.join(traceback.format_exception(*exc_info))})
Ejemplo n.º 7
0
def bpipe_log_level():
    if request.json:
        os.environ['BLPAPI_LOGLEVEL'] = request.json['log_level']
        user_id = session.get("user_id", None)
        username = get_username(user_id)
        print(f"REBOOTING by: {username}", flush=True)
        ping_ip1 = subprocess.run(
            f"""sh /opt/robotfx/etc/robotfx.sh restart 'rfx-flask_website
                                                        rfx-legacy_mocks
                                                        rfx-frontend
                                                        rfx-fixserver'""",
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            shell=True,
            encoding="utf-8",
        )
        stdout_msg = ping_ip1.stdout
        stderr_msg = ping_ip1.stderr
        if not stderr_msg:
            return jsonify({'status': 'ok', 'msg': stdout_msg})
        else:
            return jsonify({'status': 'error', 'msg': stderr_msg})
Ejemplo n.º 8
0
def spreads_spot_put():
    now = get_local_time()
    type_update = request.args.get('type', '').lower()
    update_group = type_update == 'group'
    key = request.args.get('key', '').upper()
    status = request.json['status']
    currency = status['currency']
    spotDay = status['spotday']
    side = status['side']
    spread = status['spread']
    if spread != '-':
        spread = int(
            Decimal(spread) *
            10_000)  # Solucao de caso de spread igual a: 12, 24 ou 48.

    basic_key = 'SpreadRegistry/SPOT/' + type_update

    if databus.exists(basic_key):
        data_list = databus.get(basic_key)
    else:
        data_list = []
    user_id = session.get("user_id", None)
    username = get_username(user_id)
    element = {
        'target': key,
        'ts': now.strftime('%Y-%m-%d %H:%M:%S'),
        'user': str(username),
        'ccy': str(currency),
        'spotday': str(spotDay),
        'side': str(side),
        'spread': str(spread),
    }

    if not update_group:
        element['counterparty'] = databus.get(
            'LegalEntities/{cnpj}/CounterpartyName'.format(cnpj=key))
        basic_group_key = 'LegalEntitiesRelationships/Groups_Spreads_'
        if databus.exists((basic_group_key +
                           'FX{type}_Memberships/{cnpj}').format(cnpj=key,
                                                                 type='SPOT')):
            element['group'] = databus.get(
                (basic_group_key + 'FX{type}_Memberships/{cnpj}').format(
                    cnpj=key, type="SPOT"))
        else:
            element['group'] = '-'

    data_list.append(element)

    databus.set(basic_key, data_list)

    manage_spreads_tables(1, is_ndf=False)

    with open(get_data_path('RobotFX_Client_Spreads.json')) as json_file:
        all_spreads = json.load(json_file)
        entity_type = 'GroupSpreads' if update_group else 'CounterpartySpreads'
        if key not in all_spreads[entity_type]:
            all_spreads[entity_type][key] = {}

        all_spreads[entity_type][key]['FXSPOT'] = request.json['spreads']

    with open(get_data_path('RobotFX_Client_Spreads.json'),
              'w') as json_file_out:
        json_file_out.write(json.dumps(all_spreads, indent=2))

    databus.update_from_file(get_data_path('RobotFX_Client_Spreads.json'),
                             'ClientSpreads')

    return jsonify({'status': 'ok'})
Ejemplo n.º 9
0
def trading_parameters_spot():
    cash_limits_initialized = databus.get(
        'System/Status/Trading/SPOT/Initialized')
    trading_parameters = databus.get_dict('TradingParameters')
    engine_parameters = trading_parameters["Engine_Global_Parameters"][
        "FXSPOT"]
    currency_keys = trading_parameters["CurrencyKeys"]
    leg_entities = databus.get_dict('LegalEntities')
    if leg_entities is None:
        leg_entities = {}
    trad_counterparties = trading_parameters['CounterpartyKeys']
    common_cp_keys = tuple(k for k, v in leg_entities.items()
                           if 'FXSPOT' in v['Products'])
    counterparty_list = []
    for cp_key in common_cp_keys:
        trad_value = trad_counterparties[cp_key]['FXSPOT']
        validate_kyc_rule = update_validate_rule(trad_value['ValidateKYC'],
                                                 'KYC', cp_key, False)
        counterparty_list.append({
            'cter_prty_id':
            cp_key,
            'counterparty':
            leg_entities[cp_key]["CounterpartyName"],
            'automatic_flow':
            trad_value['AutoFlow'],
            'validate_kyc':
            validate_kyc_rule,
        })
    json_sorted_currencies = get_currencies_sorted()
    cash_limits_logs = {}

    if cash_limits_initialized:
        cash_limits_logs = databus.get_dict('CashLimits/Logs')
        pre_trading_ini_bal = {}
        for currency, maturity_value in cash_limits_logs.items():
            pre_trading_ini_bal[currency] = {}
            for maturity, value in maturity_value.items():
                if isinstance(value, list) and len(value) > 0:
                    pre_trading_ini_bal[currency][maturity] = value[0]
    else:
        cash_limits_logs = {}
        pre_trading_ini_bal = trading_parameters['PreTradingInitialBalance']

    with open(get_data_path('RobotFX_Users.json')) as json_file:
        user_data = json.load(json_file)
        user_id = session.get("user_id", None)
        username = get_username(user_id)
        if username not in user_data:
            return render_template('404.html')

        response_data = user_data[username]
        allow_validate = response_data['allow_validate'].lower() == 'yes'

    validate_parameters = get_validate_parameters()

    return render_template(
        'trading-parameters-spot.html',
        engine_parameters=json.dumps(engine_parameters),
        currency_keys=json.dumps(currency_keys),
        pre_trading_ini_bal=json.dumps(pre_trading_ini_bal),
        counterparty_data=json.dumps(counterparty_list),
        sorted_currencies=json_sorted_currencies,
        spot_initialized=cash_limits_initialized,
        cash_limits_logs=cash_limits_logs,
        allow_validate=json.dumps(allow_validate),
        validate_parameters=json.dumps(validate_parameters),
    )
Ejemplo n.º 10
0
def spreads_ndf_put():
    now = get_local_time()
    print('ndf put.....')
    type_update = request.args.get('type', '').lower()
    update_group = type_update == 'group'
    key = request.args.get('key', '').upper()
    if 'status' not in request.json:
        return jsonify({
            'status':
            'error',
            'exception':
            'Status data is not in Request\'s JSON\'s Content.'
        })

    status = request.json['status']
    if ('currency' in status) and ('bucket' in status) and ('spread'
                                                            in status):
        currency = status['currency']
        bucket = status['bucket']
        spread = status['spread']
        if spread is None:
            spread = '-'

        if spread != '-':
            spread = int(
                Decimal(spread) *
                10_000)  # Solucao de caso de spread igual a: 12, 24 ou 48.

        basic_key = 'SpreadRegistry/NDF/' + type_update

        if databus.exists(basic_key):
            data_list = databus.get(basic_key)
        else:
            data_list = []

        user_id = session.get("user_id", None)
        username = get_username(user_id)
        element = {
            'target': key,
            'ts': now.strftime('%Y-%m-%d %H:%M:%S'),
            'user': str(username),
            'ccy': str(currency),
            'bucket': str(bucket),
            'spread': str(spread),
        }

        if not update_group:
            element['counterparty'] = databus.get(
                'LegalEntities/{cnpj}/CounterpartyName'.format(cnpj=key))
            basic_group_key = 'LegalEntitiesRelationships/Groups_Spreads_'
            if databus.exists(
                (basic_group_key + 'FX{type}_Memberships/{cnpj}').format(
                    cnpj=key, type='NDF')):
                element['group'] = databus.get(
                    (basic_group_key + 'FX{type}_Memberships/{cnpj}').format(
                        cnpj=key, type="NDF"))
            else:
                element['group'] = '-'

        data_list.append(element)

        databus.set(basic_key, data_list)

        manage_spreads_tables(1, is_ndf=True)

    with open(get_data_path('RobotFX_Client_Spreads.json')) as json_file:
        all_spreads = json.load(json_file)
        entity_type = 'GroupSpreads' if update_group else 'CounterpartySpreads'
        if key not in all_spreads[entity_type]:
            all_spreads[entity_type][key] = {}

        all_spreads[entity_type][key]['FXNDF'] = request.json[
            'spreads_catalog']

    with open(get_data_path('RobotFX_Client_Spreads.json'),
              'w') as json_file_out:
        json_file_out.write(json.dumps(all_spreads, indent=2))

    databus.update_from_file(get_data_path('RobotFX_Client_Spreads.json'),
                             'ClientSpreads')

    return jsonify({'status': 'ok'})