def get_marks(self, instrument: ExchangeInstrument) -> Signal: if self.mark_type == MarkType.LAST: trades = self.mds.get_trades(instrument) return Map(self.network, trades, lambda x: Mark(instrument.get_instrument(), x.get_price())) else: books = self.mds.get_order_books(instrument) return Map(self.network, books, lambda x: Mark(instrument.get_instrument(), x.get_mid()))
def get_marks(self, instrument: ExchangeInstrument) -> Signal: economics = instrument.get_instrument().get_economics() if isinstance(economics, FutureContract): economics = economics.get_underlier().get_economics() if isinstance(economics, CurrencyPair): ccy_code = economics.get_base_currency().get_currency_code() symbol = f'.M{ccy_code}' cash_instrument = self.instrument_cache.get_or_create_cash_instrument( ccy_code) else: raise ValueError( 'Unable to get marks: expected CurrencyPair or FutureContract on CurrencyPair' ) network = self.scheduler.get_network() marks = self.instrument_marks.get(symbol) if marks is None: marks = MutableSignal() network.attach(marks) self.instrument_marks[symbol] = marks subscribe_msg = { 'id': 1, 'method': 'tick.subscribe', 'params': [symbol] } messages = MutableSignal() json_messages = Map(network, messages, lambda x: json.loads(x)) tick_messages = Filter(network, json_messages, lambda x: 'tick' in x) ticks = Map( network, tick_messages, lambda x: self.__extract_tick( x, cash_instrument.get_instrument())) Pipe(self.scheduler, ticks, marks) asyncio.ensure_future( websocket_subscribe_with_retry(self.ws_uri, self.timeout, self.logger, subscribe_msg, self.scheduler, messages, symbol, 'ticks')) return marks