// ********************************************************************** // * Соединение * // ********************************************************************** void TryConnect(Object state) { if (working) { try { if ( Trans2Quik.SET_CONNECTION_STATUS_CALLBACK(StatusCallback, out error, msg, msg.Capacity) != Trans2Quik.Result.SUCCESS || Trans2Quik.SET_TRANSACTIONS_REPLY_CALLBACK(TransactionReplyCallback, out error, msg, msg.Capacity) != Trans2Quik.Result.SUCCESS ) { mgr.ConnectionUpdate(TermConnection.None, msg.ToString()); return; } Trans2Quik.Result result = Trans2Quik.CONNECT(cfg.u.QuikFolder, out error, msg, msg.Capacity); if (result != Trans2Quik.Result.SUCCESS && result != Trans2Quik.Result.ALREADY_CONNECTED_TO_QUIK) { mgr.ConnectionUpdate(TermConnection.None, msg.ToString()); return; } } catch (Exception e) { mgr.ConnectionUpdate(TermConnection.None, e.Message); return; } connected = true; if (Trans2Quik.UNSUBSCRIBE_ORDERS() != Trans2Quik.Result.SUCCESS || Trans2Quik.UNSUBSCRIBE_TRADES() != Trans2Quik.Result.SUCCESS || Trans2Quik.SUBSCRIBE_ORDERS(cfg.u.ClassCode, cfg.u.SecCode) != Trans2Quik.Result.SUCCESS || Trans2Quik.START_ORDERS(OrderStatusCallback) != Trans2Quik.Result.SUCCESS || Trans2Quik.SUBSCRIBE_TRADES(cfg.u.ClassCode, cfg.u.SecCode) != Trans2Quik.Result.SUCCESS || Trans2Quik.START_TRADES(TradeStatusCallback) != Trans2Quik.Result.SUCCESS) { mgr.ConnectionUpdate(TermConnection.Partial, "Соединение установлено неполностью"); return; } mgr.ConnectionUpdate(TermConnection.Full, "Соединение с сервером QUIK установлено"); } connecting.Change(Timeout.Infinite, Timeout.Infinite); }