Skip to content

Commit 9697bff

Browse files
authored
Merge pull request #743 from DavideColdebella/master
Added TICKER support for Huobi
2 parents aaa9e91 + d2b9cde commit 9697bff

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

cryptofeed/exchanges/huobi.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from yapic import json
1515

1616
from cryptofeed.connection import AsyncConnection
17-
from cryptofeed.defines import BUY, CANDLES, HUOBI, L2_BOOK, SELL, TRADES
17+
from cryptofeed.defines import BUY, CANDLES, HUOBI, L2_BOOK, SELL, TRADES, TICKER
1818
from cryptofeed.feed import Feed
19-
from cryptofeed.types import OrderBook, Trade, Candle
19+
from cryptofeed.types import OrderBook, Trade, Candle, Ticker
2020

2121

2222
LOG = logging.getLogger('feedhandler')
@@ -32,6 +32,7 @@ class Huobi(Feed):
3232
L2_BOOK: 'depth.step0',
3333
TRADES: 'trade.detail',
3434
CANDLES: 'kline',
35+
TICKER: 'ticker'
3536
}
3637

3738
@classmethod
@@ -66,6 +67,38 @@ async def _book(self, msg: dict, timestamp: float):
6667
self._l2_book[pair].book.asks = {Decimal(price): Decimal(amount) for price, amount in data['asks']}
6768

6869
await self.book_callback(L2_BOOK, self._l2_book[pair], timestamp, timestamp=self.timestamp_normalize(msg['ts']), raw=msg)
70+
71+
async def _ticker(self, msg: dict, timestamp: float):
72+
"""
73+
{
74+
"ch":"market.btcusdt.ticker",
75+
"ts":1630982370526,
76+
"tick":{
77+
"open":51732,
78+
"high":52785.64,
79+
"low":51000,
80+
"close":52735.63,
81+
"amount":13259.24137056181,
82+
"vol":687640987.4125315,
83+
"count":448737,
84+
"bid":52732.88,
85+
"bidSize":0.036,
86+
"ask":52732.89,
87+
"askSize":0.583653,
88+
"lastPrice":52735.63,
89+
"lastSize":0.03
90+
}
91+
}
92+
"""
93+
t = Ticker(
94+
self.id,
95+
self.exchange_symbol_to_std_symbol(msg['ch'].split('.')[1]),
96+
msg['tick']['bid'],
97+
msg['tick']['ask'],
98+
self.timestamp_normalize(msg['ts']),
99+
raw=msg['tick']
100+
)
101+
await self.callback(TICKER, t, timestamp)
69102

70103
async def _trade(self, msg: dict, timestamp: float):
71104
"""
@@ -152,6 +185,8 @@ async def message_handler(self, msg: str, conn, timestamp: float):
152185
elif 'ch' in msg:
153186
if 'trade' in msg['ch']:
154187
await self._trade(msg, timestamp)
188+
elif 'tick' in msg['ch']:
189+
await self._ticker(msg, timestamp)
155190
elif 'depth' in msg['ch']:
156191
await self._book(msg, timestamp)
157192
elif 'kline' in msg['ch']:

0 commit comments

Comments
 (0)