Esempio n. 1
0
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'})
Esempio n. 2
0
def halt_spot():
    if request.method == 'GET':
        status_trading_spot = databus.get_dict('System/Status/Trading/SPOT')
        status_supplier = databus.get_dict('System/Status/Quoting')
        status_trading_spot.update(status_supplier)
        return jsonify(status_trading_spot)
    if request.method == 'PUT':
        spot_key = databus.get_dict('System/Status/General/Spot')
        if spot_key:
            databus.update_from_dict(json.loads(request.data),
                                     "System/Status/Trading")
            return jsonify({'status': 'ok'})
        else:
            return jsonify({'status': 'ok - halted'})
Esempio n. 3
0
def halt_ndf():
    if request.method == 'GET':
        status_trading_ndf = databus.get_dict('System/Status/Trading/NDF')
        status_supplier = databus.get_dict('System/Status/Quoting')
        status_trading_ndf.update(status_supplier)
        return jsonify(status_trading_ndf)
    if request.method == 'PUT':
        ndf_key = databus.get_dict('System/Status/General/NDF')
        if ndf_key:
            databus.update_from_dict(json.loads(request.data),
                                     "System/Status/Trading")
            return jsonify({'status': 'ok'})
        else:
            return jsonify({'status': 'ok - halted'})
Esempio n. 4
0
def halt_quoting():
    if request.method == 'GET':
        return jsonify(databus.get_dict('System/Status/Quoting'))
    if request.method == 'PUT':
        spot_key = databus.get_dict('System/Status/General/Spot')
        ndf_key = databus.get_dict('System/Status/General/NDF')
        data = (json.loads(request.data))['Quoting']
        allow_clicking_NDF = 'Spot' not in data and 'NDF' in data and ndf_key
        allow_clicking_Spot = 'Spot' in data and 'NDF' not in data and spot_key
        allow_clicking_All = 'Spot' in data and 'NDF' in data and spot_key and ndf_key
        if allow_clicking_NDF or allow_clicking_Spot or allow_clicking_All:
            databus.update_from_dict(json.loads(request.data), "System/Status")
            return jsonify({'status': 'ok'})
        else:
            return jsonify({'status': 'ok - halted'})
Esempio n. 5
0
def pre_trading_ini_bal_spot_put():
    pre_trading_ini_bal_spot = json.loads(request.data)['pre_trading_ini_bal']

    initialized = False
    log = {}

    for ccy, maturity_balance in pre_trading_ini_bal_spot.items():
        log[ccy] = {}
        for maturity, value in maturity_balance.items():
            log[ccy][maturity] = [value]
            if value is not None:
                initialized = True

    databus.update_from_dict(pre_trading_ini_bal_spot, 'CashLimits/SPOT')
    databus.update_from_dict(log, 'CashLimits/Logs')
    databus.set('System/Status/Trading/SPOT/Initialized', initialized)

    return jsonify({'status': 'ok'})
Esempio n. 6
0
def set_timestamp(msg_id, msg_code, value):
    if msg_code != 'Quote':
        result = databus.get(f'Transactions/Metrics/{msg_id}')
        if result is not None:
            j = json.loads(result)
        else:
            j = {'timestamps': {}}
        j['timestamps'][msg_code] = value
        pack = json.dumps(j)
        databus.update_from_dict({msg_id: pack}, 'Transactions/Metrics')
    else:  # for Quote is a list of timestamps
        result = databus.get(f'Transactions/Metrics/{msg_id}')
        j = json.loads(result)
        if 'Quote' not in j['timestamps'].keys():
            j['timestamps'][msg_code] = []
        j['timestamps'][msg_code].append(get_local_timestamp())
        pack = json.dumps(j)
        databus.update_from_dict({msg_id: pack}, 'Transactions/Metrics')

    r.publish('history', json.dumps({"info": "metrics", "publish_data": {'pack': pack, 'msg_id': msg_id}}))
Esempio n. 7
0
def update_blotter(msg):
    model = None

    if isinstance(msg, messages.QuoteRequest):
        quoterequest = msg
    else:
        quoterequest, _ = get_quoterequest_msg(msg.QuoteReqID)

    if quoterequest.SecurityType == messages.EnumSecurityType.SPOT:
        model = update_blotter_spot(msg)
        if model:
            cur = model["currency"]
            root_key = f'Balance/SPOT/{cur}/TotalAmount/'
            if model['mtype'] == "DEAL":
                buy_total = sum(float(databus.get(root_key + 'BuyD' + str(i))) for i in range(3))
                sell_total = sum(float(databus.get(root_key + 'SellD' + str(i))) for i in range(3))
                accounting_supplier_model = {
                    model['currency']: {
                        'net': buy_total - sell_total,
                        'buy_total': buy_total,
                        'buy_d0': float(databus.get(root_key + 'BuyD0')),
                        'buy_d1': float(databus.get(root_key + 'BuyD1')),
                        'buy_d2': float(databus.get(root_key + 'BuyD2')),
                        'sell_total': sell_total,
                        'sell_d0': float(databus.get(root_key + 'SellD0')),
                        'sell_d1': float(databus.get(root_key + 'SellD1')),
                        'sell_d2': float(databus.get(root_key + 'SellD2')),
                    }
                }
                accounting_supplier_model_json = json.dumps(json.dumps(accounting_supplier_model))
                r.publish('accounting_fxsupplier', accounting_supplier_model_json)
    elif quoterequest.SecurityType == messages.EnumSecurityType.NDF:
        model = update_blotter_ndf(msg)

    if model:
        model_json = json.dumps(model)
        entry = {model['quote_req_id']: model_json}
        databus.update_from_dict(entry, 'Blotter')
        r.publish('blotter', json.dumps(model_json))
        r.publish('blotter_fxsupplier', json.dumps(model_json))
Esempio n. 8
0
def set_transaction(msg, details=None):
    msg_code = msg.get_message_code()
    current_status = get_transaction_status(msg.QuoteReqID)

    if msg_code not in messages.Flow[current_status]:
        if msg_code == messages.Code.Quote:  # ignora cotação que chegar atrasada
            return

        raise RuntimeError(f'ID: {msg.QuoteReqID}: {msg_code} is not a valid sequence to {current_status}')

    msg_id = msg.get_message_id()
    msg_str = messages.serialize_to_json(msg)
    pack = json.dumps({'msg': msg_str})
    entry = {msg.MsgType: {msg_id: pack}}
    databus.update_from_dict(entry, 'Transactions/Messages')
    databus.update_from_dict({msg.QuoteReqID: msg_code}, 'Transactions/Status')
    if msg_code == messages.Code.Quote:
        databus.update_from_dict({msg.QuoteReqID: msg.QuoteID}, 'Transactions/LastQuoteID')
    set_timestamp(msg.QuoteReqID, msg_code, get_local_timestamp())
    update_blotter(msg)

    r.publish('history', json.dumps({"info": "transaction", "publish_data": msg_str}))