Esempio n. 1
0
def list_assets():
    global ASSETS
    if not ASSETS:
        custom_asset_list = av_config.av.get("custom_asset_list")
        if custom_asset_list:
            custom_asset_list = custom_asset_list.strip().replace(
                " ", "").split(",")
            ASSETS = list(set(custom_asset_list))
        else:
            try:
                universe = Universe[av_config.av["universe"]]
            except:
                universe = Universe.ALL
            if universe == Universe.ALL:
                # alpha vantage doesn't define a universe. we could try using alpaca's universe if the
                # user defined credentials. if not, we will raise an exception.
                try:
                    import zipline.data.bundles.alpaca_api as alpaca
                    alpaca.initialize_client()
                    ASSETS = all_alpaca_assets(alpaca.CLIENT)
                except:
                    raise Exception(
                        "You tried to use Universe.ALL but you didn't define the alpaca credentials."
                    )
            elif universe == Universe.SP100:
                ASSETS = get_sp100()
            elif universe == Universe.SP500:
                ASSETS = get_sp500()
            elif universe == Universe.NASDAQ100:
                ASSETS = get_nasdaq100()
            ASSETS = list(set(ASSETS))
    return ASSETS
Esempio n. 2
0
def list_assets():
    global ASSETS
    with open("alpaca.yaml", mode='r') as f:
        o = yaml.safe_load(f)
        try:
            ASSETS = [
                str(asset).strip()
                for asset in o["custom_asset_list"].split(",")
            ]
            print(f"custom assets: {ASSETS}")
        except:
            ASSETS = None
        try:
            universe = Universe[o["universe"]]
        except:
            universe = Universe.ALL
    if not ASSETS:
        print(f"universe {ASSETS}")
        if universe == Universe.ALL:
            ASSETS = all_alpaca_assets(CLIENT)
        elif universe == Universe.SP100:
            ASSETS = get_sp100()
        elif universe == Universe.SP500:
            ASSETS = get_sp500()
        elif universe == Universe.NASDAQ100:
            ASSETS = get_nasdaq100()

    return list(set(ASSETS))
Esempio n. 3
0
def list_assets():
    global ASSETS
    if not ASSETS:
        with open("alpaca.yaml", mode='r') as f:
            o = yaml.safe_load(f)
            custom_asset_list = o.get("custom_asset_list")
            if custom_asset_list:
                custom_asset_list = custom_asset_list.strip().replace(
                    " ", "").split(",")
                ASSETS = list(set(custom_asset_list))
            else:
                try:
                    universe = Universe[o["universe"]]
                except:
                    universe = Universe.ALL
                if universe == Universe.ALL:
                    ASSETS = all_alpaca_assets(CLIENT)
                elif universe == Universe.SP100:
                    ASSETS = get_sp100()
                elif universe == Universe.SP500:
                    ASSETS = get_sp500()
                elif universe == Universe.NASDAQ100:
                    ASSETS = get_nasdaq100()
                ASSETS = list(set(ASSETS))
    return ASSETS
Esempio n. 4
0
def list_assets():
    global ASSETS
    if not ASSETS:
        conf = config.bundle.AlpacaConfig()
        custom_asset_list = conf.custom_asset_list
        if custom_asset_list:
            custom_asset_list = custom_asset_list.strip().replace(
                " ", "").split(",")
            ASSETS = list(set(custom_asset_list))
        else:
            try:
                universe = Universe[conf.universe]
            except:
                universe = Universe.ALL
            if universe == Universe.ALL:
                ASSETS = all_alpaca_assets(CLIENT)
            elif universe == Universe.SP100:
                ASSETS = get_sp100()
            elif universe == Universe.SP500:
                ASSETS = get_sp500()
            elif universe == Universe.NASDAQ100:
                ASSETS = get_nasdaq100()
            ASSETS = list(set(ASSETS))
        write_symbol_list(expandvars(conf.al['store_data_path']))
    return ASSETS
Esempio n. 5
0
def list_assets():
    with open("alpaca.yaml", mode='r') as f:
        o = yaml.safe_load(f)
        try:
            universe = Universe[o["universe"]]
        except:
            universe = Universe.ALL
    global ASSETS
    if not ASSETS:
        if universe == Universe.ALL:
            ASSETS = all_alpaca_assets(CLIENT)
        elif universe == Universe.SP100:
            ASSETS = get_sp100()
        elif universe == Universe.SP500:
            ASSETS = get_sp500()
        elif universe == Universe.NASDAQ100:
            ASSETS = get_nasdaq100()

    return list(set(ASSETS))
Esempio n. 6
0
def list_assets():
    global ASSETS
    if not ASSETS:
        conf = config.bundle.CustomCsvConfig()
        custom_asset_list = conf.custom_asset_list
        if custom_asset_list:
            custom_asset_list = custom_asset_list.strip().replace(" ", "").split(",")
            ASSETS = list(set(custom_asset_list))
        else:
            try:
                universe = Universe[conf.universe]
            except:
                universe = Universe.ALL
            if universe == Universe.ALL:
                filename = expandvars(conf.ccsv['input_asset_filename'])
                ASSETS = read_all_alpaca_assets(filename)
            elif universe == Universe.SP100:
                ASSETS = get_sp100()
            elif universe == Universe.SP500:
                ASSETS = get_sp500()
            elif universe == Universe.NASDAQ100:
                ASSETS = get_nasdaq100()
            ASSETS = list(set(ASSETS))
    return ASSETS