Beispiel #1
0
 def __init__(self, addr, auth, outdir, pidfile, errorfile, interval, itype,
              symbols):
     _Daemon.__init__(self, pidfile, stderr=errorfile)
     self._addr = addr
     self._auth = auth
     self._outdir = _path(outdir)
     self._interval = interval
     self._has_vol = 'V' in itype
     self._is_ohlc = 'OHLC' in itype
     self._symbols = symbols
     self._iobj = None
     # date prefix for filename
     dprfx = _strftime("%Y%m%d", _localtime())
     # generate paths from filenames
     self._paths = {s.upper() : (_path(self._outdir) + '/' + dprfx + '_' \
                                + s.replace('/','-S-').replace('$','-D-').replace('.','-P-') \
                                + '_' + itype + '_' + str(self._interval) + 'sec.tosdb') \
                                  for s in self._symbols}
     # create callback object
     if self._has_vol:
         self._callback = _ohlcv_callbacks._Matcher(
             'ohlc' if self._is_ohlc else 'c', self._write)
     else:
         l = (lambda o: str((o.o, o.h, o.l, o.c))) if self._is_ohlc else (
             lambda o: str(o.c))
         self._callback = _ohlcv_callbacks._Basic(l, self._write)
Beispiel #2
0
def spawn(dllroot,outdir,intrvl,val_type,*symbols):   
    if val_type not in ['OHLCV','OHLC','CV','C']:
        raise ValueError("invalid val_type (OHLCV,OHLC,CV or C)")

    exc_cmd = "from tosdb.intervalize import " + CLS_BASE + val_type + " as _Goti"
    exec(exc_cmd, globals())
    
    tosdb.init(root=dllroot)
    
    # create block
    blk = tosdb.TOSDB_DataBlock(BLOCK_SIZE, date_time=True)
    blk.add_items(*(symbols))
    blk.add_topics('last')
    if 'V' in val_type:
        blk.add_topics('volume')
        
    # generate filename          
    dprfx = _strftime("%Y%m%d", _localtime())
    isec = int(intrvl * 60)  
    iobjs = list()

    for s in symbols:
        #
        # create GetOnTimeInterval object for each symbol
        # 
        p = _path(outdir) + '/' + dprfx + '_' \
            + s.replace('/','-S-').replace('$','-D-').replace('.','-P-') \
            + '_' + val_type + '_' + str(intrvl) + 'min.tosdb'       
        iobj = _Goti.send_to_file(blk, s, p, getattr(_TI,_TI.val_dict[isec]), isec/10)
        print( repr(iobj) )
        iobjs.append( iobj )
    
    return iobjs
Beispiel #3
0
def spawn(dllroot,outdir,intrvl,val_type,*symbols):
   
    if val_type not in ['OHLCV','OHLC','CV','C']:
         raise ValueError("invalid val_type (OHLCV,OHLC,CV or C)")

    exec( "from tosdb.intervalize import " + CLS_BASE + val_type + " as _Goti",
          globals() )
    
    tosdb.init( root=dllroot )
    
    # create block
    blk = tosdb.TOSDB_DataBlock( BLOCK_SIZE, date_time=True)
    blk.add_items( *(symbols) )
    blk.add_topics( 'last' )
    if 'V' in val_type:
        blk.add_topics( 'volume' )
        
    # generate filename                
    dprfx = _strftime("%Y%m%d", _localtime())
    isec = int(intrvl * 60)    
    iobjs = list()
    for s in symbols:
        #
        # create GetOnTimeInterval object for each symbol
        # 
        p = _path(outdir) + '/' + dprfx + '_' + \
                s.replace('/','-S-').replace('$','-D-').replace('.','-P-') + \
                '_' + val_type + '_' + str(intrvl) + 'min.tosdb'           
        iobj = _Goti.send_to_file( blk, s, p, getattr(_TI,_TI.val_dict[ isec ]),
                                   isec/10)
        print( repr(iobj) )
        iobjs.append( iobj )
    
    return iobjs
Beispiel #4
0
 def __init__(self, addr, dll_root, out_dir, pid_file, error_file, 
              intrvl, symbols):
     _Daemon.__init__(self, pid_file, stderr = error_file)
     self._addr = addr
     self._dll_root = dll_root
     self._out_dir = _path(out_dir)
     self._intrvl = intrvl
     self._symbols = symbols
     self._iobjs = list()
Beispiel #5
0
 def __init__(self, addr, dll_root, out_dir, pid_file, error_file, intrvl,
              symbols):
     _Daemon.__init__(self, pid_file, stderr=error_file)
     self._addr = addr
     self._dll_root = dll_root
     self._out_dir = _path(out_dir)
     self._intrvl = intrvl
     self._symbols = symbols
     self._iobjs = list()
Beispiel #6
0
 def __init__(self, addr, auth, outdir, pidfile, errorfile, interval, itype, symbols):
     _Daemon.__init__(self, pidfile, stderr = errorfile)
     self._addr = addr    
     self._auth = auth
     self._outdir = _path(outdir)
     self._interval = interval
     self._has_vol = 'V' in itype
     self._is_ohlc = 'OHLC' in itype
     self._symbols = symbols   
     self._iobj = None     
     # date prefix for filename          
     dprfx = _strftime("%Y%m%d", _localtime())
     # generate paths from filenames
     self._paths = {s.upper() : (_path(self._outdir) + '/' + dprfx + '_' \
                                + s.replace('/','-S-').replace('$','-D-').replace('.','-P-') \
                                + '_' + itype + '_' + str(self._interval) + 'sec.tosdb') \
                                  for s in self._symbols}
     # create callback object
     if self._has_vol:            
         self._callback = _ohlcv_callbacks._Matcher('ohlc' if self._is_ohlc else 'c', self._write)
     else:
         l = (lambda o: str((o.o, o.h, o.l, o.c))) if self._is_ohlc else (lambda o: str(o.c))
         self._callback = _ohlcv_callbacks._Basic(l, self._write)       
Beispiel #7
0
def spawn(outdir, interval, is_ohlc, has_vol, *symbols):
    global _paths

    itype = ("OHLC" if is_ohlc else "C") + ("V" if has_vol else "")    
    # date prefix for filename                    
    dprfx = _strftime("%Y%m%d", _localtime())
    # generate paths from filenames
    _paths = {s.upper() : (_path(outdir) + '/' + dprfx + '_' \
                          + s.replace('/','-S-').replace('$','-D-').replace('.','-P-') \
                          + '_' + itype + '_' + str(interval) + 'sec.tosdb')
                          for s in symbols}  

    # create callback object
    if has_vol:
        callback = _ohlcv_callbacks._Matcher('ohlc' if is_ohlc else 'c', _write)
    else:
        l = (lambda o: str((o.o, o.h, o.l, o.c))) if is_ohlc else (lambda o: str(o.c))
        callback = _ohlcv_callbacks._Basic(l, _write)   
  
    # create block
    blk = tosdb.TOSDB_ThreadSafeDataBlock(BLOCK_SIZE, date_time=True)
    blk.add_items(*(symbols))
    blk.add_topics('last')        
    if has_vol:
        blk.add_topics('volume')  
     
    # create interval object
    IObj = OHLCIntervals if is_ohlc else CIntervals
    iobj = IObj(blk, interval, interval_cb=callback.callback)
    try:
        while iobj.running():
            _sleep(1)
    except:
        iobj.stop()
    finally:
        blk.close()