Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Fetch list of symbols after market open

Hi,

I would like to fetch a list of symbols from an external source soon after the market opens (daily) and then perform trades on those symbols during the day. Is it possible to do?

Thanks for you help.

7 responses

Hi Guarav,

Unfortunately this isn't possible on Quantopian. You can use Fetcher to import data to a live algorithm, but input for a given day needs to be added before midnight of the previous night. Is there some type of data missing on Q that you are using to determine this list? On top of the pricing and fundamentals data, there are 42+ other datasets available to play with!

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.

The data I am fetching is a list of top gainers during market open hours.

Have you tried using the Pipeline API to determine these? With Pipeline, you can rank securities by custom factors and pick the top gainers this way. Check out this example as a starting point.

Thanks Jamie, let me try that out as see if I am able to replicate the Yahoo top gainers list.

It works! Now I don't have to rely on my remote fetcher and can backtest my stuff.

can you share the code?

Sure (there is a problem with USEquityPricing.open in the current release, so I am using USEquityPricing.high right now):

from quantopian.algorithm import attach_pipeline, pipeline_output  
from quantopian.pipeline import Pipeline  
from quantopian.pipeline import CustomFactor  
from quantopian.pipeline.data.builtin import USEquityPricing

# Create custom factor #2 Price of current day / Price of 60 days ago.  
class PctGain(CustomFactor):  
    # Pre-declare inputs and window_length  
    inputs = [USEquityPricing.close, USEquityPricing.high]  
    window_length = 2  
    # Compute factor2 value  
    def compute(self, today, assets, out, close, high):  
        out[:] = (high[0] - close[1]) * 100 / close[1]

def initialize(context):  
    # Create and attach an empty Pipeline.  
    pipe = Pipeline()  
    pipe = attach_pipeline(pipe, name='ranked_pct_gainers')  
    pct_gain = PctGain()  
    pipe.add(pct_gain, 'pct_gain')  
    pct_gain_rank = pct_gain.rank()  
    pipe.add(pct_gain_rank, 'pct_gain_rank')  
    context.order_size = 1

def before_trading_start(context, data):  
    # Access results using the name passed to `attach_pipeline`.  
    results = pipeline_output('ranked_pct_gainers')  
    top_gainers = results.sort(['pct_gain_rank'], ascending=False)  
    # print top_gainers.head(19)

    # Define a universe with the results of a Pipeline.  
    # Take the first ten assets by Percent gain.  
    update_universe(top_gainers.index[:100])


# This function is run once per bar, REQUIRED  
def handle_data(context, data):  
    for stock in data:  
        log.info(stock.symbol)