예제 #1
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        ts = time.time()
        await self.connect()

        data = {'timestamp': timestamp, 'delta': True, BID: {}, ASK: {}}
        book_delta_convert(delta, data, convert=self.numeric_type)
        data = json.dumps(data)
        await self.redis.zadd(f"{self.key}-{feed}-{pair}", ts, data, exist=self.redis.ZSET_IF_NOT_EXIST)
예제 #2
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        await self.connect()

        data = {'timestamp': timestamp, 'delta': True, BID: {}, ASK: {}}
        book_delta_convert(delta, data, convert=self.numeric_type)

        data = json.dumps(data)
        await self.redis.xadd(f"{self.key}-{feed}-{pair}", {'data': data})
예제 #3
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        await self._connect()

        data = {'timestamp': timestamp, 'delta': True, BID: {}, ASK: {}}
        book_delta_convert(delta, data)

        data = json.dumps(data).encode('utf8')
        topic = f"{self.key}-{feed}-{pair}" if self.key else f"book-{feed}-{pair}"
        await self.producer.send_and_wait(topic, data)
예제 #4
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        await self.connect()
        data = {'timestamp': timestamp, BID: {}, ASK: {}}
        book_delta_convert(delta, data)
        upd = {'feed': feed, 'pair': pair, 'delta': True, 'data': data}

        await self.conn.default_exchange.publish(
            aio_pika.Message(body=f'book {json.dumps(upd)}'.encode()),
            routing_key='cryptofeed')
예제 #5
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        if self.redis is None:
            self.redis = await aioredis.create_redis_pool(
                f'redis://{self.host}:{self.port}')

        data = {'timestamp': timestamp, 'delta': True, BID: {}, ASK: {}}
        book_delta_convert(delta, data)

        data = json.dumps(data)
        await self.redis.xadd(f"{self.key}-{feed}-{pair}", {'data': data})
예제 #6
0
 async def __call__(self, *, feed: str, pair: str, delta: dict,
                    timestamp: float, receipt_timestamp: float):
     data = {
         'timestamp': timestamp,
         'receipt_timestamp': receipt_timestamp,
         'delta': True,
         BID: {},
         ASK: {}
     }
     book_delta_convert(delta, data, convert=self.numeric_type)
     await self.write(feed, pair, timestamp, receipt_timestamp, data)
예제 #7
0
 async def __call__(self, *, feed, pair, delta, timestamp):
     start = f"{self.key}-{feed},pair={pair},delta=True"
     data = {BID: {}, ASK: {}}
     book_delta_convert(delta, data)
     for side in (BID, ASK):
         for price, val in data[side].items():
             if isinstance(val, dict):
                 for order_id, amount in val.items():
                     await self.write(f'{start} side="{side}",id="{order_id}",timestamp={timestamp},price="{price}",amount="{amount}"')
             else:
                 await self.write(f'{start} side="{side}",price="{price}",timestamp={timestamp},amount="{val}"')
예제 #8
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        data = {
            'timestamp': timestamp,
            'feed': feed,
            'pair': pair,
            'delta': True,
            BID: {},
            ASK: {}
        }
        book_delta_convert(delta, data, convert=lambda x: str(int(x * 10000)))

        await self.db[self.collection].insert_one(data)
예제 #9
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        data = {'timestamp': timestamp, BID: {}, ASK: {}}
        book_delta_convert(delta, data)
        upd = {
            'type': 'book',
            'feed': feed,
            'pair': pair,
            'delta': True,
            'data': data
        }

        await self.con.send_json(upd)
예제 #10
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        ts = time.time()

        if self.redis is None:
            self.redis = await aioredis.create_redis_pool(
                f'redis://{self.host}:{self.port}')

        data = {'timestamp': timestamp, 'delta': True, BID: {}, ASK: {}}
        book_delta_convert(delta, data)
        data = json.dumps(data)
        await self.redis.zadd(f"{self.key}-{feed}-{pair}",
                              ts,
                              data,
                              exist=self.redis.ZSET_IF_NOT_EXIST)
예제 #11
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        data = {BID: {}, ASK: {}}

        book_delta_convert(delta, data, convert=self.numeric_type)
        data = book_flatten(feed, pair, data, timestamp, True)

        data = itertools.chain(*zip([json.dumps({"index": {}})] *
                                    len(data), [json.dumps(d) for d in data]))
        data = '\n'.join(data)
        data = f"{data}\n"

        await self.write('POST',
                         data,
                         headers={'content-type': 'application/x-ndjson'})
예제 #12
0
    async def __call__(self, *, feed, pair, delta, timestamp,
                       receipt_timestamp):
        delta_update = {"bid": [], "ask": []}
        for side in (BID, ASK):
            for price, size in delta[side]:
                if price in self.book[pair][side]:
                    size_delta = size - self.book[pair][side][price]

                else:
                    size_delta = size

                if abs(size_delta) > 0:
                    delta_update[side].append((price, size_delta))

        data = {'timestamp': timestamp, 'delta': True, BID: {}, ASK: {}}
        book_delta_convert(delta_update, data, convert=self.numeric_type)
        await self.write(feed, pair, timestamp, receipt_timestamp, data)
예제 #13
0
 async def __call__(self, *, feed, pair, delta, timestamp):
     data = {'timestamp': timestamp, 'delta': True, BID: {}, ASK: {}}
     book_delta_convert(delta, data, convert=self.numeric_type)
     await self.write(feed, pair, timestamp, data)
예제 #14
0
 async def __call__(self, *, feed, pair, delta, timestamp):
     start = f"{self.key}-{feed},pair={pair},delta=True"
     data = {BID: {}, ASK: {}}
     book_delta_convert(delta, data)
     await self._write_rows(start, data, timestamp)
예제 #15
0
    async def __call__(self, *, feed, pair, delta, timestamp):
        data = {'timestamp': timestamp, BID: {}, ASK: {}}
        book_delta_convert(delta, data)
        upd = {'feed': feed, 'pair': pair, 'delta': True, 'data': data}

        await self.con.send_string(f'book {json.dumps(upd)}')