def print_line(text, fp=None): text = str(text) if fp: fp.write(current_datetime_string()) fp.write(text + '\n') fp.flush() print text
def record_signal(code, data, name=''): stbase.print_line(data, stdout=True) if name: name = name + '_' + code + '.signal' fname = stbase.TradeManager().getDataPath(name) data = current_datetime_string() + ' ' + data fp = open(fname, 'a+') # fp.writelines([data]) fp.write(data + '\n') fp.close()
def print_line(self, text, fp=None, stdout=True): text = str(text) if not fp: fp = self.logfile if fp: fp.write(current_datetime_string()) fp.write(' ') fp.write(text + '\n') fp.flush() if stdout: print text
def record_signal(self, code, data, name=''): print_line(data, stdout=True) if not name: name = self.strategy.name if name: name = name + '_' + code + '.signal' fname = self.getDataPath(name) data = current_datetime_string() + ' ' + data fp = open(fname, 'a+') # fp.writelines([data]) fp.write(data + '\n') fp.close()
def save_bar_data(self, ktype, bar, num): # 非交易时间段丢弃 f = open( '{}/{}-{}.txt'.format(TradeManager().logpath, self.code, ktype), 'a+') # data = hash_object(bar) data = dict(Open=bar.Open, High=bar.High, Low=bar.Low, Close=bar.Close, Vol=bar.Vol, Amount=bar.Amount, DateTime=bar.DateTime) print data data['bar_num'] = num # data = json.dumps(data) # f.write(data + '\n') # f.close() data = json.dumps(data) # 写入当前系统时间 TradeManager().save_data('#{}'.format(current_datetime_string()), f) TradeManager().save_data(data, f) f.close()