public static PriceQuoteUnits Parse(string quoteUnitsAsString)
        {
            var quoteUnitsEnum = PriceQuoteUnitsEnum.Undefined;

            if (quoteUnitsAsString != null)
            {
                quoteUnitsEnum = PriceQuoteUnitsScheme.ParseEnumString(quoteUnitsAsString);
            }
            return(new PriceQuoteUnits {
                Value = quoteUnitsEnum.ToString()
            });
        }
示例#2
0
        protected RequestContext ConvertStandardAssetQuotesToProviderInstrFieldCodes(
            MDSRequestType requestType,
            QuotedAssetSet standardQuotedAssetSet)
        {
            // extract assets/quotes that require market quotes
            var standardAssets = new List <Asset>();
            var standardQuotes = new List <BasicQuotation>();
            {
                // build a request/response map (indexed by instrument id)
                var instrumentMap = new Dictionary <string, Asset>();
                //List<Pair<Asset, BasicQuotation>> completeAssetQuotes = new List<Pair<Asset, BasicQuotation>>();

                foreach (Asset asset in standardQuotedAssetSet.instrumentSet.Items)
                {
                    instrumentMap[asset.id.ToLower()] = asset;
                }
                foreach (BasicAssetValuation quoteInstr in standardQuotedAssetSet.assetQuote)
                {
                    string instrId = quoteInstr.objectReference.href;
                    if (!instrumentMap.TryGetValue(instrId.ToLower(), out var asset))
                    {
                        throw new ApplicationException($"Cannot find instrument '{instrId}' for assetQuote");
                    }
                    foreach (BasicQuotation quoteField in quoteInstr.quote)
                    {
                        if (quoteField.valueSpecified)
                        {
                            // value provided - don't get from market
                            //completeAssetQuotes.Add(new Pair<Asset, BasicQuotation>(asset, quoteField));
                        }
                        else
                        {
                            // value not supplied - get from market
                            BasicQuotation quote = BasicQuotationHelper.Clone(quoteField);
                            standardAssets.Add(asset);
                            standardQuotes.Add(quote);
                        }
                    }
                }
            }
            var requestItems       = new List <RequestItem>();
            var instrConversionMap = new Dictionary <string, string>();
            var instrUniquenessMap = new Dictionary <string, string>();
            var internalInstrIds   = new List <string>();
            var fieldConversionMap = new Dictionary <string, string>();
            var fieldUniquenessMap = new Dictionary <string, string>();
            var internalFieldIds   = new List <string>();

            Logger.LogDebug("    Mappings    :");
            for (int i = 0; i < standardAssets.Count; i++)
            {
                // map asset to provider instrument id
                Asset  standardAsset   = standardAssets[i];
                string internalInstrId = standardAsset.id;
                internalInstrIds.Add(internalInstrId);
                string providerInstrId = _marketDataMap.Convert(
                    MDSDictionaryType.Instrument, requestType,
                    MDSProviderId.GlobalIB, ProviderId, internalInstrId,
                    ConvertFailMode.ThrowException);
                // update 1-way map
                instrConversionMap[internalInstrId.ToLower()] = providerInstrId;
                instrUniquenessMap[providerInstrId.ToLower()] = providerInstrId;
                // map quote to provider field name
                BasicQuotation standardQuote   = standardQuotes[i];
                string         internalFieldId = standardQuote.GetStandardFieldName();
                internalFieldIds.Add(internalFieldId);
                string providerFieldId = _marketDataMap.Convert(
                    MDSDictionaryType.FieldName, requestType,
                    MDSProviderId.GlobalIB, ProviderId, internalFieldId,
                    ConvertFailMode.ThrowException);
                // update 1-way map
                fieldConversionMap[internalFieldId.ToLower()] = providerFieldId;
                fieldUniquenessMap[providerFieldId.ToLower()] = providerFieldId;
                // get provider units
                string providerUnitsId = _marketDataMap.Convert(
                    MDSDictionaryType.QuoteUnits, requestType,
                    MDSProviderId.GlobalIB, ProviderId, String.Format("{0}/{1}", internalInstrId, internalFieldId),
                    ConvertFailMode.ThrowException);
                var requestItem = new RequestItem
                {
                    StandardAsset        = standardAsset,
                    StandardQuote        = standardQuote,
                    StandardUnits        = PriceQuoteUnitsScheme.ParseEnumString(standardQuote.quoteUnits.Value),
                    ProviderInstrumentId = providerInstrId,
                    ProviderFieldName    = providerFieldId,
                    ProviderUnits        = PriceQuoteUnitsScheme.ParseEnumString(providerUnitsId)
                };
                requestItems.Add(requestItem);
                // debug
                Logger.LogDebug("      [{0}] '{1}/{2}' ({3}) --> '{4}/{5}' ({6})", i,
                                internalInstrIds[i], internalFieldIds[i], standardQuote.quoteUnits.Value,
                                instrConversionMap[internalInstrIds[i].ToLower()], fieldConversionMap[internalFieldIds[i].ToLower()], providerUnitsId);
                // end debug
            }
            var providerInstrIds = new List <string>(instrUniquenessMap.Values);
            var providerFieldIds = new List <string>(fieldUniquenessMap.Values);
            // build provider instr/field code sets - todo - for now just build 1
            var results = new List <ProviderInstrFieldCodeSet>();
            var result  = new ProviderInstrFieldCodeSet(providerInstrIds, providerFieldIds);

            results.Add(result);
            return(new RequestContext
            {
                RequestItems = requestItems,
                ProviderInstrFieldCodeSets = results,
                InstrConversionMap = instrConversionMap,
                FieldConversionMap = fieldConversionMap
            });
        }
示例#3
0
        public void ImportRules(ProviderRuleSet mapRuleSet)
        {
            ClearRules(mapRuleSet.provider);
            if (mapRuleSet.rules != null)
            {
                foreach (QRMarketDataMap rule in mapRuleSet.rules)
                {
                    MDSDictionaryType dictType = rule.dictType;
                    switch (dictType)
                    {
                    case MDSDictionaryType.FieldName:
                        AddFieldMap(rule.priority, rule.requestType, rule.sourcePattern, rule.outputValue);
                        break;

                    case MDSDictionaryType.Instrument:
                        AddInstrMap(rule.priority, rule.sourcePattern, rule.outputValue);
                        break;

                    case MDSDictionaryType.QuoteUnits:
                        AddUnitsMap(rule.priority, rule.requestType, rule.sourcePattern, PriceQuoteUnitsScheme.ParseEnumString(rule.outputValue));
                        break;

                    default:
                        throw new NotSupportedException("DictionaryType: " + dictType.ToString());
                    }
                }
            }
            // import done
            SortRules();
        }