/// <summary> /// connect to API /// подключиться к Апи /// </summary> public void Connect() { try { _lastStartServerTime = DateTime.Now; if (string.IsNullOrWhiteSpace(((ServerParameterPath)ServerParameters[0]).Value)) { SendLogMessage(OsLocalization.Market.Message83, LogMessageType.Error); return; } if (ServerStatus == ServerConnectStatus.Connect) { return; } if (_transe2QuikStatus != ServerConnectStatus.Connect) { int error; var msg = new StringBuilder(256); Trans2Quik.QuikResult result = Trans2Quik.SET_CONNECTION_STATUS_CALLBACK(StatusCallback, out error, msg, msg.Capacity); if (result != Trans2Quik.QuikResult.SUCCESS) { SendLogMessage(OsLocalization.Market.Message84 + error, LogMessageType.Error); return; } result = Trans2Quik.CONNECT(((ServerParameterPath)ServerParameters[0]).Value, out error, msg, msg.Capacity); if (result != Trans2Quik.QuikResult.SUCCESS && result != Trans2Quik.QuikResult.ALREADY_CONNECTED_TO_QUIK) { SendLogMessage(OsLocalization.Market.Message84 + msg, LogMessageType.Error); return; } Trans2Quik.SET_TRANSACTIONS_REPLY_CALLBACK(TransactionReplyCallback, out error, msg, msg.Capacity); result = Trans2Quik.SUBSCRIBE_ORDERS("", ""); while (result != Trans2Quik.QuikResult.SUCCESS) { Thread.Sleep(5000); result = Trans2Quik.SUBSCRIBE_ORDERS("", ""); } result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback)); while (result != Trans2Quik.QuikResult.SUCCESS) { Thread.Sleep(5000); result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback)); } Trans2Quik.SUBSCRIBE_TRADES("", ""); Trans2Quik.START_TRADES(PfnTradeStatusCallback); Trans2Quik.GetTradeAccount(0); } if (_serverDde == null) { _serverDde = new QuikDde("OSA_DDE"); _serverDde.StatusChangeEvent += _serverDde_StatusChangeEvent; _serverDde.UpdatePortfolios += _serverDde_UpdatePortfolios; _serverDde.UpdateSecurity += _serverDde_UpdateSecurity; _serverDde.UpdateTrade += _serverDde_UpdateTrade; _serverDde.UpdateGlass += _serverDde_UpdateGlass; _serverDde.LogMessageEvent += SendLogMessage; if (!_serverDde.IsRegistered) { _serverDde.StartServer(); } else { _ddeStatus = ServerConnectStatus.Connect; } } if (_serverDde.IsRegistered) { _ddeStatus = ServerConnectStatus.Connect; } Thread.Sleep(1000); } catch (Exception erorr) { SendLogMessage(erorr.ToString(), LogMessageType.Error); } }
/// <summary> /// подключиться к Апи /// </summary> public void Connect() { try { _lastStartServerTime = DateTime.Now; if (string.IsNullOrWhiteSpace(((ServerParameterPath)ServerParameters[0]).Value)) { SendLogMessage("Ошибка. Необходимо указать местоположение Quik", LogMessageType.Error); return; } if (ServerStatus == ServerConnectStatus.Connect) { SendLogMessage("Ошибка. Соединение уже установлено", LogMessageType.Error); return; } if (_transe2QuikStatus != ServerConnectStatus.Connect) { int error; var msg = new StringBuilder(256); Trans2Quik.QuikResult result = Trans2Quik.SET_CONNECTION_STATUS_CALLBACK(StatusCallback, out error, msg, msg.Capacity); if (result != Trans2Quik.QuikResult.SUCCESS) { SendLogMessage("Ошибка. Trans2Quik не хочет подключаться " + error, LogMessageType.Error); return; } result = Trans2Quik.CONNECT(((ServerParameterPath)ServerParameters[0]).Value, out error, msg, msg.Capacity); if (result != Trans2Quik.QuikResult.SUCCESS && result != Trans2Quik.QuikResult.ALREADY_CONNECTED_TO_QUIK) { SendLogMessage("Ошибка при попытке подклчиться через Transe2Quik." + msg, LogMessageType.Error); return; } Trans2Quik.SET_TRANSACTIONS_REPLY_CALLBACK(TransactionReplyCallback, out error, msg, msg.Capacity); result = Trans2Quik.SUBSCRIBE_ORDERS("", ""); while (result != Trans2Quik.QuikResult.SUCCESS) { Thread.Sleep(5000); result = Trans2Quik.SUBSCRIBE_ORDERS("", ""); SendLogMessage("Повторно пытаемся включить поток сделок" + msg, LogMessageType.Error); } result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback)); while (result != Trans2Quik.QuikResult.SUCCESS) { Thread.Sleep(5000); result = Trans2Quik.START_ORDERS((PfnOrderStatusCallback)); SendLogMessage("Повторно пытаемся включить поток сделок" + msg, LogMessageType.Error); } Trans2Quik.SUBSCRIBE_TRADES("", ""); Trans2Quik.START_TRADES(PfnTradeStatusCallback); Trans2Quik.GetTradeAccount(0); } if (_serverDde == null) { _serverDde = new QuikDde("OSA_DDE"); _serverDde.StatusChangeEvent += _serverDde_StatusChangeEvent; _serverDde.UpdatePortfolios += _serverDde_UpdatePortfolios; _serverDde.UpdateSecurity += _serverDde_UpdateSecurity; _serverDde.UpdateTrade += _serverDde_UpdateTrade; _serverDde.UpdateGlass += _serverDde_UpdateGlass; _serverDde.LogMessageEvent += SendLogMessage; if (!_serverDde.IsRegistered) { _serverDde.StartServer(); } else { _ddeStatus = ServerConnectStatus.Connect; } } if (_serverDde.IsRegistered) { _ddeStatus = ServerConnectStatus.Connect; } Thread.Sleep(1000); } catch (Exception erorr) { SendLogMessage(erorr.ToString(), LogMessageType.Error); } }