(self, endpoint="", symbol="XBTN15", shouldAuth=True)
Connect to the websocket and initialize data stores.
Connect to the websocket and initialize data stores.
Connect to the websocket and initialize data stores .
def connect(self, endpoint="", symbol="XBTN15", shouldAuth=True):
        '''Connect to the websocket and initialize data stores.'''

        self.logger.debug("Connecting WebSocket.")
        self.symbol = symbol
        self.shouldAuth = shouldAuth

        # We can subscribe right in the connection querystring, so let's build that.
        # Subscribe to all pertinent endpoints
        subscriptions = [sub + ':' + symbol for sub in ["quote", "trade", "orderBook25"]]
        subscriptions += ["instrument"]  # We want all of them
        if self.shouldAuth:
            subscriptions += [sub + ':' + symbol for sub in ["order", "execution"]]
            subscriptions += ["margin", "position"]

        # Get WS URL and connect.
        urlParts = list(urlparse(endpoint))
        urlParts[0] = urlParts[0].replace('http', 'ws')
        urlParts[2] = "/realtime?subscribe=" + ",".join(subscriptions)
        wsURL = urlunparse(urlParts)
        self.logger.info("Connecting to %s" % wsURL)
        self.__connect(wsURL)
        self.logger.info('Connected to WS. Waiting for data images, this may take a moment...')

        # Connected. Wait for partials
        self.__wait_for_symbol(symbol)
        if self.shouldAuth:
            self.__wait_for_account()
        self.logger.info('Got all market data. Starting.')
def connect ( self , endpoint = "" , symbol = "XBTN15" , shouldAuth = True ) : self . logger . debug ( "Connecting WebSocket." ) self . symbol = symbol self . shouldAuth = shouldAuth # We can subscribe right in the connection querystring, so let's build that. # Subscribe to all pertinent endpoints subscriptions = [ sub + ':' + symbol for sub in [ "quote" , "trade" , "orderBook25" ] ] subscriptions += [ "instrument" ] # We want all of them if self . shouldAuth : subscriptions += [ sub + ':' + symbol for sub in [ "order" , "execution" ] ] subscriptions += [ "margin" , "position" ] # Get WS URL and connect. urlParts = list ( urlparse ( endpoint ) ) urlParts [ 0 ] = urlParts [ 0 ] . replace ( 'http' , 'ws' ) urlParts [ 2 ] = "/realtime?subscribe=" + "," . join ( subscriptions ) wsURL = urlunparse ( urlParts ) self . logger . info ( "Connecting to %s" % wsURL ) self . __connect ( wsURL ) self . logger . info ( 'Connected to WS. Waiting for data images, this may take a moment...' ) # Connected. Wait for partials self . __wait_for_symbol ( symbol ) if self . shouldAuth : self . __wait_for_account ( ) self . logger . info ( 'Got all market data. Starting.' )