Exemplo n.º 1
0
        private void L1OnSystemMsg(IQMessageArgs args)
        {
            var systemMessage = args.Message;

            switch (systemMessage)
            {
            case L1SystemMsg.SERVER_CONNECTED:
                ChangeConnectionStatus(ConnectionStatus.Connected);
                break;

            case L1SystemMsg.SERVER_DISCONNECTED:
                ChangeConnectionStatus(ConnectionStatus.Disconnected);
                break;

            case L1SystemMsg.SYMBOL_LIMIT_REACHED:
                OnMessageReceived(new ErrorMessage {
                    Message = systemMessage
                });
                break;

            default:
                if (systemMessage.StartsWith(L1SystemMsg.CURRENT_UPDATE_FIELDNAMES))
                {
                    fieldIndex.UpdateFromL1SystemMsg(args);
                    ChangeConnectionStatus(ConnectionStatus.Connected);
                }
                break;
            }
        }
Exemplo n.º 2
0
 private void L1OnErrorMsg(IQMessageArgs args)
 {
     OnMessageReceived(new ErrorMessage {
         Message = args.Message
     });
     ChangeConnectionStatus(ConnectionStatus.Disconnected);
 }
Exemplo n.º 3
0
        private void HistoryOnHistoryMsg(IQMessageArgs args)
        {
            HistoryRequest request;

            using (historyRequestsLock.Lock())
            {
                if (!historyRequests.TryGetValue(args.RequestId, out request))
                {
                    return;
                }
            }

            HistoryMsg mgs;

            HistoryMsg.Parse(args, request.Span, out mgs);

            request.AddPoint(new HistoryDataPoint(
                                 mgs.Time,
                                 mgs.High,
                                 mgs.Low,
                                 mgs.Open,
                                 mgs.Close,
                                 mgs.Volume,
                                 mgs.OpenInterest));
        }
Exemplo n.º 4
0
        private void L1OnFundamentalMsg(IQMessageArgs args)
        {
            L1FundamentalMsg msg;

            L1FundamentalMsg.Parse(args, out msg);

            InstrumentSubscription subscription;

            using (instrumentSubscriptionsLock.Lock())
            {
                if (!instrumentSubscriptionsByCode.TryGetValue(msg.Symbol, out subscription))
                {
                    return;
                }
            }

            switch (subscription.SecurityType)
            {
            case SecurityType.FUTURE:
            case SecurityType.FOPTION:
                break;

            default:
                subscription.InstrumentParams.PriceStepValue = subscription.InstrumentParams.PriceStep;
                break;
            }

            var shouldTransmit = subscription.Update(ref msg);

            if (shouldTransmit)
            {
                OnMessageReceived(subscription.InstrumentParams);
            }
        }
Exemplo n.º 5
0
        private void L1OnSubscriptionErrorMsg(IQMessageArgs args)
        {
            // args.RequestId

            /*
             * TODO
             * InstrumentSubscription subscription;
             * using (instrumentSubscriptionsLock.Lock())
             * {
             *  if(!instrumentSubscriptionsByCode.TryGetValue(args.Message, out subscription))
             *  {
             *      return;
             *  }
             *
             *  if (instrumentSubscriptionsByCode.TryGetValue(args.RequestId, out subscription))
             *  {
             *      instrumentSubscriptionsByCode.Remove(subscription.Code);
             *      instrumentSubscriptionsByInstrument.Remove(instrument);
             *  }
             * }
             *
             * subscription.TrySetResult(
             *  new SubscriptionResult(subscription.Instrument, false, string.Format("Can't subscribe \"{0}\"", args.Message))
             *  );*/
        }
Exemplo n.º 6
0
        private bool SymbolLookupOnResultMsg(IQMessageArgs args)
        {
            SymbolLookupRequest operation;

            using (symbolLookupRequestsLock.Lock())
            {
                if (!symbolLookupRequests.TryGetValue(args.RequestId, out operation))
                {
                    return(false);
                }
            }

            bool isCompleted;

            operation.Handle(args, out isCompleted);

            if (isCompleted)
            {
                using (symbolLookupRequestsLock.Lock())
                {
                    symbolLookupRequests.Remove(args.RequestId);
                }
            }

            return(true);
        }
Exemplo n.º 7
0
 protected static void RaiseEvent(ProcessMessageDelegate handler, IQMessageArgs args)
 {
     if (handler != null)
     {
         handler(args);
     }
 }
Exemplo n.º 8
0
        private void LookupOnSecurityTypeMsg(IQMessageArgs args)
        {
            var isCompleted = securityTypeIndex.UpdateFromSecurityTypeMsg(args);

            if (isCompleted)
            {
                securityTypeIndexCompleted.TrySetResult(true);
            }
        }
Exemplo n.º 9
0
        private void LookupOnErrorMsg(IQMessageArgs args)
        {
            if (SubscriptionTestOnErrorMsg(args))
            {
                return;
            }

            if (SymbolLookupOnErrorMsg(args))
            {
                return;
            }

            Logger.Trace().PrintFormat("Message LOOKUP.{0} wasn't handled. request_id={1}", args.Message, args.RequestId);
        }
Exemplo n.º 10
0
        private void HistoryOnHistoryEndMsg(IQMessageArgs args)
        {
            HistoryRequest request;

            using (historyRequestsLock.Lock())
            {
                if (!historyRequests.TryGetValue(args.RequestId, out request))
                {
                    return;
                }
                historyRequests.Remove(args.RequestId);
            }

            request.Complete();
        }
Exemplo n.º 11
0
        private bool SymbolLookupOnErrorMsg(IQMessageArgs args)
        {
            SymbolLookupRequest operation;

            using (symbolLookupRequestsLock.Lock())
            {
                if (!symbolLookupRequests.TryGetValue(args.RequestId, out operation))
                {
                    return(false);
                }

                symbolLookupRequests.Remove(args.RequestId);
            }

            operation.Fail(args);
            return(true);
        }
Exemplo n.º 12
0
        private bool SubscriptionTestOnErrorMsg(IQMessageArgs args)
        {
            SubscriptionTest operation;

            using (subscriptionTestsLock.Lock())
            {
                if (!subscriptionTests.TryGetValue(args.RequestId, out operation))
                {
                    return(false);
                }

                subscriptionTests.Remove(args.RequestId);
            }

            operation.Message = args.Message;
            operation.TrySetResult(false);
            Logger.Warn().PrintFormat("Unable to find {0} {1} due to error {2}", operation.Type, operation.Code, args.Message);
            return(true);
        }
Exemplo n.º 13
0
        private bool SubscriptionTestOnResultMsg(IQMessageArgs args)
        {
            SubscriptionTest operation;

            using (subscriptionTestsLock.Lock())
            {
                if (!subscriptionTests.TryGetValue(args.RequestId, out operation))
                {
                    return(false);
                }

                subscriptionTests.Remove(args.RequestId);
            }

            var passed = args.Message.Split(',')[0] == operation.Code;

            operation.Message = args.Message;
            operation.TrySetResult(passed);
            Logger.Debug().PrintFormat("{0} {1} is found ({2})", operation.Type, operation.Code, args.Message);
            return(true);
        }
Exemplo n.º 14
0
            public void Handle(IQMessageArgs args, out bool isCompleted)
            {
                var parts = args.Message.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (parts.Length < 2)
                {
                    TrySetResult(codes.ToArray());
                    isCompleted = true;
                    return;
                }

                codes.Add(parts[0]);
                isCompleted = false;

                if (maxResults != null && codes.Count >= maxResults.Value)
                {
                    // Если установлен лимит на число результатов, то прерываемся преждевременно
                    // Все последующие сообщения будут проигнорированы.
                    // Увы, мощный API не позволяет задать макс. число результатов в запросе.
                    TrySetResult(codes.ToArray());
                    isCompleted = true;
                }
            }
Exemplo n.º 15
0
        private void L1OnUpdateMsg(IQMessageArgs args)
        {
            if (!L1UpdateMsg.TryParse(args, fieldIndex, out var msg))
            {
                return;
            }

            InstrumentSubscription subscription;

            using (instrumentSubscriptionsLock.Lock())
            {
                if (!instrumentSubscriptionsByCode.TryGetValue(msg.Symbol, out subscription))
                {
                    return;
                }
            }

            var shouldTransmit = subscription.Update(ref msg);

            if (shouldTransmit)
            {
                OnMessageReceived(subscription.InstrumentParams);
            }
        }
Exemplo n.º 16
0
        private void HistoryOnErrorMsg(IQMessageArgs args)
        {
            HistoryRequest request;

            using (historyRequestsLock.Lock())
            {
                if (!historyRequests.TryGetValue(args.RequestId, out request))
                {
                    return;
                }
                historyRequests.Remove(args.RequestId);
            }

            var message = args.Message.Trim(',', '\r', '\n');

            if (message == "!NO_DATA!")
            {
                request.NoData();
            }
            else
            {
                request.Fail(message);
            }
        }
Exemplo n.º 17
0
 public void Fail(IQMessageArgs args)
 {
     TrySetCanceled();
 }
Exemplo n.º 18
0
 protected void RaiseError(IQMessageArgs args)
 {
     RaiseEvent(OnErrorMsg, args);
 }