Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Iterating Data Issue

Hey guys, so after I set up my algo to fetch and parse a CSV I have set up, it seems I am unable to iterate "data" when attempting to go live. Any suggestions on how to combat this issue?

import datetime  
import pandas as pd  
import numpy as np  
import talib  
import math  
def my_universe(context, fetcher_data):  
    my_stocks = set(fetcher_data['sid'])  
    context.count = len(my_stocks)  
    return my_stocks

# see a snapshot of your CSV for debugging  
def preview(df):  
    log.info(' %s ' % df.head())  
    return df

def initialize(context):  
    log.info("starting")  
    set_long_only()  
    context.money = context.portfolio.cash  
    # import the custom CSV data file  
    fetch_csv("http://54.183.4.219/api/equities_test.csv",  
              pre_func=preview,  
              post_func=preview,  
              date_column='start_date',  
              universe_func=(my_universe))  
    schedule_function(portfolio_buy,date_rules.every_day(), time_rules.market_open(hours=0,minutes=5))  

def portfolio_buy(context, data):  
    for sec in data:  
        order_value(sec, 10000)  
def handle_data(context,data):  
    print('handling data')  
    pass  
2 responses

Hi Ryan,

It seems you may be trying to use an old version of the API by iterating over data. Back in April, we upgraded to Quantopian 2. The new way to iterate over the securities in your fetcher file is by iterating over data.fetcher_assets.

There's a migration page to help with the transition from the old to the new API that includes a fetcher example, I'd recommend checking it out!

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Thanks Jamie,

That definitely fixed my issue. I appreciate your help!