Skip to content

Commit

Permalink
v1.2.5-3 fixed #2
Browse files Browse the repository at this point in the history
  • Loading branch information
DogsTailFarmer committed Sep 26, 2022
1 parent 321e4b9 commit 27aa110
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v1.2.5-3 2022-09-26
### Fixed
* #2 FTX WS market stream lies down quietly

### Update
* Slightly optimized process of docker container setup and start-up

## v1.2.5-2 2022-09-23
### Added for new features
* Published as Docker image
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,26 @@ at real bidding. First, run applications on the [Binance Spot Test Network](http

### Use Docker image
* pull image with [last version](https://github.com/DogsTailFarmer/exchanges-wrapper/pkgs/container/exchanges-wrapper/versions)
* get IMAGE_ID from pulled image and use it when run next command
* get IMAGE_ID from pulled image and use it for set environment variable
```console
IMAGE_ID=sha256:d52ecfb66fac32f1eaeec994cde18453120d49ff38245f1e84b8fa929e811c09
```
#### First run
The structure of the working directory will be created and the necessary files will be copied:
For Ubuntu it will be here: ```home/user/.MartinBinance/```
```console
sudo docker run --rm --entrypoint /bin/sh IMAGE_ID -c "cat /home/appuser/.local/lib/python3.10/site-packages/exchanges_wrapper/__init__.py" > init.py && \
sudo docker run --rm --entrypoint /bin/sh IMAGE_ID -c "cat /home/appuser/.local/lib/python3.10/site-packages/exchanges_wrapper/exch_srv_cfg.toml.template" > exch_srv_cfg.toml.template &&\
python3 init.py &&\
rm init.py &&\
rm exch_srv_cfg.toml.template
docker run --rm --entrypoint /bin/sh $IMAGE_ID -c "cat ./exchanges_wrapper/__init__.py" > init.py && \
docker run --rm --entrypoint /bin/sh $IMAGE_ID -c "cat ./exchanges_wrapper/exch_srv_cfg.toml.template" > exch_srv_cfg.toml.template &&\
python3 init.py && rm init.py && rm exch_srv_cfg.toml.template
```
#### Start server
```console
sudo docker run -ditP \
--mount type=bind,source=/home/ubuntu/.MartinBinance,target=/home/appuser/.MartinBinance \
--network=host \
--restart=always \
--name=exchanges-wrapper \
IMAGE_ID
docker run -itP \
--mount type=bind,source=/home/ubuntu/.MartinBinance,target=/home/appuser/.MartinBinance \
--network=host \
--restart=always \
--name=exchanges-wrapper \
$IMAGE_ID
```

### Install use PIP
Expand Down
2 changes: 1 addition & 1 deletion exchanges_wrapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
__contact__ = "https://github.com/DogsTailFarmer"
__email__ = "[email protected]"
__credits__ = ["https://github.com/DanyaSWorlD"]
__version__ = "1.2.5-2"
__version__ = "1.2.5-3"

from pathlib import Path
import shutil
Expand Down
30 changes: 24 additions & 6 deletions exchanges_wrapper/web_sockets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# __version__ = "1.2.5-2"
# __version__ = "1.2.5-3"

from exchanges_wrapper import __version__

Expand Down Expand Up @@ -38,7 +38,7 @@ async def start(self):
logger.info(f"EventsDataStream start(): exchange: {self.exchange}, endpoint: {self.endpoint}")
try:
await self.start_wss()
except (aiohttp.WSServerHandshakeError, aiohttp.ClientConnectionError) as ex:
except (aiohttp.WSServerHandshakeError, aiohttp.ClientConnectionError, asyncio.TimeoutError) as ex:
self.try_count += 1
delay = random.randint(1, 10) * self.try_count
logger.error(f"WSS start(): {ex}, restart try count: {self.try_count}, delay: {delay}s")
Expand Down Expand Up @@ -68,6 +68,12 @@ async def upstream_bitfinex(self, request, symbol=None, ch_type=str()):
await asyncio.sleep(60)
raise aiohttp.ClientOSError

async def _heartbeat_ftx(self, interval=15):
request = {'op': 'ping'}
while True:
await asyncio.sleep(interval)
await self.web_socket.send_json(request)

async def _handle_event(self, *args):
pass # meant to be overridden in a subclass

Expand Down Expand Up @@ -167,10 +173,16 @@ async def start_wss(self):
ch_type = 'ticker'
elif ch_type == 'depth5':
ch_type = 'orderbook'
self.web_socket = await self.session.ws_connect(self.endpoint, heartbeat=15, proxy=self.client.proxy)
self.web_socket = await self.session.ws_connect(self.endpoint,
receive_timeout=30,
proxy=self.client.proxy)
request = {'op': 'subscribe', 'channel': ch_type, 'market': symbol}
await self.web_socket.send_json(request)
await self._handle_messages(self.web_socket, symbol=symbol, ch_type=ch_type)
_task = asyncio.ensure_future(self._heartbeat_ftx())
try:
await self._handle_messages(self.web_socket, symbol=symbol, ch_type=ch_type)
finally:
_task.cancel()
elif self.exchange == 'bitfinex':
if ch_type == 'miniTicker':
ch_type = 'ticker'
Expand Down Expand Up @@ -250,7 +262,9 @@ async def stop(self):
await self.web_socket.close()

async def start_wss(self):
self.web_socket = await self.session.ws_connect(self.endpoint, heartbeat=15, proxy=self.client.proxy)
self.web_socket = await self.session.ws_connect(self.endpoint,
receive_timeout=30,
proxy=self.client.proxy)
ts = int(time.time() * 1000)
data = f"{ts}websocket_login"
request = {
Expand All @@ -268,7 +282,11 @@ async def start_wss(self):
await self.web_socket.send_json(request)
request = {'op': 'subscribe', 'channel': 'orders'}
await self.web_socket.send_json(request)
await self._handle_messages(self.web_socket)
_task = asyncio.ensure_future(self._heartbeat_ftx())
try:
await self._handle_messages(self.web_socket)
finally:
_task.cancel()

async def _handle_event(self, msg_data, *args):
self.try_count = 0
Expand Down

0 comments on commit 27aa110

Please sign in to comment.