/// <summary> /// Send message. /// </summary> /// <param name="message">Message.</param> protected override void OnSendInMessage(Message message) { switch (message.Type) { case MessageTypes.Reset: { _depths.Clear(); _secIdByTradeIds.Clear(); if (_socket != null) { try { _socket.Dispose(); } catch (Exception ex) { SendOutError(ex); } _socket = null; } SendOutMessage(new ResetMessage()); break; } case MessageTypes.Connect: { if (_socket != null) throw new InvalidOperationException(LocalizedStrings.Str1619); _socket = new IBSocket { Parent = this }; _socket.ProcessResponse += OnProcessResponse; _socket.Connect(Address); _socket.Send((int)_clientVersion); _socket.ServerVersion = (ServerVersions)_socket.ReadInt(); if (_socket.ServerVersion >= ServerVersions.V20) { var str = _socket.ReadStr(); ConnectedTime = str.Substring(0, str.LastIndexOf(' ')).ToDateTime("yyyyMMdd HH:mm:ss"); } if (_socket.ServerVersion < _minimumServerVersion) { throw new InvalidOperationException(LocalizedStrings.Str2513Params .Put((int)_socket.ServerVersion, (int)_minimumServerVersion)); } if (_socket.ServerVersion >= ServerVersions.V3) { if (_socket.ServerVersion >= ServerVersions.V70) { if (!ExtraAuth) { _socket.Send((int)RequestMessages.StartApi); _socket.Send((int)ServerVersions.V2); _socket.Send(ClientId); if (_socket.ServerVersion >= ServerVersions.V72) { _socket.Send(OptionalCapabilities); } } } else _socket.Send(ClientId); } _socket.StartListening(error => SendOutMessage(new ConnectMessage { Error = error })); SendOutMessage(new ConnectMessage()); // отправляется автоматически //RequestIds(1); SetServerLogLevel(); SetMarketDataType(); RequestCurrentTime(); break; } case MessageTypes.Disconnect: { if (_socket == null) throw new InvalidOperationException(LocalizedStrings.Str1856); UnSubscribePosition(); UnSubscribeAccountSummary(_pfRequests.GetAndRemove("ALL")); _socket.Dispose(); _socket = null; SendOutMessage(new DisconnectMessage()); break; } case MessageTypes.OrderRegister: { RegisterOrder((OrderRegisterMessage)message); break; } case MessageTypes.OrderCancel: { var cancelMsg = (OrderCancelMessage)message; ProcessRequest(RequestMessages.CancelOrder, 0, ServerVersions.V1, socket => socket.Send((int)cancelMsg.OrderTransactionId)); break; } case MessageTypes.OrderGroupCancel: { RequestGlobalCancel(); break; } case MessageTypes.SecurityLookup: { RequestSecurityInfo((SecurityLookupMessage)message); break; } case MessageTypes.MarketData: { ProcessMarketDataMessage((MarketDataMessage)message); break; } case MessageTypes.PortfolioLookup: { var pfMsg = (PortfolioLookupMessage)message; // отправляется автоматически //RequestPortfolios(); SubscribePosition(); _pfRequests.Add("ALL", pfMsg.TransactionId); SubscribeAccountSummary(pfMsg.TransactionId, "ALL", Enumerator.GetValues<AccountSummaryTag>()); break; } case MessageTypes.Portfolio: { var pfMsg = (PortfolioMessage)message; SubscribePortfolio(pfMsg.PortfolioName, pfMsg.IsSubscribe); break; } case MessageTypes.OrderStatus: { var orderMsg = (OrderStatusMessage)message; RequestOpenOrders(); RequestAllOpenOrders(); //RequestAutoOpenOrders(ClientId == 0); ReqeustMyTrades(orderMsg.TransactionId, new MyTradeFilter()); break; } } }