From 299ca1275e1d95d2e362a9428f35a893fe20418b Mon Sep 17 00:00:00 2001 From: TheHolyRoger Date: Tue, 6 Oct 2020 11:31:24 +0100 Subject: [PATCH] Cleanup and remove redundant code --- .../exchange/altmarkets/altmarkets_auth.py | 1 - .../altmarkets/altmarkets_order_book.pyx | 78 ------------------- 2 files changed, 79 deletions(-) diff --git a/hummingbot/connector/exchange/altmarkets/altmarkets_auth.py b/hummingbot/connector/exchange/altmarkets/altmarkets_auth.py index 37f4b57e2f..5a9a4e2e13 100644 --- a/hummingbot/connector/exchange/altmarkets/altmarkets_auth.py +++ b/hummingbot/connector/exchange/altmarkets/altmarkets_auth.py @@ -36,7 +36,6 @@ def generate_signature(self) -> (Dict[str, Any]): return True def get_headers(self) -> (Dict[str, Any]): - # if self.signature is None or self.nonce is None or self.signature_timestamp < int(time.time()): self.generate_signature() return { "X-Auth-Apikey": self.api_key, diff --git a/hummingbot/connector/exchange/altmarkets/altmarkets_order_book.pyx b/hummingbot/connector/exchange/altmarkets/altmarkets_order_book.pyx index a8b0217f1f..e89f900386 100644 --- a/hummingbot/connector/exchange/altmarkets/altmarkets_order_book.pyx +++ b/hummingbot/connector/exchange/altmarkets/altmarkets_order_book.pyx @@ -37,7 +37,6 @@ cdef class AltmarketsOrderBook(OrderBook): metadata: Optional[Dict] = None) -> OrderBookMessage: if metadata: msg.update(metadata) - # print(f"Snap rawmsg: {msg}") msg_ts = int(time.time() * 1e-3) content = { "trading_pair": convert_from_exchange_trading_pair(msg["trading_pair"]), @@ -45,7 +44,6 @@ cdef class AltmarketsOrderBook(OrderBook): "bids": msg["bids"], "asks": msg["asks"] } - # print(f"Snap msg: {content}") return OrderBookMessage(OrderBookMessageType.SNAPSHOT, content, timestamp or msg_ts) @classmethod @@ -64,7 +62,6 @@ cdef class AltmarketsOrderBook(OrderBook): "amount": msg["amount"], "price": msg["price"] } - # print(f"Trade msg: {content}") return OrderBookMessage(OrderBookMessageType.DIFF, content, timestamp or msg_ts) @classmethod @@ -74,7 +71,6 @@ cdef class AltmarketsOrderBook(OrderBook): metadata: Optional[Dict] = None) -> OrderBookMessage: if metadata: msg.update(metadata) - # print(f"Diff raw_msg: {msg}") msg_ts = int(time.time() * 1e-3) content = { "trading_pair": convert_from_exchange_trading_pair(msg["trading_pair"]), @@ -86,82 +82,8 @@ cdef class AltmarketsOrderBook(OrderBook): for x in range(len(content[bid_ask])): if content[bid_ask][x][1] == '': content[bid_ask][x][1] = '0.0' - # print(f"Diff msg: {content}") return OrderBookMessage(OrderBookMessageType.DIFF, content, timestamp or msg_ts) - @classmethod - def snapshot_message_from_db(cls, record: RowProxy, metadata: Optional[Dict] = None) -> OrderBookMessage: - msg = record["json"] if type(record["json"])==dict else ujson.loads(record["json"]) - if metadata: - msg.update(metadata) - msg_ts = int(time.time() * 1e-3) - msg_key = list(msg.keys())[0] - trading_pair = msg_key.split(".")[0] - return OrderBookMessage(OrderBookMessageType.SNAPSHOT, { - "trading_pair": convert_from_exchange_trading_pair(trading_pair), - "update_id": msg_ts, - "bids": msg[msg_key]["bids"], - "asks": msg[msg_key]["asks"] - }, timestamp=msg_ts) - - @classmethod - def diff_message_from_db(cls, record: RowProxy, metadata: Optional[Dict] = None) -> OrderBookMessage: - print("Diff MSG from DB") - ts = record["timestamp"] - msg = record["json"] if type(record["json"])==dict else ujson.loads(record["json"]) - if metadata: - msg.update(metadata) - return OrderBookMessage(OrderBookMessageType.DIFF, { - "trading_pair": convert_from_exchange_trading_pair(msg["s"]), - "update_id": int(ts), - "bids": msg["b"], - "asks": msg["a"] - }, timestamp=ts * 1e-3) - - @classmethod - def snapshot_message_from_kafka(cls, record: ConsumerRecord, metadata: Optional[Dict] = None) -> OrderBookMessage: - ts = record.timestamp - msg = ujson.loads(record.value.decode()) - if metadata: - msg.update(metadata) - return OrderBookMessage(OrderBookMessageType.SNAPSHOT, { - "trading_pair": convert_from_exchange_trading_pair(msg["ch"].split(".")[1]), - "update_id": ts, - "bids": msg["tick"]["bids"], - "asks": msg["tick"]["asks"] - }, timestamp=ts * 1e-3) - - @classmethod - def diff_message_from_kafka(cls, record: ConsumerRecord, metadata: Optional[Dict] = None) -> OrderBookMessage: - decompressed = bz2.decompress(record.value) - msg = ujson.loads(decompressed) - ts = record.timestamp - if metadata: - msg.update(metadata) - return OrderBookMessage(OrderBookMessageType.DIFF, { - "trading_pair": convert_from_exchange_trading_pair(msg["s"]), - "update_id": ts, - "bids": msg["bids"], - "asks": msg["asks"] - }, timestamp=ts * 1e-3) - - @classmethod - def trade_message_from_db(cls, record: RowProxy, metadata: Optional[Dict] = None): - msg = record - msg_ts = int(msg["date"]) - # ts = record.timestamp - # data = msg["tick"]["data"][0] - if metadata: - msg.update(metadata) - return OrderBookMessage(OrderBookMessageType.TRADE, { - "trading_pair": convert_from_exchange_trading_pair(msg["trading_pair"]), - "trade_type": float(TradeType.BUY.value) if msg["taker_type"] == "sell" else float(TradeType.SELL.value), - "trade_id": msg["tid"], - "update_id": msg_ts, - "amount": msg["amount"], - "price": msg["price"] - }, timestamp=msg_ts) - @classmethod def from_snapshot(cls, msg: OrderBookMessage) -> "OrderBook": retval = AltmarketsOrderBook()