/// <summary> /// Обновить контракт по его метаданным /// </summary> /// <param name="metadata"> /// Метаданные контракта /// </param> /// <param name="dependentObjectDescription"> /// Строковое описание объекта, который зависит от инструмента /// </param> public async Task HandleMetadataAsync(ContractMetadata metadata, string dependentObjectDescription = null) { using (LogManager.Scope()) { _Log.Debug().Print( "Contract metadata received", LogFields.ContractId(metadata.contract_id), LogFields.Symbol(metadata.contract_symbol), LogFields.CorrectPriceScale(metadata.correct_price_scale), LogFields.DisplayPriceScale(metadata.display_price_scale) ); using (cacheLock.Lock()) { if (cachedContracts.ContainsKey(metadata.contract_id)) { _Log.Debug().Print("Already cached", LogFields.ContractId(metadata.contract_id)); return; } } Instrument instrument = await InstrumentConverter.ResolveSymbolAsync(adapter, metadata.contract_symbol, dependentObjectDescription); if (instrument == null) { _Log.Warn().Print("Instrument not resolved", LogFields.Symbol(metadata.contract_symbol)); return; } using (cacheLock.Lock()) { _Log.Debug().Print( "Caching instrument", LogFields.ContractId(metadata.contract_id), LogFields.Symbol(metadata.contract_symbol), LogFields.Instrument(instrument) ); cachedContractIds[instrument] = metadata.contract_id; cachedContracts[metadata.contract_id] = instrument; cachedContractPriceScales[metadata.contract_id] = (decimal)metadata.correct_price_scale; } OnInstrumentResolved(metadata.contract_id); } }
/// <summary> /// Обновить контракт по его метаданным /// </summary> /// <param name="metadata"> /// Метаданные контракта /// </param> public void HandleMetadata(ContractMetadata metadata) { _Log.Debug().Print( "Contract metadata received", LogFields.ContractId(metadata.contract_id), LogFields.Symbol(metadata.contract_symbol), LogFields.CorrectPriceScale(metadata.correct_price_scale), LogFields.DisplayPriceScale(metadata.display_price_scale) ); using (cacheLock.Lock()) { if (cachedContracts.ContainsKey(metadata.contract_id)) { _Log.Debug().Print("Already cached", LogFields.ContractId(metadata.contract_id)); return; } } var instrument = InstrumentConverter.ResolveSymbolAsync(adapter, metadata.contract_symbol).Result; if (instrument == null) { _Log.Warn().Print("Instrument not resolved", LogFields.Symbol(metadata.contract_symbol)); return; } using (cacheLock.Lock()) { _Log.Debug().Print( "Caching instrument", LogFields.ContractId(metadata.contract_id), LogFields.Symbol(metadata.contract_symbol), LogFields.Instrument(instrument) ); cachedContractIds[instrument] = metadata.contract_id; cachedContracts[metadata.contract_id] = instrument; cachedContractPriceScales[metadata.contract_id] = (decimal)metadata.correct_price_scale; } OnInstrumentResolved(metadata.contract_id); }