async def _write_rows(self, start, data, timestamp): msg = [] ts = int(timestamp * 1000000000) for side in (BID, ASK): for price, val in data[side].items(): if isinstance(val, dict): for order_id, amount in val.items(): if self.numeric_type is str: msg.append( f'{start} side="{side}",id="{order_id}",timestamp={timestamp},price="{price}",amount="{amount}" {ts}' ) elif self.numeric_type is float: msg.append( f'{start} side="{side}",id="{order_id}",timestamp={timestamp},price={price},amount={amount} {ts}' ) else: raise UnsupportedType( f"Type {self.numeric_type} not supported") ts += 1 else: if self.numeric_type is str: msg.append( f'{start} side="{side}",timestamp={timestamp},price="{price}",amount="{val}" {ts}' ) elif self.numeric_type is float: msg.append( f'{start} side="{side}",timestamp={timestamp},price={price},amount={val} {ts}' ) else: raise UnsupportedType( f"Type {self.numeric_type} not supported") ts += 1 await self.http_write('POST', '\n'.join(msg), self.headers)
async def __call__(self, *, feed: str, pair: str, bid: Decimal, ask: Decimal, timestamp: float): bid = str(bid) ask = str(ask) if self.numeric_type is str: ticker = f'{self.key}-{feed},pair={pair} bid="{bid}",ask"{ask}",timestamp={timestamp}' elif self.numeric_type is float: ticker = f'{self.key}-{feed},pair={pair} bid={bid},ask={ask},timestamp={timestamp}' else: raise UnsupportedType(f"Type {self.numeric_type} not supported") await self.write('POST', ticker)
async def __call__(self, *, feed: str, pair: str, side: str, amount: Decimal, price: Decimal, order_id=None, timestamp=None): amount = str(amount) price = str(price) if order_id is None: order_id = 'None' if self.numeric_type is str: trade = f'{self.key}-{feed},pair={pair} side="{side}",id="{order_id}",amount="{amount}",price="{price}",timestamp={timestamp}' elif self.numeric_type is float: trade = f'{self.key}-{feed},pair={pair} side="{side}",id="{order_id}",amount={amount},price={price},timestamp={timestamp}' else: raise UnsupportedType(f"Type {self.numeric_type} not supported") await self.write(trade)
async def __call__(self, *, feed, pair, **kwargs): data = f"{self.key}-{feed},pair={pair} " for key, val in kwargs.items(): if key in {'feed', 'pair'}: continue if isinstance(val, (Decimal, float)): val = str(val) if self.numeric_type is str: val = f'"{val}"' elif self.numeric_type is not float: raise UnsupportedType(f"Type {self.numeric_type} not supported") elif isinstance(val, str): val = f'"{val}"' data += f"{key}={val}," data = data[:-1] await self.write(data)