示例#1
0
        private void OnMarketDataResolved(AdapterEventArgs <InformationReport> args)
        {
            using (resolutionRequestsLock.Lock())
            {
                if (!resolutionRequestsById.TryGetValue(args.Message.id, out var request))
                {
                    return;
                }

                resolutionRequestsById.Remove(args.Message.id);

                var resolvedSymbol = args.Message.symbol_resolution_report.contract_metadata.contract_symbol;

                if (resolvedSymbol.EndsWith(request.Symbol))
                {
                    request.TrySetResult(SubscriptionTestResult.Passed(
                                             ContractMetadataToString(args.Message.symbol_resolution_report.contract_metadata))
                                         );
                }
                else
                {
                    request.TrySetResult(SubscriptionTestResult.Failed(
                                             ContractMetadataToString(args.Message.symbol_resolution_report.contract_metadata))
                                         );
                }
            }

            //request.TrySetResult(Tuple.Create(true,args.Message.ToString()));
            args.MarkHandled();
        }
示例#2
0
        /// <summary>
        ///     Проверить подписку
        /// </summary>
        async Task <SubscriptionTestResult> ISubscriptionTester <IQFeedInstrumentData> .TestSubscriptionAsync(IQFeedInstrumentData data)
        {
            using (LogManager.Scope())
            {
                await securityTypeIndexCompleted.Task;

                if (!securityTypeIndex.TryGetValue(data.SecurityType, out var typeId))
                {
                    var message = LogMessage.Format($"Failed to find an identifier for {data.SecurityType}").ToString();
                    Logger.Warn().Print(message);
                    return(SubscriptionTestResult.Failed(message));
                }

                var operation = new SubscriptionTest(data.Symbol, data.SecurityType);
                var requestId = LookupSocketWrapper.RequestIdPrefix + Guid.NewGuid().ToString("N");
                using (subscriptionTestsLock.Lock())
                {
                    subscriptionTests[requestId] = operation;
                }

                lookupSocket.RequestSymbolLookup(data.Symbol, typeId, requestId);

                var result = await operation.Task;
                if (result)
                {
                    return(SubscriptionTestResult.Passed());
                }

                return(SubscriptionTestResult.Failed());
            }
        }
示例#3
0
        /// <summary>
        ///     Проверить подписку
        /// </summary>
        Task <SubscriptionTestResult> ISubscriptionTester <InstrumentData> .TestSubscriptionAsync(InstrumentData data)
        {
            var symbol = data.Symbol;
            var result = SubscriptionTestResult.Failed();

            const int timeToWait        = 10000;
            var       isResolved        = false;
            var       source            = new CancellationTokenSource(timeToWait);
            var       cancellationToken = source.Token;

            MessageReceived += (sender, args) =>
            {
                if (args.Message.message_type == QLMessageType.InstrumentParams)
                {
                    var ip = args.Message as QLInstrumentParams;
                    if (ip.code == symbol)
                    {
                        isResolved = true;
                        source.Cancel();
                    }
                }
            };

            SendMessage(new QLInstrumentParamsSubscriptionRequest(symbol));
            cancellationToken.WaitHandle.WaitOne();

            if (isResolved)
            {
                SendMessage(new QLInstrumentParamsUnsubscriptionRequest(symbol));

                result = SubscriptionTestResult.Passed();
            }

            return(Task.FromResult(result));
        }
示例#4
0
        /// <summary>
        ///     Проверить подписку
        /// </summary>
        Task <SubscriptionTestResult> ISubscriptionTester <SpimexInstrumentData> .TestSubscriptionAsync(SpimexInstrumentData data)
        {
            using (allInstrumentLock.WriteLock())
            {
                if (!allInstruments.Contains(data.Symbol))
                {
                    return(Task.FromResult(SubscriptionTestResult.Failed()));
                }

                return(Task.FromResult(SubscriptionTestResult.Passed()));
            }
        }
示例#5
0
        /// <summary>
        ///     Проверить подписку
        /// </summary>
        Task <SubscriptionTestResult> ISubscriptionTester <InstrumentData> .TestSubscriptionAsync(InstrumentData data)
        {
            var result = SubscriptionTestResult.Failed();

            using (containerLock.ReadLock())
            {
                if (mapShortIsinToIsin.ContainsKey(data.Symbol))
                {
                    result = SubscriptionTestResult.Passed();
                }
            }

            return(Task.FromResult(result));
        }
示例#6
0
        /// <summary>
        ///     Проверить подписку
        /// </summary>
        async Task <SubscriptionTestResult> ISubscriptionTester <IBInstrumentData> .TestSubscriptionAsync(IBInstrumentData data)
        {
            if (data.Symbol == null)
            {
                return(SubscriptionTestResult.Failed("No symbol has been specified"));
            }

            // Мы ожидаем, что внешний конвертер сформирует код в формате LOCALSYMBOL

            Contract contract;

            switch (data.InstrumentType)
            {
            case IBInstrumentType.Equity:
            case IBInstrumentType.Index:
            case IBInstrumentType.Commodity:
            case IBInstrumentType.FX:
                contract = ContractContainer.GetAssetContractStub(data);
                break;

            case IBInstrumentType.Future:
                contract = ContractContainer.GetFutureContractStub(data);
                break;

            case IBInstrumentType.AssetOption:
                contract = ContractContainer.GetAssetOptionContractStub(data);
                break;

            case IBInstrumentType.FutureOption:
                contract = ContractContainer.GetFutureOptionContractStub(data);
                break;

            default:
                return(SubscriptionTestResult.Failed($"Bad instrument type: {data.InstrumentType}"));
            }

            var testResult = TestContract(contract);
            var result     = await testResult.WaitAsync();

            if (result)
            {
                return(SubscriptionTestResult.Passed());
            }

            return(SubscriptionTestResult.Failed());
        }
示例#7
0
        private void OnMarketDataNotResolved(AdapterEventArgs <InformationReport> args)
        {
            ResolutionRequest request;

            using (resolutionRequestsLock.Lock())
            {
                if (!resolutionRequestsById.TryGetValue(args.Message.id, out request))
                {
                    return;
                }

                resolutionRequestsById.Remove(args.Message.id);
            }

            request.TrySetResult(SubscriptionTestResult.Failed(args.Message.text_message));
            args.MarkHandled();
        }