def control_in_p(self, bar): try: for k in self.spread_dict.keys(): s0 = self.spread_dict[k][0] s1 = self.spread_dict[k][1] if s0 not in self.got_dict or s1 not in self.got_dict: continue if self.got_dict[s0] and self.got_dict[ s1] and self.process_dict[k] == False: self.process_dict[k] = True s0 = self.signalDict[s0][0] s1 = self.signalDict[s1][0] bar_s = VtBarData() bar_s.vtSymbol = k bar_s.symbol = k bar_s.exchange = s0.bar.exchange bar_s.date = s0.bar.date bar_s.time = s0.bar.time bar_s.close = s0.bar.close - s1.bar.close bar_s.AskPrice = s0.bar.AskPrice - s1.bar.BidPrice bar_s.BidPrice = s0.bar.BidPrice - s1.bar.AskPrice # print(bar_s.time, bar_s.vtSymbol, bar_s.close, bar_s.AskPrice, bar_s.BidPrice) self.engine.lock.acquire() self.engine.bar_list.append(bar_s) self.engine.lock.release() except Exception as e: s = traceback.format_exc() to_log(s)
def bar_listen_service(self): print('bar_listen_svervice 线程开始工作') server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(('localhost', SOCKET_BAR)) server.listen(5) while True: try: conn, addr = server.accept() b = conn.recv(10240) s = str(b, encoding='utf-8') # print( 'recive:', len(s) ) conn.close() d = eval(s) if d['vtSymbol'] in self.vtSymbol_list: bar = VtBarData() bar.__dict__ = d bar.close = float( 'nan' ) if bar.close == sys.float_info.max else bar.close bar.AskPrice = float( 'nan' ) if bar.AskPrice == sys.float_info.max else bar.AskPrice # if bar.AskPrice != bar.AskPrice: # print(bar.AskPrice) bar.BidPrice = float( 'nan' ) if bar.BidPrice == sys.float_info.max else bar.BidPrice # if np.isnan(bar.BidPrice): # print(bar.BidPrice) self.lock.acquire() self.bar_list.append(bar) self.lock.release() else: pass except Exception as e: print('error ') r = traceback.format_exc() to_log(r)
def control_in_p(self, bar): try: for k in self.spread_dict.keys(): s0 = self.spread_dict[k][0] s1 = self.spread_dict[k][1] if s0 not in self.got_dict or s1 not in self.got_dict: continue if self.got_dict[s0] and self.got_dict[ s1] and self.process_dict[k] == False: self.process_dict[k] = True s0 = self.bar_dict[s0] s1 = self.bar_dict[s1] bar_s = VtBarData() bar_s.vtSymbol = k bar_s.symbol = k bar_s.exchange = s0.exchange bar_s.date = s0.date bar_s.time = s0.time bar_s.close = s0.close - s1.close bar_s.AskPrice = s0.AskPrice - s1.BidPrice bar_s.BidPrice = s0.BidPrice - s1.AskPrice # print(bar_s.time, bar_s.vtSymbol, bar_s.close, bar_s.AskPrice, bar_s.BidPrice) df = pd.DataFrame([bar_s.__dict__]) cols = [ 'date', 'time', 'open', 'high', 'low', 'close', 'volume' ] df = df[cols] fname = get_dss() + 'fut/bar/min1_' + k + '.csv' if os.path.exists(fname): df.to_csv(fname, index=False, mode='a', header=False) else: df.to_csv(fname, index=False, mode='a') return bar_s except Exception as e: s = traceback.format_exc() to_log(s) return None