Example #1
0
def purchase_stock(stock_name, quantity):
   price = markit_api.get_quote(stock_name)
   if price != -1.0: # Add in the items
        if owned_stocks.has_key(stock_name):
            owned_stocks[stock_name] += quantity
        else:
            owned_stocks[stock_name] = quantity
        cash -= quantity * price
        return quantity * price
   else: # Couldn't resolve purchase
        return -1
Example #2
0
__author__ = 'williamsb'

import markit_api
from urllib2 import Request, urlopen, URLError

# http://www.batstrading.com/market_data/symbol_listing/
# This lists all of the symbols traded on the BATS exchange

# Initialize all of the available stocks for trading
request = Request('http://www.batstrading.com/market_data/symbol_listing/csv/')

try:
    print "Attempting to download stocks"
    response = urlopen(request)
    stocks = response.read().split()
    print "Downloaded CSV of all stock symbols"

except URLError, e:
    print "Can't get csv from BATS ", e
    exit()

stock_prices = {}

for stock in stocks:
    price = markit_api.get_quote(stock)
    if price != -1:
        stock_prices[stock] = price
        print stock, stock_prices[stock]