def group_delete(fxtype): try: group_data = request.json['group'] upper_fxtype = fxtype.upper() if upper_fxtype in ('SPOT', 'NDF'): for gr in group_data: databus.delete('LegalEntitiesRelationships/Groups_Spreads/FX' + upper_fxtype + '/' + gr) databus.delete('ClientSpreads/GroupSpreads/' + gr + '/FX' + upper_fxtype) with open(get_data_path('RobotFX_LegalEntitiesRelationships.json'), 'w') as json_file_out: json_file_out.write(json.dumps(databus.get_dict('LegalEntitiesRelationships'), indent=2)) with open(get_data_path('RobotFX_Client_Spreads.json'), 'w') as json_file_out: json_file_out.write(json.dumps(databus.get_dict('ClientSpreads'), indent=2)) return jsonify({'status': 'ok - group - ' + fxtype.lower() + ' - delete'}) else: raise KeyError() except KeyError: exc_info = sys.exc_info() return jsonify( { 'status': 'error - group - ' + fxtype.lower() + ' - delete', 'exception': ''.join(traceback.format_exception(*exc_info)), } )
def user_pwd_save(): try: with open(get_data_path('RobotFX_Users.json')) as json_file: users = json.load(json_file) user_pwd = request.json['data'] username = user_pwd['username'] new_password = user_pwd['password'] new_password = user_pwd['password'] users[username]['password'] = generate_password_hash(new_password) 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( [ ''.join(traceback.format_exception(*exc_info)), ' e o request foi: ', json.dumps(request.json['data'], indent=2), ] ), } )
def counterparty_data_edit(cnpj): with open(get_data_path('RobotFX_LegalEntities.json')) as json_file: legal_entities_data = json.load(json_file) counterparty = legal_entities_data[cnpj] counterparty['Cnpj'] = cnpj read_only = True alias_ndf = [] alias_spot = [] with open(get_data_path('RobotFX_LegalEntitiesRelationships.json')) as json_file: groups_data = json.load(json_file) spreads_data = groups_data.get('Groups_Spreads', {}) spot_groups = spreads_data.get('FXSPOT', {}) alias_spot = list(spot_groups.keys()) alias_spot.insert(0, '') ndf_groups = spreads_data.get('FXNDF', {}) alias_ndf = list(ndf_groups.keys()) alias_ndf.insert(0, '') spot_members_data = groups_data.get("Groups_Spreads_FXSPOT_Memberships", {}) selected_spot = spot_members_data.get(cnpj, None) ndf_members_data = groups_data.get("Groups_Spreads_FXNDF_Memberships", {}) selected_ndf = ndf_members_data.get(cnpj, None) return render_template( 'counterparty-edit.html', counterparty=json.dumps(counterparty), alias_ndf=json.dumps(alias_ndf), alias_spot=json.dumps(alias_spot), selected_ndf=json.dumps(selected_ndf), selected_spot=json.dumps(selected_spot), read_only=json.dumps(read_only), )
def group_edit(fxtype, alias): try: with open(get_data_path('RobotFX_LegalEntitiesRelationships.json')) as json_file: old_groups_data = json.load(json_file) upper_fxtype = fxtype.upper() if upper_fxtype in ('SPOT', 'NDF'): sub_old_groups_data = old_groups_data["Groups_Spreads"]["FX" + upper_fxtype] group = sub_old_groups_data[alias] group['Alias'] = alias group['Type'] = upper_fxtype members_data = old_groups_data['Groups_Spreads_FX' + upper_fxtype + '_Memberships'] members = tuple(k for k, v in members_data.items() if v == alias) with open(get_data_path('RobotFX_LegalEntities.json')) as json_file: legal_entities_data = json.load(json_file) list_members = [] for m in members: alias = legal_entities_data[m]["Alias"] name = legal_entities_data[m]['CounterpartyName'] list_members.append({'Alias': alias, 'Name': name, 'Cnpj': m}) else: raise KeyError() read_only = True return render_template( 'group-edit.html', group=json.dumps(group), members=json.dumps(list_members), read_only=json.dumps(read_only), ) except KeyError: exc_info = sys.exc_info() return jsonify({'status': 'error', 'exception': ''.join(traceback.format_exception(*exc_info))})
def group_put(): try: json_req_data = json.loads(request.data) group = json_req_data['group'] alias = json_req_data['alias'] with open(get_data_path('RobotFX_LegalEntitiesRelationships.json')) as json_file: groups_data = json.load(json_file) work_data = groups_data["Groups_Spreads"]['FX' + group['Type']] # Se for o update de um grupo existente if group['Alias'] == alias: work_data[alias]["Name"] = group["Name"] else: alias = group['Alias'] work_data[alias] = {'Name': group['Name']} groups_data["Groups_Spreads"]['FX' + group['Type']] = work_data with open(get_data_path('RobotFX_LegalEntitiesRelationships.json'), "w") as json_file_out: json_file_out.write(json.dumps(groups_data, indent=2)) databus.update_from_file(get_data_path('RobotFX_LegalEntitiesRelationships.json'), 'LegalEntitiesRelationships') return jsonify({'status': 'ok'}) except KeyError: exc_info = sys.exc_info() return jsonify({'status': 'error', 'exception': ''.join(traceback.format_exception(*exc_info))})
def engine_parameters_ndf_put(): engine_parameters = json.loads(request.data) status = 'ok' try: datetime.datetime.strptime( engine_parameters['engine_parameters']['EngineOnlineEndTime'], "%H:%M") except ValueError: status = 'ok - Not a valid date.' if status == 'ok': with open( get_data_path('RobotFX_TradingParameters.json')) as json_file: old_obj = json.load(json_file) old_obj["Engine_Global_Parameters"]["FXNDF"] = engine_parameters[ 'engine_parameters'] with open(get_data_path('RobotFX_TradingParameters.json'), "w") as json_file_out: json_file_out.write(json.dumps(old_obj, sort_keys=True, indent=4)) databus.update_from_file( get_data_path('RobotFX_TradingParameters.json'), 'TradingParameters') return jsonify({'status': status})
def spreads_ndf_get(): search_by_group = request.args.get('search_by', '').lower() == 'group' key = request.args.get('key', '').upper() sorted_currencies = json.loads(get_currencies_sorted()) with open(get_data_path('RobotFX_Client_Spreads.json')) as json_file: all_spreads = json.load(json_file) try: if search_by_group: all_spreads = all_spreads['GroupSpreads'] else: all_spreads = all_spreads['CounterpartySpreads'] spreads_by_product = all_spreads[key] spreads = spreads_by_product['FXNDF'] except KeyError: spreads = {'Spreads': {}} with open( get_data_path('RobotFX_NDFTimeBuckets.json')) as json_file: buckets_l = json.load(json_file).get('TimeBuckets') buckets = [value['EndDay'] for value in buckets_l] spreads['Buckets'] = buckets for ccy in sorted_currencies: spreads['Spreads'][ccy] = {'BUYSELL': [None] * len(buckets)} result = {'spreads_catalog': spreads, 'currencies': sorted_currencies} return jsonify(result)
def counterparty_ndf_put(): counterparty_ndf = json.loads(request.data)['counterparty_data'] with open(get_data_path('RobotFX_TradingParameters.json')) as json_file: old_obj = json.load(json_file) alt_obj = copy.deepcopy(old_obj) for cter_prty in counterparty_ndf: autoflow = cter_prty['automatic_flow'] upper_limmit_dc = cter_prty['upper_limit_dc'] validate_kyc = cter_prty['validate_kyc'] validate_kyc = validate_kyc if validate_kyc != 'NO: GOOD-TODAY' else 'YES' validate_isda = cter_prty['validate_isda'] validate_isda = validate_isda if validate_isda != 'NO: GOOD-TODAY' else 'YES' fxndf_obj = old_obj["CounterpartyKeys"][ cter_prty['cter_prty_id']]["FXNDF"] fxndf_obj["AutoFlow"] = autoflow fxndf_obj["UpperLimitDays2Maturity"] = upper_limmit_dc fxndf_obj["ValidateKYC"] = validate_kyc fxndf_obj["ValidateISDA"] = validate_isda fxndf_obj2 = alt_obj["CounterpartyKeys"][ cter_prty['cter_prty_id']]["FXNDF"] fxndf_obj2["AutoFlow"] = autoflow fxndf_obj2["UpperLimitDays2Maturity"] = upper_limmit_dc fxndf_obj2["ValidateKYC"] = validate_kyc fxndf_obj2["ValidateISDA"] = validate_isda with open(get_data_path('RobotFX_TradingParameters.json'), "w") as json_file_out: json_file_out.write(json.dumps(old_obj, sort_keys=True, indent=4)) databus.update_from_dict(alt_obj, 'TradingParameters') return jsonify({'status': 'ok'})
def supplier_control_limits_put(): currencies_config = request.json['data'] def is_brl_ok(config): return is_positive_number(config.get('SettlementRate', None)) def is_ccy_ok(ccy, config): return (is_positive_number(config.get('SettlementRate', None)) and is_positive_number(config.get('MaxQuantity', None)) and is_positive_number(config.get('MarkupBUY', None), ge=True) and is_positive_number(config.get('MarkupSELL', None), ge=True)) ccy_valid = False system_currencies = databus.get('Currencies') if set(system_currencies) != set(currencies_config.keys()): return jsonify({'status': 'error - invalid_uploaded_data' }) # TODO: melhorar mensagem for ccy, config in currencies_config.items(): if ccy.lower() == 'brl': ccy_valid = is_brl_ok(config) else: ccy_valid = is_ccy_ok(ccy, config) if not ccy_valid: return jsonify({'status': 'error - invalid_uploaded_data'}) with open(get_data_path('RobotFX_FXSupplierControl.json'), 'w') as json_file_out: json_file_out.write(json.dumps(currencies_config, indent=2)) databus.update_from_file(get_data_path('RobotFX_FXSupplierControl.json'), 'FXSupplierControl') return jsonify({'status': 'ok'})
def config(): with open(get_data_path('RobotFX_SpotConfig.json')) as json_file: spot_config = json.load(json_file) cutoff_times = spot_config['CutOffTimes'] with open(get_data_path('RobotFX_Currencies.json')) as currencies_json_file: cur_data = json.load(currencies_json_file) for cur in cutoff_times['Primary']: cutoff_times['Primary'][cur]['ViewPriority'] = cur_data[cur]['ViewPriority'] with open(get_data_path('RobotFX_NDFTimeBuckets.json')) as json_file: time_buckets_data = json.load(json_file) time_buckets = time_buckets_data['TimeBuckets'] counterparties = [] with open(get_data_path('RobotFX_LegalEntities.json')) as json_file: legal_entities_data = json.load(json_file) for (key, obj) in legal_entities_data.items(): counterparties.append( { 'Id': len(counterparties) + 1, 'Alias': obj['Alias'], 'Counterparty': obj['CounterpartyName'], 'Cnpj': key, 'MarketType': obj['FXMarketType'], 'DefaultTransaction': obj['DefaultFXTransaction'], 'Products': obj['Products'], } ) counterparties = sorted(counterparties, key=lambda cparty: cparty['Alias']) # groups = [] with open(get_data_path('RobotFX_LegalEntitiesRelationships.json')) as json_file: groups_data = json.load(json_file) groups_data = groups_data.get('Groups_Spreads', {}) spot_groups = groups_data.get('FXSPOT', {}) ndf_groups = groups_data.get('FXNDF', {}) spot_timeout = databus.get('TradingParameters/Engine_Global_Parameters/FXSPOT/RFQ_Timeout') ndf_timeout = databus.get('TradingParameters/Engine_Global_Parameters/FXNDF/RFQ_Timeout') json_sorted_currencies = get_currencies_sorted() return render_template( 'config-main.html', cutoff_times=json.dumps(cutoff_times), time_buckets=json.dumps(time_buckets), counterparties=json.dumps(counterparties), spot_groups=json.dumps(spot_groups), ndf_groups=json.dumps(ndf_groups), currencies=json.dumps(cur_data), spot_timeout=json.dumps(spot_timeout), ndf_timeout=json.dumps(ndf_timeout), sorted_currencies=json_sorted_currencies, )
def put_time_buckets(): time_buckets = request.json['time_buckets'] with open(get_data_path('RobotFX_NDFTimeBuckets.json')) as json_file: time_buckets_data = json.load(json_file) time_buckets_data['TimeBuckets'] = time_buckets with open(get_data_path('RobotFX_NDFTimeBuckets.json'), 'w') as json_file_out: json_file_out.write(json.dumps(time_buckets_data, indent=2)) databus.update_from_file(get_data_path('RobotFX_NDFTimeBuckets.json'), 'NDFTimeBuckets') return jsonify({'status': 'ok'})
def cutoff_times_spot_put(): json_data = json.loads(request.data) cutoff_times_spot = json_data['cutoff_times'] with open(get_data_path('RobotFX_SpotConfig.json')) as json_file: old_obj = json.load(json_file) old_obj["CutOffTimes"] = cutoff_times_spot with open(get_data_path('RobotFX_SpotConfig.json'), "w") as json_file_out: json_file_out.write(json.dumps(old_obj, indent=2)) databus.update_from_file(get_data_path('RobotFX_SpotConfig.json'), 'SpotConfig') return jsonify({'status': 'ok'})
def currency_keys_spot_put(): currency_keys = json.loads(request.data) with open(get_data_path('RobotFX_TradingParameters.json')) as json_file: old_obj = json.load(json_file) old_obj["CurrencyKeys"] = currency_keys['currency_keys'] with open(get_data_path('RobotFX_TradingParameters.json'), "w") as json_file_out: json_file_out.write(json.dumps(old_obj, sort_keys=True, indent=4)) databus.update_from_file(get_data_path('RobotFX_TradingParameters.json'), 'TradingParameters') return jsonify({'status': 'ok'})
def currencies_put(): try: currencies = json.loads(request.data)['currencies'] with open(get_data_path('RobotFX_Currencies.json'), "w") as json_file_out: json_file_out.write(json.dumps(currencies, indent=2)) databus.update_from_file(get_data_path('RobotFX_Currencies.json'), 'Currencies') return jsonify({'status': 'ok'}) except KeyError: exc_info = sys.exc_info() return jsonify({'status': 'error', 'exception': ''.join(traceback.format_exception(*exc_info))}) except json.decoder.JSONDecodeError: return jsonify({'status': 'fail'})
def get_user_profile_option_list(): global default_type_profiles if not default_type_profiles: with open(get_data_path('RobotFX_TypeProfiles.json')) as json_file: default_type_profiles = json.load(json_file) return [{'value': k, 'text': v} for k, v in default_type_profiles.items()]
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')
def calendar_cur_post(cur): try: if '0' not in request.files: return jsonify({'status': 'fail'}) x = request.files['0'] path = get_data_path('Holydays_{currency}.csv'.format(currency=cur), subdirs=['calendars']) x.save(path) date_index = 0 name_index = 1 with open(path, 'r') as csv_file: reader = csv.reader(csv_file) for row in reader: try: if row: datetime.datetime.strptime(row[date_index], "%Y-%m-%d") if not row[name_index]: raise Exception('Invalid file contents!') except ValueError: raise Exception('Invalid file contents!') return jsonify({'status': 'ok'}) except (KeyError, Exception): exc_info = sys.exc_info() return jsonify({'status': 'error', 'exception': ''.join(traceback.format_exception(*exc_info))})
def counterparty_data_add(): counterparty = {} counterparty['Cnpj'] = '' counterparty['Alias'] = '' counterparty['CounterpartyName'] = '' counterparty['Products'] = [] read_only = False alias_ndf = [] alias_spot = [] with open(get_data_path('RobotFX_LegalEntitiesRelationships.json')) as json_file: groups_data = json.load(json_file) spreads_data = groups_data.get('Groups_Spreads', {}) spot_groups = spreads_data.get('FXSPOT', {}) alias_spot = list(spot_groups.keys()) alias_spot.insert(0, '') ndf_groups = spreads_data.get('FXNDF', {}) alias_ndf = list(ndf_groups.keys()) alias_ndf.insert(0, '') selected_spot = '' selected_ndf = '' return render_template( 'counterparty-edit.html', counterparty=json.dumps(counterparty), alias_ndf=json.dumps(alias_ndf), alias_spot=json.dumps(alias_spot), selected_ndf=json.dumps(selected_ndf), selected_spot=json.dumps(selected_spot), read_only=json.dumps(read_only), )
def engine_control_ndf(): with open(get_data_path('RobotFX_TradingParameters.json')) as json_file: trading_parameters = json.load(json_file) engine_parameters = trading_parameters["Engine_Global_Parameters"][ "FXNDF"] return render_template('engine-control-ndf.html', engine_parameters=json.dumps(engine_parameters))
def supplier_control(): with open(get_data_path('RobotFX_FXSupplierControl.json')) as json_file: currencies_config = json.load(json_file) json_sorted_currencies = get_currencies_sorted() return render_template( 'supplier-control.html', currencies_config=json.dumps(currencies_config), sorted_currencies=json_sorted_currencies, )
def engine_control_spot(): with open(get_data_path('RobotFX_TradingParameters.json')) as json_file: trading_parameters = json.load(json_file) engine_parameters = trading_parameters["Engine_Global_Parameters"][ "FXSPOT"] with open(get_data_path('RobotFX_SpotConfig.json')) as json_file: spot_config = json.load(json_file) cutoff_times = spot_config['CutOffTimes'] spot_timeout = databus.get( 'TradingParameters/Engine_Global_Parameters/FXSPOT/RFQ_Timeout') return render_template( 'engine-control-spot.html', engine_parameters=json.dumps(engine_parameters), cutoff_times=json.dumps(cutoff_times), spot_timeout=json.dumps(spot_timeout), )
def user_check(user_name): try: with open(get_data_path('RobotFX_Users.json')) as json_file: users = json.load(json_file) result = user_name in users return jsonify({'status': str(result)}) except Exception: exc_info = sys.exc_info() return jsonify({'status': 'error', 'exception': ''.join(traceback.format_exception(*exc_info))})
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), )
def save_new_user(): try: with open(get_data_path('RobotFX_Users.json')) as json_file: users = json.load(json_file) user_dict = request.json['data'] username = user_dict['username'].lower() del user_dict['username'] if username in users: return jsonify({'status': 'duplicate'}) user_dict['password'] = generate_password_hash(user_dict['password']) del user_dict['confirm_password'] if 'errors' in user_dict: del user_dict['errors'] if user_dict['role'] in ('e-sales ndf', 'e-sales spot'): user_dict['allow_validate'] = 'Yes' if user_dict['allow_validate'] else 'No' else: user_dict['allow_validate'] = 'N/A' users[username] = user_dict with open(get_data_path('RobotFX_Users.json'), 'w') as json_file_out: json_file_out.write(json.dumps(users, indent=2)) return jsonify({'status': 'ok'}) except Exception: exc_info = sys.exc_info() return jsonify( { 'status': 'error', 'exception': ''.join( [ ''.join(traceback.format_exception(*exc_info)), ' e o request foi: ', json.dumps(request.json['data'], indent=2), ] ), } )
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))})
def engine_parameters_spot_put(): try: engine_parameters = json.loads(request.data) with open( get_data_path('RobotFX_TradingParameters.json')) as json_file: old_obj = json.load(json_file) old_obj["Engine_Global_Parameters"]["FXSPOT"] = engine_parameters[ 'engine_parameters'] with open(get_data_path('RobotFX_TradingParameters.json'), "w") as json_file_out: json_file_out.write(json.dumps(old_obj, sort_keys=True, indent=4)) databus.update_from_file( get_data_path('RobotFX_TradingParameters.json'), 'TradingParameters') return jsonify({'status': 'ok'}) except json.decoder.JSONDecodeError: # caso uso do comando: curl... return jsonify({'status': 'fail'}) except Exception: return jsonify({'status': 'fail'})
def casado_data_put(): casado_config = request.json['data'] if not casado_config or not is_positive_number(casado_config): return jsonify({'status': 'error - invalid_uploaded_data'}) with open(get_data_path('RobotFX_FXSupplierCasado.json')) as json_file: casado_data = json.load(json_file) try: casado_data['Price'] = float(casado_config) except ValueError: return jsonify( {'status': "error: casado price's data is invalid!"}) with open(get_data_path('RobotFX_FXSupplierCasado.json'), 'w') as json_file_out: json_file_out.write(json.dumps(casado_data, indent=2)) databus.update_from_file(get_data_path('RobotFX_FXSupplierCasado.json'), 'FXSupplierCasado') return jsonify({'status': 'ok'})
def user_pwd_edit(): try: with open(get_data_path('RobotFX_Users.json')) as json_file: user_data = json.load(json_file) username = request.form['username'] password = request.form['password'] if username in user_data: hash_password = user_data[username]['password'] if hash_password == password: return render_template('user_pwd_edit.html', username=username) except KeyError: return render_template('404.html') return render_template('404.html')
def save_old_user(): try: with open(get_data_path('RobotFX_Users.json')) as json_file: users = json.load(json_file) user_dict = request.json['data'] username = user_dict['username'].lower() if username not in users: return jsonify({'status': 'error'}) del user_dict['username'] for key in ("confirm_password", 'errors'): if key in user_dict: del user_dict[key] user_dict['allow_validate'] = 'Yes' if user_dict['allow_validate'] else 'No' users[username] = user_dict with open(get_data_path('RobotFX_Users.json'), 'w') as json_file_out: json_file_out.write(json.dumps(users, indent=2)) return jsonify({'status': 'ok'}) except Exception: exc_info = sys.exc_info() return jsonify( { 'status': 'error', 'exception': ''.join( [ ''.join(traceback.format_exception(*exc_info)), ' e o request foi: ', json.dumps(request.json['data'], indent=2), ] ), } )
def spreads_spot(): legal_entities = {} with open(get_data_path( 'RobotFX_LegalEntitiesRelationships.json')) as rel_leg_ent_json: rel_leg_ents = json.load(rel_leg_ent_json) wgrp = rel_leg_ents['Groups_Spreads']['FXSPOT'] groups = { elem: { 'NameHolding': name['Name'] } for elem, name in wgrp.items() } with open(get_data_path('RobotFX_LegalEntities.json')) as json_file: counterparties = json.load(json_file) counterparties = { k: v for k, v in counterparties.items() if 'FXSPOT' in v['Products'] } legal_entities = {'Groups': groups, 'Counterparties': counterparties} return render_template('spreads-spot.html', legal_entities=json.dumps(legal_entities))