def get_and_add_prices_for_frequency(data,
                                     log,
                                     contract_object,
                                     frequency="D"):
    broker_data_source = dataBroker(data)
    db_futures_prices = updatePrices(data)

    ib_prices = broker_data_source.get_prices_at_frequency_for_contract_object(
        contract_object, frequency)
    if len(ib_prices) == 0:
        log.msg("No prices from broker for %s" % str(contract_object))
        return failure

    rows_added = db_futures_prices.update_prices_for_contract(
        contract_object, ib_prices, check_for_spike=True)
    if rows_added is data_error:
        # SPIKE
        # Need to email user about this as will need manually checking
        msg = (
            "Spike found in prices for %s: need to manually check by running interactive_manual_check_historical_prices"
            % str(contract_object))
        log.warn(msg)
        try:
            send_production_mail_msg(
                data, msg, "Price Spike %s" % contract_object.instrument_code)
        except BaseException:
            log.warn("Couldn't send email about price spike for %s" %
                     str(contract_object))

        return failure

    log.msg("Added %d rows at frequency %s for %s" %
            (rows_added, frequency, str(contract_object)))
    return success
Пример #2
0
def report_fx_data_spike(data: dataBlob, fx_code: str):
    msg = (
        "Spike found in prices for %s: need to manually check by running interactive_manual_check_fx_prices"
        % str(fx_code))
    data.log.warn(msg)
    try:
        send_production_mail_msg(data, msg, "FX Price Spike %s" % str(fx_code))
    except BaseException:
        data.log.warn("Couldn't send email about price spike")
Пример #3
0
def report_price_spike(data: dataBlob, contract_object: futuresContract):
    # SPIKE
    # Need to email user about this as will need manually checking
    msg = (
        "Spike found in prices for %s: need to manually check by running interactive_manual_check_historical_prices"
        % str(contract_object))
    data.log.warn(msg)
    try:
        send_production_mail_msg(
            data, msg, "Price Spike %s" % contract_object.instrument_code)
    except BaseException:
        data.log.warn("Couldn't send email about price spike for %s" %
                      str(contract_object))
def update_fx_prices_for_code(fx_code, data):
    broker_fx_source = dataBroker(data)
    db_fx_data = currencyData(data)

    new_fx_prices = broker_fx_source.get_fx_prices(
        fx_code)  # returns fxPrices object
    rows_added = db_fx_data.update_fx_prices(fx_code,
                                             new_fx_prices,
                                             check_for_spike=True)

    if rows_added is data_error:
        msg = "Spike found in prices for %s: need to manually check by running interactive_manual_check_fx_prices" % str(
            fx_code)
        data.log.warn(msg)
        try:
            send_production_mail_msg(data, msg,
                                     "FX Price Spike %s" % str(fx_code))
        except:
            data.log.warn("Couldn't send email about price spike")

    return success
Пример #5
0
def run_report_with_data_blob(report_config, data):
    """

    :param report_config:
    :return:
    """

    data.log.msg("Running report %s" % str(report_config))
    report_function = resolve_function(report_config.function)
    report_kwargs = report_config.kwargs

    try:
        report_results = report_function(data, **report_kwargs)
        report_result = success
    except Exception as e:
        report_results = [
            header("Report %s failed to process with error %s" %
                   (report_config.title, e))
        ]
        report_result = failure
    try:
        parsed_report = parse_report_results(report_results)
    except Exception as e:
        parsed_report = "Report failed to parse %s with error %s\n" % (
            report_config.title,
            str(e),
        )
        report_result = failure

    # We either print or email
    if report_config.output is "console":
        print(parsed_report)
    elif report_config.output is "email":
        send_production_mail_msg(data,
                                 parsed_report,
                                 subject=report_config.title,
                                 report=True)

    return report_result
Пример #6
0
 def email_user(self, log_entry):
     data = self.data
     try:
         send_production_mail_msg(data, str(log_entry), "*CRITICAL ERROR*")
     except BaseException:
         self.error("Couldn't email user")