def get_factors(current_date, exchange_symbols):
    global conversion_factor
    global price
    products = [exchange_symbol[:-3] + "_1" for exchange_symbol in exchange_symbols]
    (csidb, csidb_cursor) = db_connect()
    _format_strings = ",".join(["%s"] * len(products))
    csidb_cursor.execute(
        "SELECT product,conversion_factor FROM products WHERE product IN (%s)" % _format_strings, tuple(products)
    )
    rows = csidb_cursor.fetchall()
    for row in rows:
        conversion_factor[row["product"][:-2]] = float(row["conversion_factor"])
    price = fetch_latest_prices_v1(exchange_symbols, current_date, "future")  # Uses exchange symbols
def get_factors(current_date, exchange_symbols):
    global conversion_factor
    global price
    products = [
        exchange_symbol[:-3] + '_1' for exchange_symbol in exchange_symbols
    ]
    (csidb, csidb_cursor) = db_connect()
    _format_strings = ','.join(['%s'] * len(products))
    csidb_cursor.execute(
        "SELECT product,conversion_factor FROM products WHERE product IN (%s)"
        % _format_strings, tuple(products))
    rows = csidb_cursor.fetchall()
    for row in rows:
        conversion_factor[row['product'][:-2]] = float(
            row['conversion_factor'])
    price = fetch_latest_prices_v1(exchange_symbols, current_date,
                                   'future')  # Uses exchange symbols
def get_factors(current_date, data_source, exchange_symbols, product_type,
                wedbush_db_cursor):
    prices = {}
    conversion_factor = {}
    products = [
        exchange_symbol[:-3] + '_1' for exchange_symbol in exchange_symbols
    ]
    (csidb, csidb_cursor) = db_connect()
    _format_strings = ','.join(['%s'] * len(products))
    csidb_cursor.execute(
        "SELECT product,conversion_factor FROM products WHERE product IN (%s)"
        % _format_strings, tuple(products))
    rows = csidb_cursor.fetchall()
    for row in rows:
        conversion_factor[row['product'][:-2]] = float(
            row['conversion_factor'])

    # If data source is CSI get prices and factors from db
    if data_source == 'csi':
        new_symbols = []
        for i in range(len(exchange_symbols)):
            basename = exchange_symbols[i][:-3]
            if basename == "ES":  # For ES we want to use SP prices
                new_symbols.append('SP' + exchange_symbols[i][-3:])
            else:
                new_symbols.append(exchange_symbols[i])
        #conversion_factor, currency_factor = get_latest_currency_and_conversion_factors_v1(basenames, curr_date_str, product_type)
        prices = fetch_latest_prices_v1(new_symbols, current_date,
                                        product_type)  # Uses exchange symbols
        for key in prices.keys():
            if key[:-3] == "SP":
                prices['ES' + key[-3:]] = prices[key]

    elif data_source == 'wedbush':
        _format_strings = ','.join(['%s'] * len(exchange_symbols))
        query = "SELECT product, broker_close_price FROM positions WHERE product IN (%s) and date = '%s'" % (
            _format_strings, current_date.strftime("%Y-%m-%d"))
        wedbush_db_cursor.execute(query, tuple(exchange_symbols))
        rows = wedbush_db_cursor.fetchall()
        for row in rows:
            prices[row['product']] = float(row['broker_close_price'])
    return prices, conversion_factor
def get_factors(current_date, data_source, exchange_symbols, product_type, wedbush_db_cursor):
    prices = {}
    conversion_factor = {}
    products = [exchange_symbol[:-3] + "_1" for exchange_symbol in exchange_symbols]
    (csidb, csidb_cursor) = db_connect()
    _format_strings = ",".join(["%s"] * len(products))
    csidb_cursor.execute(
        "SELECT product,conversion_factor FROM products WHERE product IN (%s)" % _format_strings, tuple(products)
    )
    rows = csidb_cursor.fetchall()
    for row in rows:
        conversion_factor[row["product"][:-2]] = float(row["conversion_factor"])

    # If data source is CSI get prices and factors from db
    if data_source == "csi":
        new_symbols = []
        for i in range(len(exchange_symbols)):
            basename = exchange_symbols[i][:-3]
            if basename == "ES":  # For ES we want to use SP prices
                new_symbols.append("SP" + exchange_symbols[i][-3:])
            else:
                new_symbols.append(exchange_symbols[i])
        # conversion_factor, currency_factor = get_latest_currency_and_conversion_factors_v1(basenames, curr_date_str, product_type)
        prices = fetch_latest_prices_v1(new_symbols, current_date, product_type)  # Uses exchange symbols
        for key in prices.keys():
            if key[:-3] == "SP":
                prices["ES" + key[-3:]] = prices[key]

    elif data_source == "wedbush":
        _format_strings = ",".join(["%s"] * len(exchange_symbols))
        query = "SELECT product, broker_close_price FROM positions WHERE product IN (%s) and date = '%s'" % (
            _format_strings,
            current_date.strftime("%Y-%m-%d"),
        )
        wedbush_db_cursor.execute(query, tuple(exchange_symbols))
        rows = wedbush_db_cursor.fetchall()
        for row in rows:
            prices[row["product"]] = float(row["broker_close_price"])
    return prices, conversion_factor