Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Hacking-google-finance-in-pre-market-trading

Here's the code...

import urllib2 # works fine with Python 2.7.9 (not 3.4.+)
import json
import time

def fetchPreMarket(symbol, exchange):
link = "http://finance.google.com/finance/info?client=ig&q="
url = link+"%s:%s" % (exchange, symbol)
u = urllib2.urlopen(url)
content = u.read()
data = json.loads(content[3:])
info = data[0]
t = str(info["elt"]) # time stamp
l = float(info["l"]) # close price (previous trading day)
p = float(info["el"]) # stock price in pre-market (after-hours)
return (t,l,p)

p0 = 0
while True:
t, l, p = fetchPreMarket("AAPL","NASDAQ")
if(p!=p0):
p0 = p
print("%s\t%.2f\t%.2f\t%+.2f\t%+.2f%%" % (t, l, p, p-l,
(p/l-1)*100.))
time.sleep(60)

it returns an error... wat am I missing....?? anyone.. tnxs for the help in advance...

--- Error InvalidSidCount: 0019 Algorithm must reference 1-500 SIDs. Found 0

6 responses

A SID is a security id, a unique number to track a stock over time through mergers and acquisitions: https://www.quantopian.com/help#ide-sid-lookup

To run a backtest, you need to specify which securities your algo is trading.

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.

John, I'm having trouble understanding how the error you quote above, which is a Quantopian error, could arise from running the code shown above, which could not possibly run on Quantopian. The code above has no initialize or handle_data function, and it uses several things that are not allowed on Quantopian, including urllib2 and time.sleep.

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.

Jonathan.. I got the code.. from this link... http://www.quantatrisk.com/2015/05/07/hacking-google-finance-in-pre-market-trading-python/ the author is Pawel Lachowicz, PhD, MSc. He even has a code for hacking real time not pre-maket http://www.quantatrisk.com/2014/01/14/hacking-google-finance-in-real-time-for-algorithmic-traders/ However... maybe... there are members here... in the community who can... replicate or... make it work in quantopian as equivalent/ same functions... ;)

John, you didn't really answer my question or get my point.

In your posting, you said, "Here's the code..." and then some code, and then, "it returns an error..." and then an error, implying that the code you posted produced the error you posted.

But that's impossible, since that code could never have run on Quantopian.

How can people help you figure out the problem with your code if you don't post the actual code?

not sure Jonathan... if these... are supported in quantopian... in the first place
import urllib2 # works fine with Python 2.7.9 (not 3.4.+)
import json
import time

However... if we can.. replicate the hacking idea in the link as being suggested by Pawel Lachowicz then... it would be wonderful.... since the code in those links are all in pythons... ;)

John the FAQ regarding whitelisted modules. https://www.quantopian.com/faq#writing

Modules such as urllib2 and json are not supported on Quantopian and cannot be used on Quantopian.

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.