示例#1
0
 def _save_day(self, contract_name, day):
     if day.sdate == 0:
         logging.info('当日数据为空:%s' % contract_name)
         return
     sformat = DAY_FORMAT % {
         'flen': self._cbuffer[contract_name].contract.ctype.flen
     }
     logging.info('保存日数据:%s' % contract_name)
     cpath = '%s/%s' % (self.relative_path, contract_name)
     check_path(cpath)
     with open('%s/days.csv' % (cpath, ), 'at') as mf:
         mf.write(sformat.format(day))
         #mf.write('%(sdate)d,%(sopen)d,%(shigh)d,%(slow)d,%(sclose)d,%(svolume)d,%(sholding)d\n' % day.__dict__)
     logging.info('保存日数据完毕:%s' % contract_name)
示例#2
0
 def __init__(self, contract_manager, relative_path):
     ManagedAgent.__init__(self, contract_manager)
     self._cbuffer = {}
     self._error_ticks = {}
     self._reset_cbuffer()
     #self.stwaste = 0
     #self.nt = 0
     self.relative_path = relative_path[:-1] if (
         relative_path[-1] == '/'
         or relative_path[-1] == os.sep) else relative_path
     if not os.path.isdir(self.relative_path):
         os.makedirs(self.relative_path)
     for contract in self._contract_manager.current_contracts():
         cpath = '%s/%s' % (self.relative_path, contract.name)
         check_path(cpath)
         #if not os.path.isdir(cpath):
         #    os.makedirs(cpath)
     print('SaveAgent initialized')
示例#3
0
 def _save_minute1(self, contract_name, minute):
     b = time.time()
     sformat = MINUTE_FORMAT % {
         'flen': self._cbuffer[contract_name].contract.ctype.flen
     }
     cpath = '%s/%s' % (self.relative_path, contract_name)
     check_path(cpath)
     with open('%s/minutes.csv' % (cpath, ), 'at') as mf:
         #if minute.svolume > 0:
         #mf.write('%(sdate)d,%(stime)d,%(sopen)d,%(shigh)d,%(slow)d,%(sclose)d,%(svolume)d,%(sholding)d\n' % minute.__dict__)
         if minute.svolume > 0:
             mf.write(sformat.format(minute))  #20141016,不保存svolume=0
             logging.debug('thread=%s,save minute %s, used:%s' % (
                 threading.current_thread().ident,
                 contract_name,
                 time.time() - b,
             ))
         else:
             logging.debug(
                 'thread=%s,svolume<=0,not save minute %s' %
                 (threading.current_thread().ident, contract_name))