-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Websocket support #57
Comments
Is there anywhere I can read up on |
No, it's not documented yet, the Websocket API is still in development by Bittrex. There are other methods, but they require authentication and there's no current way to authenticate yet. Bittrex does this on the website when you login. So, coreHub and those states are the only entry types available to us at this time. |
The code works. I adapted it to a little class: from requests import Session
from signalr import Connection
class WebsocketAPI(object):
url = 'http:https://socket.bittrex.com/signalr'
def __init__(self, market, timeout=120000):
with Session() as session:
self.connection = Connection(self.url, session)
self.corehub = self.connection.register_hub('coreHub')
self.connection.received += self.debug
self.connection.error += self.error
self.connection.start()
self.corehub.server.invoke('SubscribeToExchangeDeltas', market)
self.corehub.client.on('updateSummaryState', self.ticker)
self.corehub.client.on('updateExchangeState', self.market)
self.connection.wait(timeout)
def error(self, error):
print(error)
def debug(self, *args, **kwargs):
print('debug', args, kwargs)
def ticker(self, *args, **kwargs):
print('ticker', args, kwargs)
def market(self, *args, **kwargs):
print('market', args, kwargs) Useful. Thanks for pointing this out. This is a nice firehose for me. Much appreciated. |
No problem, happy to help. |
I think this issue should stay open; we should get support for this into this library one way or the other. Maybe @ericsomdahl wants to weigh in. This is the future though ;P |
Ah, my mistake. I didn't realise you weren't the maintainer. |
@dparlevliet and @skyl thank you for the code! Are you able to clarify what the different 'Type' are? E.g 'Type': 0 or 'Type': 1. [Edit]
|
Sorry. Yep, that's correct. |
Hi, almost finished my implementation.... now just working on getting a snapshot of the market to then add the deltas to, for this I'm doing hub.server.invoke('QueryExchangeState', market). I get the snapshot back successfully, but it always comes back with an empty MarketName, so matching these up with the correct deltas is difficult. Has anyone else experienced this? |
Get an order book snapshot from the API and compare one of the sides (Bid/Ask) to that of the Websocket snapshot. |
Is anyone else experiencing this?
I don't think I've changed anything. I'm thinking maybe Bittrex is under heavy load in the last couple of days and shut it down. Is it just me? |
I didn't notice the connection token parameter before. This is what gets sent from the website now:
|
I will reference it here, too, for continuity n0mad01/node.bittrex.api#67 (comment) |
@dparlevliet is my hero. So, altogether, I have working, as of right now, for ticker data for example:
Then, I subclass
|
python script is not working anymore as of today, something wrong after changes they've made on their website this morning. https://twitter.com/BittrexExchange/status/932173635447431168 |
Just checked mine, and mine still works |
any chance you can leave your code here? |
Did some more testing, it seems SubscribeToExchangeDeltas does work but updateSummaryState does not, do you have updateSummaryState working with python atm? I am very interested in this please |
Ah, I'm not using updateSummaryState, only updateExchangeState, SubscribeToExchangeDeltas and QueryExchangeState. Seems like they might have changed updateSummaryState then :( |
yeah thought so :( it is not working anymore damnit. Anyone found a solution yet? |
Hrm. Yeah, confirmed that I'm not getting any data anymore. The connection seems to happen just fine; but, |
Paging Dr. @dparlevliet ... any idea where 'updateSummaryState' got off to? |
Ty so much for confirming skyl, I have been looking for around 3 hours but I can not find anything. Lets hope dparlevliet has an idea. |
the last time i received something from updateSummaryState seems to be around "2017-11-19T07:38:35.93Z" |
Yeah that is exactly when mine stopped as well, also this might be related to the Bittrex tweet around that time. https://twitter.com/BittrexExchange/status/932173635447431168 So I guess they've changed the endpoint to something else, because there must be something that they use themselfs to get volume, high, low etc etc |
taken from the refered post:
|
anybody able to translate this to python: check from line 270 |
no one yet? |
@p0nt I've created a basic websocket client. You can check it here python-bittrex-websocket. |
import asyncio
import json
import time
import aiohttp
SOCKET_URL = 'https://socket.bittrex.com/signalr/'
SOCKET_HUB = 'corehub'
async def socket(tickers):
"""
Uses signalr protocol: https://github.com/TargetProcess/signalr-client-py
https://github.com/slazarov/python-bittrex-websocket/blob/master/bittrex_websocket/websocket_client.py
"""
conn_data = json.dumps([{'name': SOCKET_HUB}])
async with aiohttp.ClientSession() as session:
url = SOCKET_URL + 'negotiate' + '?' + urlencode({
'clientProtocol': '1.5',
'connectionData': conn_data,
'_': round(time.time() * 1000)
})
async with session.get(url) as r:
socket_conf = await r.json()
socket_url = SOCKET_URL.replace('https', 'wss') + 'connect' + '?' + urlencode({
'transport': 'webSockets',
'clientProtocol': socket_conf['ProtocolVersion'],
'connectionToken': socket_conf['ConnectionToken'],
'connectionData': conn_data,
'tid': 3
})
async with session.ws_connect(socket_url) as ws:
for n, ticker in enumerate(tickers, start=1):
message = {
'H': SOCKET_HUB,
'M': 'SubscribeToExchangeDeltas',
'A': [ticker],
'I': n
}
await ws.send_str(json.dumps(message))
async for msg in ws:
print(msg.type, msg.data)
if __name__ == '__main__':
ioloop = asyncio.get_event_loop()
ioloop.run_until_complete(socket(['BTC-ETH', 'BTC-NEO'])) |
Is there any updateSummaryState equivalent? |
@skyl can you test |
@slazarov works for me. |
awesome man looks good, so this means you can not use "updateSummaryState" anymore without mentioning tickers, which previously just updated all bittrex tickets instead of chosen one? |
@p0nt I was testing it yesterday. Trying to invoke 'SubscribeToSummaryDeltas' with the specific tickers results in an error. In another words, you will receive the summary state deltas for all the updated tickers on the exchange. Bittrex seems to constantly change it. |
Ah thats great! I am looking for that to just get all tickers summary info instead of just the one I subscribe to. Thank yuu! |
For QueryExchangeState, is the solution really to get the orderbook from rest api and compare the colums? I suppose i need to do a QueryExchangeState and not just a rest call in order to get the right nonces? A weird thing too is that when i do a QueryExchangeState i also receive updateExchangeState stuff as if i had called it...(i guess i don't have to call it then, if i can get queryexchangestate to start telling me anyway and i can only figure out which market it is...) |
Also this was the only way i managed to be notified of what QueryExchangeState spits out: connection.received += getOrderBooks Any ideas? |
@hippylover there are two solutions. Firstly, you can get the order book from the REST API and compare it. Secondly, you can track the QueryExchangeState invokes and know which order book snapshot to expect next. Both have pros and cons. REST API
Websocket Invoke
In any case, if you scroll up you would see that I have posted a link to a websocket library which you can test. @ericsomdahl I don't want to hijack the thread by referring people to my library, not my point really. My idea is to get people to test the library which is solely written for that, iron out bugs/issues and combine at some point. |
@slazarov no worries. I hope for your lib to merge here eventually... Or at least become the "officially recognized" python implementation for websocket support, depending on your preference. |
@slazarov this code was working for a while but doesn't work anymore:
I'm guess Bittrex changed something again? When I print/log in |
@skyl I have released v0.0.2, please check the repo, reinstall through pip, read the new documentation and tell me if you are experiencing the issue. |
@slazarov I have something working again. I'm using master / 0.0.3. It seems like if I try to subscribe to all the markets I get a lot of:
Do you know what this is referring to? If I just subscribe to a couple of markets this doesn't seem to happen ... I guess we could take this conversation up in your repo ... |
@skyl Move the issue to the correct repo and provide the code you are using so I could replicate it (it's important to know which subscribe method you are using). The error might be caused by a lot of factors, conflicts with gevent or maybe something outdate within the SignalR library which uses gevent. |
@nanvel have you gotten your async code to work still? it seems that right now the DDOS protection page is screwing it up. |
@halcyonjuly7 it was working before. I don't use this API anymore. DDOS protection page should have no relation to the API IMHO. |
@halcyonjuly7 I see "503 Service Temporarily Unavailable" in response. So, probably, will be available soon. |
@nanvel one would think that. but using the code you provided a month ago. you called so what endpoint are you using now? |
@halcyonjuly7 I see the same page "Checking your browser before accessing bittrex.com." now. |
@slazarov Have you found a workaround for this? I'm now seeing:
We had something going with cfscrape before but that got broken too ... |
@skyl it should be fixed now. Update to v0.0.5.1 |
Guys I used ws feature with https://github.com/zolzolwik/node.bittrex.api for a few days and there was a moment when it was died :( And they use |
I've confirmed that a websocket connection can be make to an authenticated/private call (ie. chat.server.invoke('QueryBalanceState')) Though making this headless is a bit of a challenge re: recaptcha + google authenticator. Cookies seem to last 2-3 hours and could possibly be refreshed though. |
Sorry, i don't really understand what should i do with connection.wait() if i want listen sockets forever. Can anybody explain? |
Hi, can you please how to get the connectionToken? |
For some reason someone asked me on the nodejs package how to do websockets in python, they provided some code to get started and I was able to fix it so I thought you guys might be interested in using it dparlevliet/node.bittrex.api#24
The text was updated successfully, but these errors were encountered: