From 287a761917ec0a4a7c452543011e1043168c0b67 Mon Sep 17 00:00:00 2001 From: Herklos Date: Sat, 28 Aug 2021 13:34:07 +0200 Subject: [PATCH] [CryptofeedWebsocket] Add Huobi --- .../Exchange/huobi_websocket_feed/__init__.py | 1 + .../huobi_websocket_feed/huobi_websocket.py | 44 +++++++++++++++++ .../huobi_websocket_feed/metadata.json | 6 +++ .../huobi_websocket_feed/tests/__init__.py | 15 ++++++ .../test_unauthenticated_mocked_feeds.py | 48 +++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 Trading/Exchange/huobi_websocket_feed/__init__.py create mode 100644 Trading/Exchange/huobi_websocket_feed/huobi_websocket.py create mode 100644 Trading/Exchange/huobi_websocket_feed/metadata.json create mode 100644 Trading/Exchange/huobi_websocket_feed/tests/__init__.py create mode 100644 Trading/Exchange/huobi_websocket_feed/tests/test_unauthenticated_mocked_feeds.py diff --git a/Trading/Exchange/huobi_websocket_feed/__init__.py b/Trading/Exchange/huobi_websocket_feed/__init__.py new file mode 100644 index 000000000..5d7bacbec --- /dev/null +++ b/Trading/Exchange/huobi_websocket_feed/__init__.py @@ -0,0 +1 @@ +from .huobi_websocket import HuobiCryptofeedWebsocketConnector diff --git a/Trading/Exchange/huobi_websocket_feed/huobi_websocket.py b/Trading/Exchange/huobi_websocket_feed/huobi_websocket.py new file mode 100644 index 000000000..5e8247284 --- /dev/null +++ b/Trading/Exchange/huobi_websocket_feed/huobi_websocket.py @@ -0,0 +1,44 @@ +# Drakkar-Software OctoBot-Tentacles +# Copyright (c) Drakkar-Software, All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. +import octobot_trading.exchanges as exchanges +import cryptofeed.defines as cryptofeed_constants +from octobot_trading.enums import WebsocketFeeds as Feeds + + +class HuobiCryptofeedWebsocketConnector(exchanges.CryptofeedWebsocketConnector): + REQUIRED_ACTIVATED_TENTACLES = [] + EXCHANGE_FEEDS = { + Feeds.TRADES: cryptofeed_constants.TRADES, + Feeds.KLINE: Feeds.UNSUPPORTED.value, + Feeds.TICKER: Feeds.UNSUPPORTED.value, + Feeds.CANDLE: Feeds.UNSUPPORTED.value, + Feeds.L2_BOOK: Feeds.UNSUPPORTED.value, + Feeds.BOOK_DELTA: Feeds.UNSUPPORTED.value, + Feeds.VOLUME: Feeds.UNSUPPORTED.value, + Feeds.OPEN_INTEREST: Feeds.UNSUPPORTED.value, + } + + @classmethod + def get_name(cls): + return 'huobi' + + @classmethod + def get_feed_name(cls): + return cryptofeed_constants.HUOBI + + @classmethod + def is_handling_spot(cls) -> bool: + return True diff --git a/Trading/Exchange/huobi_websocket_feed/metadata.json b/Trading/Exchange/huobi_websocket_feed/metadata.json new file mode 100644 index 000000000..bb9225a85 --- /dev/null +++ b/Trading/Exchange/huobi_websocket_feed/metadata.json @@ -0,0 +1,6 @@ +{ + "version": "1.2.0", + "origin_package": "OctoBot-Default-Tentacles", + "tentacles": ["HuobiCryptofeedWebsocketConnector"], + "tentacles-requirements": [] +} \ No newline at end of file diff --git a/Trading/Exchange/huobi_websocket_feed/tests/__init__.py b/Trading/Exchange/huobi_websocket_feed/tests/__init__.py new file mode 100644 index 000000000..974dd1623 --- /dev/null +++ b/Trading/Exchange/huobi_websocket_feed/tests/__init__.py @@ -0,0 +1,15 @@ +# Drakkar-Software OctoBot-Tentacles +# Copyright (c) Drakkar-Software, All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. diff --git a/Trading/Exchange/huobi_websocket_feed/tests/test_unauthenticated_mocked_feeds.py b/Trading/Exchange/huobi_websocket_feed/tests/test_unauthenticated_mocked_feeds.py new file mode 100644 index 000000000..ccaf5b76a --- /dev/null +++ b/Trading/Exchange/huobi_websocket_feed/tests/test_unauthenticated_mocked_feeds.py @@ -0,0 +1,48 @@ +# Drakkar-Software OctoBot-Tentacles +# Copyright (c) Drakkar-Software, All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3.0 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. + +import pytest + +import octobot_commons.channels_name as channels_name +import octobot_commons.enums as commons_enums +import octobot_commons.tests as commons_tests +import octobot_trading.exchanges as exchanges +import octobot_trading.util.test_tools.exchanges_test_tools as exchanges_test_tools +import octobot_trading.util.test_tools.websocket_test_tools as websocket_test_tools +from ...huobi_websocket_feed import HuobiCryptofeedWebsocketConnector + +# All test coroutines will be treated as marked. +pytestmark = pytest.mark.asyncio + + +async def test_start_spot_websocket(): + config = commons_tests.load_test_config() + exchange_manager_instance = await exchanges_test_tools.create_test_exchange_manager( + config=config, exchange_name=HuobiCryptofeedWebsocketConnector.get_name()) + + await websocket_test_tools.test_unauthenticated_push_to_channel_coverage_websocket( + websocket_exchange_class=exchanges.CryptofeedWebSocketExchange, + websocket_connector_class=HuobiCryptofeedWebsocketConnector, + exchange_manager=exchange_manager_instance, + config=config, + symbols=["BTC/USDT", "ETH/USDT"], + time_frames=[commons_enums.TimeFrames.ONE_MINUTE, commons_enums.TimeFrames.ONE_HOUR], + expected_pushed_channels={ + channels_name.OctoBotTradingChannelsName.RECENT_TRADES_CHANNEL.value, + }, + time_before_assert=20 + ) + await exchanges_test_tools.stop_test_exchange_manager(exchange_manager_instance)