def create_histprcdat_req(requestID, symbol, exchange, record_interval, start=0, end=0, max=0): data_req = Dtc.HistoricalPriceDataRequest() data_req.RequestID = requestID # Note: Make sure this is unique when requesting multiple symbols data_req.Symbol = symbol data_req.Exchange = exchange data_req.RecordInterval = record_interval data_req.StartDateTime = start data_req.EndDateTime = end data_req.MaxDaysToReturn = max return data_req
def history(requestID, symbol, exchange, record_interval, sock, logfile, start=0, end=0, max=0): """Retrieve Historical data direct from DTC""" # custom logger with own txt file logRec = create_logger(logfile) # Create Historical Data Request data_req = Dtc.HistoricalPriceDataRequest() data_req.RequestID = requestID # Note: Make sure this is unique when requesting multiple symbols data_req.Symbol = symbol data_req.Exchange = exchange data_req.RecordInterval = record_interval data_req.StartDateTime = start data_req.EndDateTime = end data_req.MaxDaysToReturn = max # Send Request and log Response_Header send_message(data_req, Dtc.HISTORICAL_PRICE_DATA_REQUEST, sock) m_type, m_resp = get_message(sock) logRec.debug("%s, %s", m_type[0], m_resp) logStdout.debug("%s, %s", m_type[0], m_resp) # Get the rest/whole of the historical data while True: mt, mr = get_message(sock) mr1 = chekker2(mr) logRec.debug("%s, %s", mt[0], mr1) logStdout.debug("%s, %s", mt[0], mr1) if mt[0] == 'HISTORICAL_PRICE_DATA_RECORD_RESPONSE' and mr.IsFinalRecord: logStdout.info('FINISH') break quit(sock)