sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.01k stars 2.2k forks source link

ThreadedWebsocketManager start_futures_socket never uses testnet url #929

Open jamierobertson1 opened 3 years ago

jamierobertson1 commented 3 years ago

Firstly thanks for the good work.

I noticed the ThreadedWebsocketManager::start_futures_socket never sets the futures testnet url for receiving user data.

This is because it calls just futures_socket in the BinanceSocketManagerwhich just defaults to FSTREAM_URL (rather than switch to FSTREAM_TESTNET_URL)

   def futures_socket(self):
        """Start a websocket for futures data

            https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams

        :returns: connection key string if successful, False otherwise

        Message Format - see Binance API docs for all types
        """
        return self._get_account_socket('futures', stream_url=self.FSTREAM_URL)

It would be nice if it automatically selected the testnet if specified in the client.

I've hacked mine work it to work, by adding new start_testnet_socket/ futures_testnet_socket functions to the ThreadedWebsocketManager / ThreadedWebsocketManager, but it's not pretty.

Seems like it should really something along the lines of the _get_futures_socketto get the correct url.

Thanks, Jamie

cuongitl commented 3 years ago

It's easy to solved this issue: IN steams.py::: def futures_socket(self)

add:

        if self.testnet:
            return self._get_account_socket('futures', stream_url=self.FSTREAM_TESTNET_URL)

before the line: return self._get_account_socket('futures', stream_url=self.FSTREAM_URL)