async def handle_recent_trades_update(self, exchange: str, exchange_id: str, cryptocurrency: str, symbol: str, recent_trades: list): """ Recent trades channel consumer callback """ try: mark_price = calculate_mark_price_from_recent_trade_prices( [float(last_price[ExchangeConstantsOrderColumns.PRICE.value]) for last_price in recent_trades]) await self.push(symbol, mark_price) except Exception as e: self.logger.exception(e, True, f"Fail to handle recent trades update : {e}")
async def test_calculate_mark_price_from_recent_trade_prices(): assert calculate_mark_price_from_recent_trade_prices( [10, 5, 7]) == 7.333333333333333 assert calculate_mark_price_from_recent_trade_prices([10, 20]) == 15 assert calculate_mark_price_from_recent_trade_prices([]) == 0