Skip to content

Commit

Permalink
[Trading][Exchanges][Bybit] Add websocket feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Sep 19, 2021
1 parent 6ed952c commit 893077a
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions Trading/Exchange/bybit_websocket_feed/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .bybit_websocket import BybitCryptofeedWebsocketConnector
44 changes: 44 additions & 0 deletions Trading/Exchange/bybit_websocket_feed/bybit_websocket.py
Original file line number Diff line number Diff line change
@@ -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 BybitCryptofeedWebsocketConnector(exchanges.CryptofeedWebsocketConnector):
REQUIRED_ACTIVATED_TENTACLES = []
EXCHANGE_FEEDS = {
Feeds.TRADES: cryptofeed_constants.TRADES,
Feeds.KLINE: cryptofeed_constants.CANDLES,
Feeds.TICKER: Feeds.UNSUPPORTED.value,
Feeds.CANDLE: cryptofeed_constants.CANDLES,
}

@classmethod
def get_name(cls):
return 'bybit'

@classmethod
def get_feed_name(cls):
return cryptofeed_constants.BYBIT

@classmethod
def is_handling_spot(cls) -> bool:
return False # Soon

@classmethod
def is_handling_future(cls) -> bool:
return True
6 changes: 6 additions & 0 deletions Trading/Exchange/bybit_websocket_feed/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.2.0",
"origin_package": "OctoBot-Default-Tentacles",
"tentacles": ["BybitCryptofeedWebsocketConnector"],
"tentacles-requirements": []
}
15 changes: 15 additions & 0 deletions Trading/Exchange/bybit_websocket_feed/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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 ...binance_websocket_feed import BinanceCryptofeedWebsocketConnector

# 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=BinanceCryptofeedWebsocketConnector.get_name())

await websocket_test_tools.test_unauthenticated_push_to_channel_coverage_websocket(
websocket_exchange_class=exchanges.CryptofeedWebSocketExchange,
websocket_connector_class=BinanceCryptofeedWebsocketConnector,
exchange_manager=exchange_manager_instance,
config=config,
symbols=["BTC/USDT", "ETH/BTC", "ETH/USDT"],
time_frames=[commons_enums.TimeFrames.ONE_MINUTE,
commons_enums.TimeFrames.ONE_HOUR,
commons_enums.TimeFrames.FOUR_HOURS],
expected_pushed_channels={
channels_name.OctoBotTradingChannelsName.KLINE_CHANNEL.value,
channels_name.OctoBotTradingChannelsName.OHLCV_CHANNEL.value
},
time_before_assert=75
)
await exchanges_test_tools.stop_test_exchange_manager(exchange_manager_instance)

0 comments on commit 893077a

Please sign in to comment.