Skip to content

Commit

Permalink
Merge pull request #27 from Mai-Te-Pora/enhancement/websocket-crawler
Browse files Browse the repository at this point in the history
Crawl Tradehub Network for Open WS Ports
  • Loading branch information
Devel484 committed Feb 24, 2021
2 parents cff36f2 + 07b0222 commit bdd9b2d
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 58 deletions.
2 changes: 1 addition & 1 deletion docs/websocket_client.rst
@@ -1,4 +1,4 @@
Public Class - :mod:`websocket_client`
Websocket Class - :mod:`websocket_client`
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. contents:: Table of Contents
Expand Down
6 changes: 4 additions & 2 deletions tests/__init__.py
Expand Up @@ -3,10 +3,12 @@

from tradehub.public_client import PublicClient

mainnet_client = PublicClient(network='mainnet')
mainnet_client = PublicClient(network='mainnet', is_websocket_client=True)
MAINNET_VAL_IP = mainnet_client.active_sentry_api_ip
testnet_client = PublicClient(network='testnet')
MAINNET_WS_URI = mainnet_client.active_ws_uri
testnet_client = PublicClient(network='testnet', is_websocket_client=True)
TESTNET_VAL_IP = testnet_client.active_sentry_api_ip
TESTNET_WS_URI = testnet_client.active_ws_uri

WALLET_VALIDATOR = "swth1vwges9p847l9csj8ehrlgzajhmt4fcq4sd7gzl"
WALLET_DEVEL = "swth1qlue2pat9cxx2s5xqrv0ashs475n9va963h4hz"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ws_get_account_trades.py
Expand Up @@ -2,7 +2,7 @@
import concurrent
from typing import Optional

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_GET_REQUEST, WALLET_DEVEL
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_GET_REQUEST, WALLET_DEVEL
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -37,7 +37,7 @@ def test_get_account_trades_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: Optional[dict] = None

