def __init__(self): self._log = logger.getLogger('TK') dataDir = os.path.expanduser('~') + '/twpData' if not os.path.exists(dataDir): os.mkdir(dataDir) self._timeFormat = "%Y%m%d %H:%M:%S" self.dataFile = os.path.normpath(os.path.join(dataDir, 'requests.txt')) self._log.debug('Data file: {0}'.format(self.dataFile))
def __init__(self): self._log = logger.getLogger('TK') dataDir = os.path.expanduser('~')+'/twpData' if not os.path.exists(dataDir): os.mkdir(dataDir) self._timeFormat = "%Y%m%d %H:%M:%S" self.dataFile = os.path.normpath(os.path.join(dataDir,'requests.txt')) self._log.debug('Data file: {0}'.format(self.dataFile))
def __init__(self, name = "broker"): super(Broker,self).__init__() self.name = name self.log = logger.getLogger(self.name) self.log.debug('Initializing broker. Pandas version={0}'.format(pandas.__version__)) self.contracts = {} # a dict to keep track of subscribed contracts self._id2symbol = {} # id-> symbol dict self.tws = None self._nextId = 1 # tws subscription id self.nextValidOrderId = None
def __init__(self, name="broker"): super(Broker, self).__init__() self.name = name self.log = logger.getLogger(self.name) self.log.debug('Initializing broker. Pandas version={0}'.format( pandas.__version__)) self.contracts = {} # a dict to keep track of subscribed contracts self._id2symbol = {} # id-> symbol dict self.tws = None self._nextId = 1 # tws subscription id self.nextValidOrderId = None
def __init__(self,debug=False): self._log = logger.getLogger('DLD') self._log.debug('Initializing data dwonloader. Pandas version={0}, ibpy version:{1}'.format(pandas.__version__,ib.version)) self.tws = ibConnection() self._dataHandler = DataHandler(self.tws) if debug: self.tws.registerAll(self._debugHandler) self.tws.unregister(self._debugHandler,message.historicalData) self._log.debug('Connecting to tws') self.tws.connect() self._timeKeeper = TimeKeeper() # keep track of past requests self._reqId = 1 # current request id
def __init__(self, debug=False): self._log = logger.getLogger('DLD') self._log.debug( 'Initializing data dwonloader. Pandas version={0}, ibpy version:{1}' .format(pandas.__version__, ib.version)) self.tws = ibConnection() self._dataHandler = DataHandler(self.tws) if debug: self.tws.registerAll(self._debugHandler) self.tws.unregister(self._debugHandler, message.HistoricalData) self._log.debug('Connecting to tws') self.tws.connect() self._timeKeeper = TimeKeeper() # keep track of past requests self._reqId = 1 # current request id
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 .helpers import createContract from tradingWithPython.lib import logger log = logger.getLogger("main", logFile="downloader.log") dl = Downloader(debug=False) # historic data downloader class contract = createContract( "SPY") # create contract using defaults (STK,SMART,USD) data = dl.requestData( contract, "20161005 16:00:00 EST") # request 30-second data bars up till now data.to_csv("SPY.csv") # write data to csv print("Done")
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 helpers import createContract from tradingWithPython.lib import logger log = logger.getLogger('main', logFile='downloader.log') dl = Downloader(debug=False) # historic data downloader class contract = createContract( 'SPY') # create contract using defaults (STK,SMART,USD) data = dl.requestData( contract, "20161005 16:00:00 EST") # request 30-second data bars up till now data.to_csv('SPY.csv') # write data to csv print('Done')
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 helpers import createContract from tradingWithPython.lib import logger log = logger.getLogger('main',logFile='downloader.log') dl = Downloader(debug=False) # historic data downloader class contract = createContract('SPY') # create contract using defaults (STK,SMART,USD) data = dl.requestData(contract,"20161005 16:00:00 EST") # request 30-second data bars up till now data.to_csv('SPY.csv') # write data to csv print('Done')
def __init__(self, tws): self._log = logger.getLogger('DH') tws.register(self.msgHandler, message.HistoricalData) self.reset()
def __init__(self): self.listeners = {} self.logger = logger.getLogger()
from tradingWithPython.lib.csvDatabase import HistDataCsv from tradingWithPython.lib.interactiveBrokers.helpers import createContract from tradingWithPython.lib.interactiveBrokers.histData import Downloader import tradingWithPython.lib.yahooFinance as yf from tradingWithPython.lib import logger import logging import argparse import pandas as pd import os import time import datetime import yaml log = logger.getLogger('main', logFile='downloader.log', consoleLevel=logging.DEBUG) def errorLogger(msg): if msg.typeName == 'error': log.error(str(msg)) def str2time(s): return datetime.datetime.strptime(s, "%Y%m%d %H:%M:%S") def time2str(ts): return ts.strftime("%Y%m%d %H:%M:%S")
def __init__(self,tws): self._log = logger.getLogger('DH') tws.register(self.msgHandler,message.historicalData) self.reset()
from tradingWithPython.lib.csvDatabase import HistDataCsv from tradingWithPython.lib.interactiveBrokers.helpers import createContract from tradingWithPython.lib.interactiveBrokers.histData import Downloader import tradingWithPython.lib.yahooFinance as yf from tradingWithPython.lib import logger import logging import argparse import pandas as pd import os import time import datetime import yaml log = logger.getLogger("main", logFile="downloader.log", consoleLevel=logging.DEBUG) def errorLogger(msg): if msg.typeName == "error": log.error(str(msg)) def str2time(s): return datetime.datetime.strptime(s, "%Y%m%d %H:%M:%S") def time2str(ts): return ts.strftime("%Y%m%d %H:%M:%S")