async def write(self, feed, pair, timestamp, receipt_timestamp, data): if 'timestamp' in data: data['timestamp'] = f"{dt.fromtimestamp(data['timestamp'], tz=tz.utc).isoformat()}Z" if 'receipt_timestamp' in data: data['receipt_timestamp'] = f"{dt.fromtimestamp(data['receipt_timestamp'], tz=tz.utc).isoformat()}Z" timestamp = f"{dt.fromtimestamp(timestamp, tz=tz.utc).isoformat()}Z" receipt_timestamp = F"{dt.fromtimestamp(receipt_timestamp, tz=tz.utc).isoformat()}Z" data = book_flatten(feed, pair, data, timestamp, True) await self.write_bulk(data)
async def write(self, data): if 'timestamp' in data and data['timestamp']: data[ 'timestamp'] = f"{dt.fromtimestamp(data['timestamp'], tz=tz.utc).isoformat()}Z" data[ 'receipt_timestamp'] = f"{dt.fromtimestamp(data['receipt_timestamp'], tz=tz.utc).isoformat()}Z" data = book_flatten(data['exchange'], data['symbol'], data['book'] if 'book' in data else data['delta'], data['timestamp'], 'delta' in data) await self.write_bulk(data)
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'})
async def __call__(self, *, feed, pair, book, timestamp): if self.redis is None: self.redis = await aioredis.create_redis_pool(f'redis://{self.host}:{self.port}') data = {'timestamp': timestamp, BID: {}, ASK: {}} book_convert(book, data, self.depth) if self.depth: if data[BID] == self.previous[BID] and data[ASK] == self.previous[ASK]: return self.previous[ASK] = data[ASK] self.previous[BID] = data[BID] flat = book_flatten(data, data['timestamp']) for update in flat: await self.redis.xadd(f"{self.key}-{feed}-{pair}", update)
async def __call__(self, *, feed, pair, book, timestamp): data = {BID: {}, ASK: {}} book_convert(book, data, self.depth, convert=self.numeric_type) if self.depth: if data[BID] == self.previous[BID] and data[ASK] == self.previous[ ASK]: return self.previous[ASK] = data[ASK] self.previous[BID] = data[BID] data = book_flatten(feed, pair, data, timestamp, False) 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'})
async def write(self, feed, pair, timestamp, data): data = book_flatten(feed, pair, data, timestamp, True) await self.write_bulk(data)
async def write(self, feed, pair, timestamp, receipt_timestamp, data): data = book_flatten(feed, pair, data, timestamp, False) await self.write_bulk(data)