def feed_enQ_msg(self, msg): #print("Feed MSG: %s"%(json.dumps(msg, indent=4, sort_keys=True))) msg_type = msg.get('type') product_id = msg.get("product_id") if (msg_type == 'ticker'): if (product_id == None): log.error("Feed Thread: Invalid Product-id: %s" % (json.dumps(msg, indent=4, sort_keys=True))) return market = get_market_by_product(self.name, product_id) if (market == None): log.error("Feed Thread: Unknown market: %s" % (json.dumps(msg, indent=4, sort_keys=True))) return feed_enQ(market, msg) elif (msg_type == 'snapshot') or (msg_type == 'l2update'): if (product_id == None): log.error("Feed Thread: Invalid Product-id: %s" % (json.dumps(msg, indent=4, sort_keys=True))) return market = get_market_by_product(self.name, product_id) if (market == None): log.error("Feed Thread: Unknown market: %s" % (json.dumps(msg, indent=4, sort_keys=True))) return feed_enQ(market, msg) elif (msg_type in ['received', 'open', 'done', 'change']): if (product_id == None): log.error("Feed Thread: Invalid Product-id: %s" % (json.dumps(msg, indent=4, sort_keys=True))) return market = get_market_by_product(self.name, product_id) if (market == None): log.error("Feed Thread: Unknown market: %s" % (json.dumps(msg, indent=4, sort_keys=True))) return feed_enQ(market, msg) elif (msg_type == 'match'): #log.debug ("Feed Thread: Match msg : IGNORED") pass elif (msg_type == 'heartbeat'): #log.debug ("Feed Thread: Heartbeat: IGNORED") self.hearbeat_time = time.time() elif (msg_type == 'subscriptions'): log.debug("Feed: Subscribed to WS feed %s" % (json.dumps(msg, indent=4, sort_keys=True))) elif (msg_type == 'error'): log.error("Feed Thread: Error Msg received on Feed msg: %s" % (json.dumps(msg, indent=4, sort_keys=True))) else: log.error("Feed Thread: Unknown Feed Msg Type (%s)" % (msg['type']))
def _feed_enQ_msg(self, msg): # log.debug ("feed msg: %s"%msg) product_id = msg.id if (product_id == None): log.error("Feed Thread: Invalid Product-id: msg - \n %s" % (msg)) return market = get_market_by_product(self.name, product_id) if (market == None): log.error("Feed Thread: Unknown market: %s" % (msg)) return feed_enQ(market, msg)
def process_ui_get_market_indicators_rr(msg, ui_conn_pipe): log.debug("enter") exch = msg.get("exchange") product = msg.get("product") num_periods = msg.get("periods", 0) start_time = msg.get("start_time", 0) market = get_market_by_product(exch, product) ind_list = {} if market: ind_list = market.get_indicator_list(num_periods, start_time) msg["type"] = "GET_MARKET_INDICATORS_RESP" msg["data"] = ind_list ui_conn_pipe.send(msg)
def process_ui_pause_trading_notif(msg): exch = msg.get("exchange") product = msg.get("product") buy_pause = msg.get("buy_pause") sell_pause = msg.get("sell_pause") m = get_market_by_product(exch, product) if not m: log.error("Unknown exchange/product exch: %s prod: %s" % (exch, product)) else: log.info("pause trading on exch: %s prod: %s" % (exch, product)) m.pause_trading(buy_pause, sell_pause)
def process_ui_trade_notif(msg): exch = msg.get("exchange") product = msg.get("product") side = msg.get("side") signal = msg.get("signal") m = get_market_by_product(exch, product) if not m: log.error("Unknown exchange/product exch: %s prod: %s" % (exch, product)) else: log.info("Manual Trade Req: exch: %s prod: %s side: %s signal: %s" % (exch, product, side, str(signal))) m.consume_trade_signal(signal)
def process_ui_get_positions_rr(msg, ui_conn_pipe): log.debug("enter") exch = msg.get("exchange") product = msg.get("product") start_time = msg.get("start_time", 0) end_time = msg.get("end_time", 0) market = get_market_by_product(exch, product) pos_list = {} if market: log.info("get positions ") pos_list = market.get_positions_list(start_time, end_time) msg["type"] = "GET_MARKET_POSITIONS_RESP" msg["data"] = pos_list ui_conn_pipe.send(msg)
def _feed_enQ_msg(self, msg): log.debug("message :%s " % msg) msg_type = msg.get('e') symbol = msg.get("s") product_id = self.symbol_to_id[symbol] if (msg_type == 'kline'): log.debug("kline") market = get_market_by_product(self.name, product_id) if (market == None): log.error( "Feed Thread: Unknown market product: %s: msg %s" % (product_id, json.dumps(msg, indent=4, sort_keys=True))) return k = msg.get('k') if k.get('x') == True: #This kline closed, this is a candle feed_enQ(market, msg) else: # not interested pass else: log.error("Unknown feed. message type: %s prod: %s" % (msg_type, product_id)) return
def _feed_enQ_msg(self, msg_raw): # log.debug("message :%s " % msg_raw) if msg_raw.get('stream'): msg = msg_raw.get('data') else: msg = msg_raw msg_type = msg.get('e') if (msg_type == 'aggTrade' or msg_type == 'trade'): log.debug("aggTrade/trade") symbol = msg.get("s") product_id = self.symbol_to_id.get(symbol) if not product_id: log.error("unknown market(%s)" % (symbol)) return market = get_market_by_product(self.name, product_id) if (market == None): log.error( "Feed Thread: Unknown market product: %s: msg %s" % (product_id, json.dumps(msg, indent=4, sort_keys=True))) return feed_enQ(market, msg) elif (msg_type == 'kline'): log.debug("kline") symbol = msg.get("s") product_id = self.symbol_to_id.get(symbol) if not product_id: log.error("unknown market(%s)" % (symbol)) return k = msg.get('k') if k.get('x') == True: # This kline closed, this is a candle market = get_market_by_product(self.name, product_id) if (market == None): log.error( "Feed Thread: Unknown market product: %s: msg %s" % (product_id, json.dumps(msg, indent=4, sort_keys=True))) return feed_enQ(market, msg) else: # not interested pass elif (msg_type == 'executionReport'): log.debug("USER DATA: executionReport") symbol = msg.get("s") product_id = self.symbol_to_id.get(symbol) if not product_id: log.error("unknown market(%s)" % (symbol)) return market = get_market_by_product(self.name, product_id) if (market == None): log.error( "Feed Thread: Unknown market product: %s: msg %s" % (product_id, json.dumps(msg, indent=4, sort_keys=True))) return feed_enQ(market, msg) elif (msg_type == 'error'): log.critical("websocket connection retries exceeded!!") raise Exception("websocket connection retries exceeded!!") else: log.error("Unknown feed. message type: %s" % (msg_type)) return