except KeyboardInterrupt: print 'Interrupted with Ctrl-c' logger.close() tws.disconnect() print 'All done' #--------------main script------------------ if __name__ == '__main__': #-----------parse command line arguments parser = argparse.ArgumentParser( description='Log ticks for a set of stocks') parser.add_argument("symbols", help='symbols separated by coma: SPY,VXX') parser.add_argument("-v", "--verbose", help="show all incoming messages", action="store_true") args = parser.parse_args() symbols = args.symbols.strip().split(',') print 'Logging ticks for:', symbols contracts = [createContract(symbol) for symbol in symbols] logTicks(contracts, verbose=args.verbose)
print 'Interrupted with Ctrl-c' logger.close() tws.disconnect() print 'All done' #--------------main script------------------ if __name__ == '__main__': #-----------parse command line arguments parser = argparse.ArgumentParser(description='Log ticks for a set of stocks') parser.add_argument("symbols",help = 'symbols separated by coma: SPY,VXX') parser.add_argument("-v", "--verbose", help="show all incoming messages", action="store_true") args = parser.parse_args() symbols = args.symbols.strip().split(',') print 'Logging ticks for:',symbols contracts = [createContract(symbol) for symbol in symbols] logTicks(contracts, verbose=args.verbose)
''' return number of requests in past timespan (s) ''' delta = dt.timedelta(seconds=timeSpan) now = dt.datetime.now() requests = 0 with open(self.dataFile,'r') as f: lines = f.readlines() for line in lines: if now-dt.datetime.strptime(line.strip(),self._timeFormat) < delta: requests+=1 if requests==0: # erase all contents if no requests are relevant open(self.dataFile,'w').close() self._log.debug('past requests: {0}'.format(requests)) return requests if __name__ == '__main__': from extra import createContract dl = Downloader(debug=True) # historic data downloader class contract = createContract('SPY') # create contract using defaults (STK,SMART,USD) data = dl.requestData(contract,"20141208 16:00:00 EST") # request 30-second data bars up till now data.to_csv('SPY.csv') # write data to csv print('Done')
with open(self.dataFile, 'r') as f: lines = f.readlines() for line in lines: if now - dt.datetime.strptime(line.strip(), self._timeFormat) < delta: requests += 1 if requests == 0: # erase all contents if no requests are relevant open(self.dataFile, 'w').close() self._log.debug('past requests: {0}'.format(requests)) return requests if __name__ == '__main__': from extra import createContract dl = Downloader(debug=True) # historic data downloader class contract = createContract( 'SPY') # create contract using defaults (STK,SMART,USD) data = dl.requestData( contract, "20141208 16:00:00 EST") # request 30-second data bars up till now data.to_csv('SPY.csv') # write data to csv print 'Done'