Skip to content

Commit

Permalink
Merge branch '0.32/connector-altmarkets' into 0.32-altmarkets
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHolyRoger committed Oct 6, 2020
2 parents a347962 + 299ca12 commit 13591bb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
78 changes: 0 additions & 78 deletions hummingbot/connector/exchange/altmarkets/altmarkets_order_book.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ 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"]),
"update_id": msg_ts,
"bids": msg["bids"],
"asks": msg["asks"]
}
# print(f"Snap msg: {content}")
return OrderBookMessage(OrderBookMessageType.SNAPSHOT, content, timestamp or msg_ts)

@classmethod
Expand All @@ -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
Expand All @@ -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"]),
Expand All @@ -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()
Expand Down

0 comments on commit 13591bb

Please sign in to comment.