Skip to content

Commit

Permalink
add before_connect and endpoint_args to websocket exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed Jul 18, 2020
1 parent c28a3ee commit b04ae44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions octobot_trading/exchanges/types/websocket_exchange.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ cdef class WebsocketExchange:
cdef bint use_testnet
cdef bint is_authenticated

cdef public dict endpoint_args

cdef public list currencies
cdef public list pairs
cdef public list time_frames
Expand Down
13 changes: 11 additions & 2 deletions octobot_trading/exchanges/types/websocket_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(self,
self.is_authenticated = False
self.should_stop = False

# keyword arguments to be given to get_ws_endpoint
self.endpoint_args = {}

self.currencies = currencies if currencies else []
self.pairs = []
self.channels = []
Expand Down Expand Up @@ -112,9 +115,12 @@ async def _connect(self):
# manage max delay
if delay >= self.MAX_DELAY:
delay = self.MAX_DELAY

try:
async with websockets.connect(self.get_ws_endpoint()
await self.before_connect()
except Exception as e:
self.logger.exception(e, True, f"Error on before_connect {e}")
try:
async with websockets.connect(self.get_ws_endpoint(**self.endpoint_args)
if not self.use_testnet else self.get_ws_testnet_endpoint(),
subprotocols=self.get_sub_protocol()) as websocket:
self.websocket = websocket
Expand Down Expand Up @@ -202,6 +208,9 @@ def close(self):
self.websocket.close()
self.on_close()

async def before_connect(self):
pass

async def prepare(self):
pass

Expand Down

0 comments on commit b04ae44

Please sign in to comment.