slazarov / python-bittrex-websocket-aio Goto Github PK
View Code? Open in Web Editor NEWPython websocket for Bittrex (async).
Home Page: http://python-bittrex-websocket-docs.readthedocs.io/en/latest/index.html#
License: MIT License
Python websocket for Bittrex (async).
Home Page: http://python-bittrex-websocket-docs.readthedocs.io/en/latest/index.html#
License: MIT License
First of all thanks for this library - very helpful. However I'm noticing that my connections periodically close without much information as to why. Its not that big of a deal, except I don't see a way to poll the connection object to make sure that it is still connected (https://github.com/slazarov/python-signalr-client/blob/master/signalr_aio/_connection.py).
Here is the log message I'm receiving:
2019-12-27 23:35:51 - bittrex_websocket.websocket_client - INFO - Bittrex connection successfully closed.
It also doesn't appear to auto-reconnect. I'm wondering if anybody using this library has found a simple solution to improve connection stability, or to recover failed/closed connections quickly and seamlessly.
Line 42 in _transport.py can be modified to remove the loop=self.ws_loop
argument, which make the code fail in Python 3.10.
Good afternoon!
I am making a trading application and since the buy/sell orders are submitted through REST API, I wonder how to implement the authorization logic:
Thanks
Hi,
Not more that one query_summary_state is succesfully made when previosuly "authentication" is performed.
I did solve it by adding:
self.invokes.append({'invoke': invoke, 'ticker': None})
at _handle_subscribe function for the invoke == BittrexMethods.AUTHENTICATE case.
BR.
bittrex_websocket.websocket_client - INFO - Establishing connection to Bittrex through https://beta.bittrex.com/signalr.
ws.subscribe_to_orderbook(tickers)
AttributeError: 'MySocket' object has no attribute 'subscribe_to_orderbook
bittrex_websocket.websocket_client - INFO - cfscrape detected, using it to bypass Cloudflare.'
Because this happens, the record_trades and ticket_updates go correctly.
I'm getting the following error intermittently while running ~35 connections to subscribe_to_exchange_deltas
Exception in thread SocketConnection:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/dist-packages/bittrex_websocket/websocket_client.py", line 76, in _connection_handler
self.connection.conn.start()
File "/usr/local/lib/python3.6/dist-packages/signalr_aio/_connection.py", line 36, in start
self.__transport.start()
File "/usr/local/lib/python3.6/dist-packages/signalr_aio/transports/_transport.py", line 47, in start
self.ws_loop.run_until_complete(self.socket(self.ws_loop))
File "/usr/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/dist-packages/signalr_aio/transports/_transport.py", line 59, in socket
loop=loop) as self.ws:
File "/usr/local/lib/python3.6/dist-packages/websockets/client.py", line 386, in __aenter__
return (yield from self)
File "/usr/local/lib/python3.6/dist-packages/websockets/client.py", line 400, in __await__
extra_headers=protocol.extra_headers,
File "/usr/local/lib/python3.6/dist-packages/websockets/client.py", line 263, in handshake
raise InvalidStatusCode(status_code)
websockets.exceptions.InvalidStatusCode: Status code not 101: 524
Im running the example presented in this link: https://python-bittrex-websocket-docs.readthedocs.io/en/latest/howto.html (using steps 1 and 2) and I get the following error:
RuntimeWarning: coroutine 'MySocket.on_public' was never awaited
f(*a, **kw)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
It seems that this new version using asyncio depends on uvloop that is not supported in Windows systems.
C:>pip install bittrex-websocket-aio
Collecting bittrex-websocket-aio
Using cached bittrex_websocket_aio-0.0.0.2.2-py2.py3-none-any.whl
Collecting uvloop>=0.9.1 (from bittrex-websocket-aio)
Using cached uvloop-0.9.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users~\AppData\Local\Temp\pip-build-1qo1p6yg\uvloop\setup.py", line 10, in
raise RuntimeError('uvloop does not support Windows at the moment')
RuntimeError: uvloop does not support Windows at the moment
Hi,
In actual version (0.0.0.2.8), function async on_public receive 'None' in msg['M'] with subscription to 'query_exchange_state', in version 0.0.0.2.7 works OK.
You can check with:
from bittrex_websocket import BittrexSocket, BittrexMethods
from time import sleep
# Define a new method to check if we have received all the data
def are_we_finished():
ticker_cnt = len(tickers)
exch_delta_cnt = len(exchange_deltas)
summ_delta_cnt = len(summary_deltas)
if exch_delta_cnt == summ_delta_cnt:
num = (exch_delta_cnt + summ_delta_cnt) / ticker_cnt
# E.g with 2 tickers the equation will be: (2 + 2) / 2 = 2
if num == 2:
return True
return False
class MySocket(BittrexSocket):
async def on_public(self, msg):
if msg['invoke_type'] == BittrexMethods.QUERY_EXCHANGE_STATE:
name = msg['M']
if name not in exchange_deltas:
exchange_deltas[name] = msg
print('Just received exchange state for {}.'.format(name))
elif msg['invoke_type'] == BittrexMethods.SUBSCRIBE_TO_SUMMARY_DELTAS:
for summary in msg['D']:
name = summary['M']
if name in tickers and name not in summary_deltas:
summary_deltas[name] = summary
print('Just received summary delta update for {}.'.format(name))
# Add the new summary delta container
exchange_deltas = {}
summary_deltas = {}
# Create the socket instance
ws = MySocket()
# Enable logging
ws.enable_log()
# Define tickers
tickers = ['BTC-ETH', 'BTC-ZEC']
# Invoke subscriptions
ws.query_exchange_state(tickers)
ws.subscribe_to_summary_deltas()
while are_we_finished() is False:
sleep(1)
else:
print('We have received updates for all tickers. Closing...')
ws.disconnect()
sleep(10)
Randomly getting this "error", but without any exception.
Basically doesn't stop the script working but it seems I stop getting data from the private ws stream. Looks like public still stays online.
I did some research and I am trying to fix it by changing this line on websocket_client-aio.py : 136
for future in (self.futures if not (future.done() or future.cancelled())) + self.connection.conn._Connection__transport.futures
I would recommend to "merge" this effort with the CryptoFeed library.
https://github.com/bmoscon/cryptofeed
Isn't it same command with https://github.com/slazarov/python-bittrex-websocket
?
Do they use the same command to install?
Another question:
Line 59 of websocket_client.py is:
connection = Connection(BittrexParameters.URL, Session())
Shouldn't it be:
connection = Connection(self.url, Session())
?
/usr/lib/python3.6/site-packages/events/events.py:95: RuntimeWarning: coroutine 'Bittrex.on_public' was never awaited
f(*a, **kw)
^CTraceback (most recent call last):
File "async130.py", line 565, in
time.sleep(1337)
I am getting this error on 3.6.5 but strangely on 3.6.3 I dont get it.
PS: thanks for the lib, is this possible to donate BTC somewhere?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.