Expand Down Expand Up @@ -80,7 +80,7 @@ def test_get_account_trades_pagination(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: Optional[dict] = None

Expand Down
6 changes: 3 additions & 3 deletions tests/test_ws_get_candlesticks.py
@@ -1,7 +1,7 @@
import asyncio
from typing import Optional, List

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_GET_REQUEST
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_GET_REQUEST
from tradehub.websocket_client import DemexWebsocket


Expand All @@ -23,7 +23,7 @@ def test_get_candlesticks_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[Optional[dict]] = []

Expand Down Expand Up @@ -57,7 +57,7 @@ def test_get_candlesticks_wrong_granularity(self):
"""

# connect to websocket
client = DemexWebsocket("")
client = DemexWebsocket(uri="")
for wrong_granularity in [0, 2, 4, 6, 100, 1500]:
with self.assertRaises(ValueError):
loop = asyncio.get_event_loop()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_ws_get_market_stats.py
@@ -1,7 +1,7 @@
import asyncio
from typing import Optional

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_GET_REQUEST
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_GET_REQUEST
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -44,7 +44,7 @@ def test_get_market_stats_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: Optional[dict] = None

Expand Down Expand Up @@ -105,7 +105,7 @@ def test_get_market_stats_with_param(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: Optional[dict] = None

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_get_open_orders.py
@@ -1,7 +1,7 @@
import asyncio
from typing import Optional

from tests import APITestCase, MAINNET_VAL_IP, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_GET_REQUEST
from tests import APITestCase, MAINNET_WS_URI, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_GET_REQUEST
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -46,7 +46,7 @@ def test_get_open_orders_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: Optional[dict] = None

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_get_order_history.py
@@ -1,7 +1,7 @@
import asyncio
from typing import Optional

from tests import APITestCase, MAINNET_VAL_IP, WALLET_DEVEL, WEBSOCKET_TIMEOUT_GET_REQUEST
from tests import APITestCase, MAINNET_WS_URI, WALLET_DEVEL, WEBSOCKET_TIMEOUT_GET_REQUEST
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -46,7 +46,7 @@ def test_get_order_history_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: Optional[dict] = None

Expand Down
8 changes: 2 additions & 6 deletions tests/test_ws_get_recent_trades.py
@@ -1,7 +1,7 @@
import asyncio
from typing import Optional

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_GET_REQUEST
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_GET_REQUEST
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -41,7 +41,7 @@ def test_get_recent_trades_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: Optional[dict] = None

Expand All @@ -65,7 +65,3 @@ async def on_message(message: dict):
raise RuntimeError("Did not receive a response.")

self.assertDictStructure(expect, self.response)

# TODO remove or change if id in trade is no longer 'id'
for trade in self.response["result"]:
self.assertTrue(trade["id"] == "0", msg="Expected id to be '0'")
6 changes: 3 additions & 3 deletions tests/test_ws_subscribe_account_trades.py
@@ -1,6 +1,6 @@
import asyncio
from tradehub.websocket_client import DemexWebsocket
from tests import APITestCase, MAINNET_VAL_IP, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tests import APITestCase, MAINNET_WS_URI, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_SUBSCRIPTION


class TestWSSubscribeAccountTrades(APITestCase):
Expand Down Expand Up @@ -44,7 +44,7 @@ def test_subscribe_account_trades_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down Expand Up @@ -117,7 +117,7 @@ def test_subscribe_account_market_trades_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_subscribe_balance.py
@@ -1,7 +1,7 @@
import asyncio
from typing import List

from tests import APITestCase, MAINNET_VAL_IP, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tests import APITestCase, MAINNET_WS_URI, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -34,7 +34,7 @@ def test_subscribe_balance_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_subscribe_books.py
@@ -1,7 +1,7 @@
import asyncio
from typing import List

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -32,7 +32,7 @@ def test_subscribe_books_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_subscribe_candlesticks.py
@@ -1,7 +1,7 @@
import asyncio
from typing import List

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -35,7 +35,7 @@ def test_subscribe_candlesticks_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_subscribe_market_stats.py
@@ -1,7 +1,7 @@
import asyncio
from typing import List

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_GET_REQUEST
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_GET_REQUEST
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -49,7 +49,7 @@ def test_subscribe_market_stats_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down
6 changes: 3 additions & 3 deletions tests/test_ws_subscribe_orders.py
@@ -1,7 +1,7 @@
import asyncio
from typing import List

from tests import APITestCase, MAINNET_VAL_IP, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tests import APITestCase, MAINNET_WS_URI, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -51,7 +51,7 @@ def test_subscribe_orders_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down Expand Up @@ -129,7 +129,7 @@ def test_subscribe_market_orders_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_subscribe_recent_trades.py
@@ -1,7 +1,7 @@
import asyncio
from typing import List

from tests import APITestCase, MAINNET_VAL_IP, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tests import APITestCase, MAINNET_WS_URI, WEBSOCKET_TIMEOUT_SUBSCRIPTION
from tradehub.websocket_client import DemexWebsocket


Expand Down Expand Up @@ -46,7 +46,7 @@ def test_subscribe_recent_trades_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down
4 changes: 2 additions & 2 deletions tests/test_ws_unsubscribe.py
@@ -1,7 +1,7 @@
import asyncio
from typing import List

from tests import APITestCase, MAINNET_VAL_IP, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_GET_REQUEST
from tests import APITestCase, MAINNET_WS_URI, WALLET_SWTH_ETH1_AMM, WEBSOCKET_TIMEOUT_GET_REQUEST
from tradehub.websocket_client import DemexWebsocket


Expand All @@ -18,7 +18,7 @@ def test_unsubscribe_structure(self):
}

# connect to websocket
client = DemexWebsocket(f"ws://{MAINNET_VAL_IP}:5000/ws")
client = DemexWebsocket(uri=MAINNET_WS_URI)
# little work around to save the response
self.response: List[dict] = []

Expand Down

0 comments on commit bdd9b2d

Please sign in to comment.