Exemplo n.º 1
0
 def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, 
                 count):
     msg = EWrapperMsgGenerator.realtimeBar(reqId, time, open_, high, low, 
                                            close, volume, wap, count)
     timestamp = timemod.strftime('%Y%m%d %H:%M:%S', 
                                  timemod.localtime(time))
     if not args.port:
         print >> sys.stderr, msg
     else:
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         sock.connect((args.host, args.port))
         sock.sendall('%s,%s,%s,0 %s\n' % (args.database, 
                                           args.schema, 
                                           fnames[reqId], 
                                           msg.replace(str(time), 
                                                       timestamp)))
         sock.close()
Exemplo n.º 2
0
    def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, 
                    count):
        for reversal in self.req_to_rev[reqId]:
            rev_id, pos = reversal
            self.rev_to_data[rev_id][pos] = (close, time)
            data = self.rev_to_data[rev_id]
            self.logger.debug('Processing %s: %s', str(reversal), str(data))
            times = [x[1] for x in data]
            if times[0] == times[1] == times[2]: 
                prices = [x[0] for x in data]
                self.evaluate_and_enter_reversal(rev_id, prices)

        msg = EWrapperMsgGenerator.realtimeBar(reqId, time, open_, high, low, 
                                               close, volume, wap, count)
        fnm = '%i_%s.csv' % (self.realtime_bars[reqId]['contract'].m_conId,
                             self.realtime_bars[reqId]['show'])
        self.datahandler(fnm, reqId, msg)
Exemplo n.º 3
0
    def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, 
                    count):
        msg = EWrapperMsgGenerator.realtimeBar(reqId, time, open_, high, low, 
                                               close, volume, wap, count)
        timestamp = timemod.strftime('%Y%m%d %H:%M:%S', 
                                     timemod.localtime(time))

        strike, right, show = self.show_req[reqId]        
        self.bars[(strike, right, show)] = (timestamp, open_, high, low, close, 
                                            volume, wap, count)

        if strike == -1 and show == 'TRADES':
            self.gen_strikes(close, self.interval)

        self.l = [self.bars[x][0] for x in self.show_req.values()]
        if self.l.count(timestamp) + self.l.count(None) == len(self.l):
            try:
                flies = self.compute_fly_prices()

                try:                
                    spot = self.bars[(-1, None, 'TRADES')]\
                           + (self.bars[(-1, None, 'BID')][4], 
                              self.bars[(-1, None, 'ASK')][4])
                except IndexError:
                    spot = self.bars[(-1, None, 'TRADES')] + (None, None)
                row = ['underlying=%s' % c.symbol, 'interval=%f' % c.interval]
                for field, data in zip(self.FIELDS, spot + flies):
                    row += ['%s=%s' % (field, str(data))]
                if not c.port:
                    for datapoint in row:
                        print datapoint
                else:
                    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                    sock.connect((c.host, c.port))
                    sock.sendall('%s,%s,%s,%s\n' % (c.database, 
                                                    c.schema, 
                                                    c.tablename, 
                                                    ','.join(row)))
                    sock.close()
            except KeyError, err:
                self.logger.warn('Realtime bars (%f, %s, %s) not started yet', 
                                 *err.args[0])
                pass
Exemplo n.º 4
0
Arquivo: client.py Projeto: gazzman/ib
 def realtimeBar(self, reqId, time, open_, high, low, close, volume, wap, 
                 count):
     msg = EWrapperMsgGenerator.realtimeBar(reqId, time, open_, high, low, 
                                            close, volume, wap, count)
     self.datahandler(reqId, msg)