Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

remove invocation of unknown method _check_login #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Keep valid mode when login is executed after error
  • Loading branch information
michaelflowersky committed Nov 2, 2020
commit 09860087504a39397e5c69a873771e067802b701
10 changes: 8 additions & 2 deletions XTBApi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,12 @@ def _check_volume(volume):
class BaseClient(object):
"""main client class"""

VALID_MODES = ["demo", "demoStream", "real", "realStream"]

def __init__(self):
self.ws = None
self._login_data = None
self._mode = None
self._time_last_request = time.time() - MAX_TIME_INTERVAL
self.status = STATUS.NOT_LOGGED
LOGGER.debug("BaseClient inited")
Expand All @@ -113,11 +116,11 @@ def _login_decorator(self, func, *args, **kwargs):
return func(*args, **kwargs)
except SocketError as e:
LOGGER.info("re-logging in due to LOGIN_TIMEOUT gone")
self.login(self._login_data[0], self._login_data[1])
self.login(self._login_data[0], self._login_data[1], self._mode)
return func(*args, **kwargs)
except Exception as e:
LOGGER.warning(e)
self.login(self._login_data[0], self._login_data[1])
self.login(self._login_data[0], self._login_data[1], self._mode)
return func(*args, **kwargs)

def _send_command(self, dict_data):
Expand Down Expand Up @@ -146,10 +149,13 @@ def _send_command_with_check(self, dict_data):

def login(self, user_id, password, mode='demo'):
"""login command"""
if mode not in self.VALID_MODES:
raise Exception("Invalid mode: {}".format(mode))
data = _get_data("login", userId=user_id, password=password)
self.ws = create_connection(f"wss://ws.xtb.com/{mode}")
response = self._send_command(data)
self._login_data = (user_id, password)
self._mode = mode
self.status = STATUS.LOGGED
self.LOGGER.info("CMD: login...")
return response
Expand Down