예제 #1
0
    def websocket_connect(self, event):
        self.send({
            "type": "websocket.accept",
        })

        r = redis.StrictRedis(host=LOCAL_SERVICE_HOST, port=REDIS_DEFAULT_PORT, db=0)
        # r = redis.Redis(connection_pool=conn_r)
        p = r.pubsub()
        while 1:
            p.psubscribe('s-*')
            # After the connect with client was established open connect to MongoDB
            all_the_current_keys = approved_keys()
            # Register.
            try:
                while True:
                    message = p.get_message()
                    if message:
                        msg = dict(message)['data']
                        if msg == 1:
                            continue
                        else:
                            msg = dict(message)['data'].decode('utf-8')
                            exch = str(msg.split('/')[1])
                            pair = str(msg.split('/')[2])
                            pretick = r.get(msg)
                            tick = str(pretick.decode('utf-8'))
                        if msg in all_the_current_keys:
                            self.send({
                                "type": "websocket.send",
                                "text": json.dumps([exch + '/' + pair, tick]),
                            })
            except BaseException:
                pass
예제 #2
0
async def handler(websocket, path):
    websockets_all.append(websocket)
    r = aredis.StrictRedis(host=LOCAL_SERVICE_HOST,
                           port=REDIS_DEFAULT_PORT,
                           db=0)
    # r = redis.Redis(connection_pool=conn_r)
    p = r.pubsub()
    await p.psubscribe('s-*')
    # After the connect with client was established open connect to MongoDB
    all_the_current_keys = approved_keys()
    # Register.
    try:
        while True:
            message = await p.get_message()
            if message:
                msg = dict(message)['data']
                if msg == 1:
                    continue
                else:
                    msg = dict(message)['data'].decode('utf-8')
                    exch = str(msg.split('/')[1])
                    pair = str(msg.split('/')[2])
                    pretick = await r.get(msg)
                    tick = str(pretick.decode('utf-8'))
                if msg in all_the_current_keys:
                    await websocket.send(json.dumps([exch + '/' + pair, tick]))
                #else:
                #  pass
    #
    finally:
        # Unregister.
        pass
예제 #3
0
async def arbitration_socket(websocket, path):
    websockets_all.append(websocket)
    conn_r = redis.ConnectionPool(host=LOCAL_SERVICE_HOST,
                                  port=REDIS_DEFAULT_PORT,
                                  db=0)
    r = redis.Redis(connection_pool=conn_r)
    p = r.pubsub()
    p.psubscribe('s-*')
    # After the connect with client was established open connect to MongoDB
    all_the_current_keys = approved_keys()
    while True:
        message = p.get_message()
        if message:
            try:
                try:
                    msg = dict(message)['data'].decode('utf-8')
                except AttributeError:
                    continue
                if msg in all_the_current_keys:
                    for websocket in websockets_all:
                        await websocket.send(
                            json.dumps([
                                msg.split('/')[1] + '/' + msg.split('/')[2],
                                r.get(msg).decode('utf-8')
                            ]))
            except TypeError:
                pass
        time.sleep(0.001)
예제 #4
0
 def get(self, request, mode="", *args, **kwargs):
     if mode == 'new':
         return render(
             request, 'comparebeta.html',
             {})  # установить compare для другого отображения арбитража
     else:
         return render(
             request, 'compare.html', {
                 'pairs': json.dumps(sorted(approved_pairs())),
                 'exchs': json.dumps(sorted(approved_exchanges())),
                 'ticks': json.dumps(state_getter(keys(approved_keys())))
             })