Skip to content

Instantly share code, notes, and snippets.

Created June 5, 2017 12:17
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Import NASDAQ stocks from Quandl EOD data
import pymongo
from pymongo import MongoClient
import csv
import urllib2
import sys
import os.path
from datetime import datetime, timedelta
# Are we using development or Production ?
# uri = "mongodb://"
uri = 'mongodb://localhost:27017'
# Make sure unique index has been created
# db.candles.createIndex({ date: 1, ticker: 1 }, { unique: true })
client = MongoClient(uri)
db = client.fluid
candles = db.candles
# We don't need all candles from IPO to now - I'll start with the past few months
sixty_days_ago = - timedelta(days=60)
# Get the list of tickers from the companies collection
companies = db.companies.find()
for company in companies:
print("Getting " + company['Name'])
url = '' + str( + '&api_key=' + QUANDL_API_KEY + "&ticker=" + company['Symbol']
csvfile = urllib2.urlopen(url)
reader = csv.DictReader(csvfile, delimiter=',')
for line in reader:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment