示例#1
0
    def data_handler(self, reqId, date, open_, high, low, close, volume, count, 
                     WAP, hasGaps=False):
        showbase = self.req_map[reqId]
        try:
            base = '%s_%s' % showbase
        except TypeError:
            base = showbase

        if self.port is None:
            msg = EWrapperMsgGenerator.historicalData(reqId, date, open_, high, 
                                                      low, close, volume, 
                                                      count, WAP, hasGaps)
            print self.mdata['underlying'], base, msg
        else:
            bar = [('open', open_), ('high', high), ('low', low), 
                   ('close', close), ('hasgaps', hasGaps)]
            if 'trade' in base:
                bar += [('volume', volume), ('count', count), ('wap', WAP)]
            data = self.mdatastring + ['timestamp=%s' % date]
            data += ['%s_%s=%s' % (base, name, data) for name, data in bar]

            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((self.host, self.port))
            sock.sendall('%s,%s\n' % (self.dbinfo, ','.join(data)))
            sock.close()
示例#2
0
文件: client.py 项目: gazzman/ib
 def historicalData(self, reqId, date, open_, high, low, close, volume, 
                    count, WAP, hasGaps):
     msg = EWrapperMsgGenerator.historicalData(reqId, date, open_, high, 
                                               low, close, volume, count, 
                                               WAP, hasGaps)
     self.datahandler(reqId, msg, date)