Ejemplo n.º 1
0
    def connect(
        self
    ) -> List[Tuple[AsyncConnection, Callable[[None], None], Callable[
        [str, float], None]]]:
        """
        Generic connection method for exchanges. Exchanges that require/support
        multiple addresses will need to override this method in their specific class
        unless they use the same subscribe method and message handler for all
        connections.

        Connect returns a list of tuples. Each tuple contains
        1. an AsyncConnection object
        2. the subscribe function pointer associated with this connection
        3. the message handler for this connection
        """
        ret = []
        if isinstance(self.address, str):
            return [(AsyncConnection(self.address, self.id,
                                     **self.ws_defaults), self.subscribe,
                     self.message_handler)]

        for _, addr in self.address.items():
            ret.append((AsyncConnection(addr, self.id, **self.ws_defaults),
                        self.subscribe, self.message_handler))
        return ret
Ejemplo n.º 2
0
    def connect(self) -> List[Tuple[AsyncConnection, Callable[[None], None], Callable[[str, float], None]]]:
        ret = []

        if any(pair[-4:] == 'USDT' for pair in self.normalized_symbols):
            subscribe = partial(self.subscribe, quote='USDT')
            ret.append((AsyncConnection(self.address['USDT'], self.id, **self.ws_defaults), subscribe, self.message_handler))
        if any(pair[-3:] == 'USD' for pair in self.normalized_symbols):
            subscribe = partial(self.subscribe, quote='USD')
            ret.append((AsyncConnection(self.address['USD'], self.id, **self.ws_defaults), subscribe, self.message_handler))

        return ret
Ejemplo n.º 3
0
    def connect(self) -> List[Tuple[AsyncConnection, Callable[[None], None], Callable[[str, float], None]]]:
        ret = []
        for channel in self.subscription or self.channels:
            if is_authenticated_channel(channel):
                syms = self.symbols or self.subscription[channel]
                for s in syms:
                    ret.append((AsyncConnection(self.address, self.id, **self.ws_defaults), partial(self.user_order_subscribe, symbol=s), self.message_handler))
            else:
                ret.append((AsyncConnection(self.address, self.id, **self.ws_defaults), self.subscribe, self.message_handler))

        return ret
Ejemplo n.º 4
0
 def _connect_builder(self,
                      address: str,
                      options: list,
                      header=None,
                      sub=None,
                      handler=None):
     """
     Helper method for building a custom connect tuple
     """
     subscribe = partial(self.subscribe if not sub else sub,
                         options=options)
     conn = AsyncConnection(address,
                            self.id,
                            extra_headers=header,
                            **self.ws_defaults)
     return conn, subscribe, handler if handler else self.message_handler
Ejemplo n.º 5
0
 def connect(
     self
 ) -> List[Tuple[AsyncConnection, Callable[[None], None], Callable[
     [str, float], None]]]:
     addrs = []
     for chan in self.channels if self.channels else self.config:
         for pair in self.pairs if not self.config else self.config[chan]:
             if chan == MARKET_INFO:
                 addrs.append(
                     f"{self.address}coins/{pair}?localization=false&tickers=false&market_data=true&community_data=true&developer_data=false&sparkline=false"
                 )
     return [(AsyncConnection(addrs,
                              self.id,
                              delay=self.sleep_time * 2,
                              sleep=self.sleep_time), self.subscribe,
              self.message_handler)]
Ejemplo n.º 6
0
    def connect(
        self
    ) -> List[Tuple[AsyncConnection, Callable[[None], None], Callable[
        [str, float], None]]]:
        ret = []
        if self.address:
            ret = super().connect()

        for chan in set(self.channels or self.subscription):
            if chan == 'open_interest':
                addrs = [
                    f"{self.rest_endpoint}/openInterest?symbol={pair}"
                    for pair in set(self.symbols or self.subscription[chan])
                ]
                ret.append((AsyncConnection(addrs,
                                            self.id,
                                            delay=60.0,
                                            sleep=1.0,
                                            **self.ws_defaults),
                            self.subscribe, self.message_handler))
        return ret
Ejemplo n.º 7
0
 def build(options: list):
     subscribe = partial(self.subscribe, options=options)
     conn = AsyncConnection(self.address, self.id, **self.ws_defaults)
     return conn, subscribe, self.message_handler