python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

Web Socket APIs not working

Open shubhankar1904 opened this issue 8 years ago • 10 comments

Hi I was trying to implement the websocket API of binance, but the APIs do not return anything. I tried using your implementation but still no luck. Is it a binance issue? or are we missing something?

shubhankar1904 avatar Jan 10 '18 06:01 shubhankar1904

Hi Shubhankar, are you using the websocket correctly? Can you please post your code without keys? kindly just send the code from client construction and the additional line to call to the websocket till bm.start()

Kato-Official avatar Jan 10 '18 08:01 Kato-Official

Hi PFB the code i'm trying with your implementation `` from binance.websockets import BinanceSocketManager from binance.client import Client

class test:

def process_message(msg):
	print("message type: {}".format(msg['e']))
	print(msg)
	# do something
	

bm = BinanceSocketManager(Client('xxx','yyy'))
# start any sockets here, i.e a trade socket
conn_key = bm.start_trade_socket('BNBBTC', process_message)
# then start the socket manager
bm.start()
bm.close()

``

shubhankar1904 avatar Jan 10 '18 10:01 shubhankar1904

Make sure you imported both below

from binance.client import Client from binance.websockets import BinanceSocketManager

#Start your client separately like below not in the same bm.start..... client = Client('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') #set the function like below, you will sort it later def process_message(msg): print(msg) #Start socket manager like below bm = BinanceSocketManager(client)

#Create connection key variable like below conn_key = bm.start_trade_socket('BNBBTC',process_message) #start it bm.start()

#Do not put bm.close() and run the code and see what you get , you can copy paste and just replace the xxxxxxxxxxxxxxxxxxxxxxxxx with your keys

#Let me know how it goes. #Cheers

Kato-Official avatar Jan 10 '18 10:01 Kato-Official

#Also give it few seconds to get the info, on mine sometimes it take a little while, just be patient :)

Kato-Official avatar Jan 10 '18 10:01 Kato-Official

Oh....that was silly, putting close right after open. I removed that and put a few print statements in the code.

I'm getting the following error in clientConnectionFailed method in socket manager

" [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionRefusedError'> : Connection was refused by other side: 10061: No connection could be made because the target machine actively refused it.. ] "

shubhankar1904 avatar Jan 10 '18 12:01 shubhankar1904

#I am assuming that you are already registered with Binance and that you have the right keys #Try to check that you have correctly inserted you API keys,etc in the client = Client('xxxxxxx, xxxxxxxxx #make sure you inserted them as strings, with the the quotation mark at the beginning and at the end of each of the 2 arguments. #The only reason which I can think of for which Binance is refusing your connection is that it did not received the right keys from the socket you are creating.

Kato-Official avatar Jan 10 '18 12:01 Kato-Official

i debugged it. Apparently my connection was via a proxy. I used a direct connection and it worked like a charm. Thanks a lot @SkylerX for all the help, and quick responses.

shubhankar1904 avatar Jan 10 '18 12:01 shubhankar1904

You're welcome! Cheers

Kato-Official avatar Jan 10 '18 12:01 Kato-Official

@shubhankar1904 can you post the code for how you got around the proxy/where you found info on direct connection?

mpias670 avatar Feb 20 '18 18:02 mpias670

You cannot. That is still an issue. I did speak to my network admin and the ports can be exposed to allow such a connection. But it required certain approvals hence I started using aws.

On 20 Feb 2018 11:32 pm, "klop670" [email protected] wrote:

@shubhankar1904 https://github.com/shubhankar1904 can you post the code for how you got around the proxy/where you found info on direct connection?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sammchardy/python-binance/issues/97#issuecomment-367064337, or mute the thread https://github.com/notifications/unsubscribe-auth/AMw_g6ruroyq_BY0E55KwZjdC84L8vOoks5tWwidgaJpZM4RY2Gl .

shubhankar1904 avatar Feb 23 '18 01:02 shubhankar1904