def lineReceived(self, line): # print("receive:", line) pd = json.loads(line.decode("utf-8")) if "instrument" in pd: # 忽略非行情消息(如登录消息,是否登录成功) symbol = pd["instrument"] if symbol in tick_event: # 如果注册了这个品种的数据事件 if symbol in self.__tict_bar: bar = self.__tict_bar[symbol] if pd["ctime"] - bar["ctime"] >= tick_peroid: tick = Tick(symbol) tick.highPrice = bar["high"] tick.lowPrice = bar["low"] tick.openPrice = bar["open"] tick.lastPrice = bar["close"] tick.time = pd["ctime"] tick.time_msc = tick_peroid tick_event[symbol](tick) del self.__tict_bar[symbol] else: price = (pd["ask"] + pd["bid"]) / 2 bar["close"] = price if price < bar["low"]: bar["low"] = price if price > bar["high"]: bar["high"] = price else: price = (pd["ask"] + pd["bid"]) / 2 self.__tict_bar[symbol] = {"ctime": pd["ctime"], "open": price, "low": price, "high": price, "close": price} if line == self.end: self.transport.loseConnection()
def lineReceived(self, line): # print("receive:", line) pd = json.loads(line.decode("utf-8")) if "instrument" in pd: # 忽略非行情消息(如登录消息,是否登录成功) symbol = pd["instrument"].replace('/', '') if symbol in self._tick_event: # 如果注册了这个品种的数据事件 tick = Tick(symbol) price = (pd['ask'] + pd['bid']) / 2 tick.highPrice = price tick.lowPrice = price tick.openPrice = price tick.lastPrice = price tick.time = pd["ctime"] self._tick_event[symbol](tick) if line == self.end: self.transport.loseConnection()
def lineReceived(self, line): # print("receive:", line) pd = json.loads(line.decode("utf-8")) if "instrument" in pd: # 忽略非行情消息(如登录消息,是否登录成功) symbol = pd["instrument"] if symbol in tick_event: # 如果注册了这个品种的数据事件 if symbol in self.__tict_bar: bar = self.__tict_bar[symbol] if pd["ctime"] - bar["ctime"] >= tick_peroid: tick = Tick(symbol) tick.highPrice = bar["high"] tick.lowPrice = bar["low"] tick.openPrice = bar["open"] tick.lastPrice = bar["close"] tick.time = pd["ctime"] tick.time_msc = tick_peroid tick_event[symbol](tick) del self.__tict_bar[symbol] else: price = (pd["ask"] + pd["bid"]) / 2 bar["close"] = price if price < bar["low"]: bar["low"] = price if price > bar["high"]: bar["high"] = price else: price = (pd["ask"] + pd["bid"]) / 2 self.__tict_bar[symbol] = { "ctime": pd["ctime"], "open": price, "low": price, "high": price, "close": price } if line == self.end: self.transport.loseConnection()