//================================================================================ void Transaq_Connect() { // чтение параметров из формы sLogin = edt_Login.Text; sPassword = edt_Password.Text; ServerIP = edt_IP.Text; ServerPort = edt_Port.Text; // проверка наличия параметров if (sLogin.Length == 0) { ShowStatus("Не указан логин"); return; } if (sPassword.Length == 0) { ShowStatus("Не указан пароль"); return; } if (ServerIP.Length == 0) { ShowStatus("Не указан IP-адрес"); return; } if (ServerPort.Length == 0) { ShowStatus("Не указан порт"); return; } ConnectingReflect(); // очистка таблиц с данными DTS.t_timeframe.Clear(); DTS.t_security.Clear(); DTS.t_candle.Clear(); DTS.t_my_securities.Clear(); DTS.t_my_takingPositions.Clear(); DTS.t_my_ClosingPositions.Clear(); // формирование текста команды string cmd = "<command id=\"connect\">"; cmd = cmd + "<login>" + sLogin + "</login>"; cmd = cmd + "<password>" + sPassword + "</password>"; cmd = cmd + "<host>" + ServerIP + "</host>"; cmd = cmd + "<port>" + ServerPort + "</port>"; cmd = cmd + "<rqdelay>100</rqdelay>"; cmd = cmd + "<session_timeout>" + session_timeout.ToString() + "</session_timeout> "; cmd = cmd + "<request_timeout>" + request_timeout.ToString() + "</request_timeout>"; cmd = cmd + "</command>"; // отправка команды log.WriteLog("SendCommand: <command id=\"connect\"><login>" + sLogin + "</login><password>*</password><host>" + ServerIP + "</host><port>" + ServerPort + "</port><logsdir>" + AppDir + "</logsdir><rqdelay>100</rqdelay></command>"); TXmlConnector.statusDisconnected.Reset(); string res = TXmlConnector.ConnectorSendCommand(cmd); log.WriteLog("ServerReply: " + res); }
public static void sendNewStopOrder2Transaq(NewStopOrder stopOrder) { StringWriter stream = new StringWriter(); XmlWriter writer = XmlWriter.Create(stream, settingsXmlWriter); serializer4newStopOrders.Serialize(writer, stopOrder, emptyNamespaces); string cmd = stream.ToString(); string res = TXmlConnector.ConnectorSendCommand(cmd); }
//================================================================================ // отключение коннектора от сервера Транзак void Transaq_Disconnect() { DisconnectingReflect(); string cmd = "<command id=\"disconnect\"/>"; log.WriteLog("SendCommand: " + cmd); TXmlConnector.statusDisconnected.Reset(); string res = TXmlConnector.ConnectorSendCommand(cmd); log.WriteLog("ServerReply: " + res); }
private void btnPassChange_Click(object sender, EventArgs e) { // Проверяем пароль // Правило: только латинские буквы и цифры, минимум 4, максимум 19 string passPattern = @"^[a-zA-Z0-9]{4,20}$"; string oldPass = txtOldPass.Text; string newPass = txtNewPass.Text; string result; Match m = Regex.Match(newPass, passPattern); if (!bConnected) { ShowStatus("Для смены пароля подключитесь к серверу"); } else if (txtNewPass.Text.Length == 0) { ShowStatus("Введите новый пароль"); } else if (m.Success) { string cmd = String.Format("<command id=\"change_pass\" oldpass=\"{0}\" newpass=\"{1}\" />", oldPass, newPass); log.WriteLog("SendCommand: <command id=\"change_pass\" oldpass=\"*\" newpass=\"*\" />"); result = TXmlConnector.ConnectorSendCommand(cmd); log.WriteLog("ServerReply: " + result); ShowStatus(result); XDocument aXmlDoc = XDocument.Load(new System.IO.StringReader(result)); if (aXmlDoc.Root.Name == "result") { if (aXmlDoc.Root.Attribute("success").Value == "true") { ShowStatus("Пароль изменен"); log.WriteLog("Password was changed"); txtOldPass.Text = ""; txtNewPass.Text = ""; } else if (aXmlDoc.Root.Attribute("success").Value == "false") { ShowStatus(aXmlDoc.Root.Value); } } else { ShowStatus("Произошла ошибка"); } } else { ShowStatus("Введите верный новый пароль"); } }
//================================================================================ void MainFormFormClosing(object sender, FormClosingEventArgs e) { TXmlConnector.FormReady = false; if (bConnected || bConnecting) { Transaq_Disconnect(); } TXmlConnector.ConnectorUnInitialize(); log.StopLogging(); }
//================================================================================ void Transaq_Disconnect() { // отключение коннектора от сервера Транзак DisconnectingReflect(); string cmd = "<command id=\"disconnect\"/>"; log.WriteLog("SendCommand: " + cmd); TXmlConnector.statusDisconnected.Reset(); string res = TXmlConnector.ConnectorSendCommand(cmd); log.WriteLog("ServerReply: " + res); }
public static void sendOrder2Transaq(Position position) { string cmd = position.getTakingPositionCommandXML(); string res = TXmlConnector.ConnectorSendCommand(cmd); XmlReader xr = XmlReader.Create(new System.IO.StringReader(res), xs); result result = (result)serializer4results.Deserialize(xr); if (result.success == true) { position.transactionid = result.transactionid; monitoredPositions.Add(position); } }
//================================================================================ void MainFormFormClosing(object sender, FormClosingEventArgs e) { MamuschkaRepeater.stopMonitoringMamuschkaServer(); TXmlConnector.FormReady = false; if (bConnected || bConnecting) { Transaq_Disconnect(); } TXmlConnector.ConnectorUnInitialize(); log.StopLogging(); Environment.Exit(Environment.ExitCode); Application.Exit(); }
//================================================================================ void MainFormLoad(object sender, EventArgs e) { // параметры по умолчанию session_timeout = 25; request_timeout = 10; edt_Login.Text = sLogin; edt_Password.Text = sPassword; bConnected = false; bConnecting = false; Enable_Password_Controls(false); Init_Data(); // открытие лог-файла log.StartLogging(AppDir + "log" + DateTime.Now.ToString("yyMMdd") + ".txt"); TXmlConnector.statusTimeout = session_timeout * 1000; TXmlConnector.ConnectorSetCallback(OnNewFormData, OnNewSecurity, OnNewTimeframe, OnNewStatus); //NewStringDataHandler nStrDH = Add_FormData; //this.onNewFormDataEvent += nStrDH; this.onNewFormDataEvent += new NewStringDataHandler(Add_FormData); this.onNewSecurityEvent += new NewStringDataHandler(Add_Security); this.onNewTimeframeEvent += new NewStringDataHandler(Add_Timeframe); this.onNewStatusEvent += new NewBoolDataHandler(ConnectionStatusReflect); TXmlConnector.FormReady = true; string LogPath = AppDir + "\0"; if (TXmlConnector.ConnectorInitialize(LogPath, 3)) { TXmlConnector.statusDisconnected.Set(); } }
//================================================================================ // запрос исторических данных для инструмента void Get_Transaq_History(int SecurityID, int TimeframeID, int HistoryLength, bool ResetFlag) { string cmd = "<command id=\"gethistorydata\" "; cmd = cmd + "secid=\"" + SecurityID.ToString() + "\" "; cmd = cmd + "period=\"" + TimeframeID.ToString() + "\" "; cmd = cmd + "count=\"" + HistoryLength.ToString() + "\" "; string s = "false"; if (ResetFlag) { s = "true"; } cmd = cmd + "reset=\"" + s + "\"/>"; log.WriteLog("SendCommand: " + cmd); string res = TXmlConnector.ConnectorSendCommand(cmd); log.WriteLog("ServerReply: " + res); }
public static void sendCancelAll2Transaq() { foreach (Order order in monitoredOrders) { string cmd = "<command id=\"cancelorder\">"; cmd = cmd + "<transactionid>" + order.transactionid.ToString() + "</transactionid>"; cmd = cmd + "</command>"; string res = TXmlConnector.ConnectorSendCommand(cmd); } foreach (Stoporder stoporder in monitoredStopOrders) { string cmd = "<command id=\"cancelstoporder\">"; cmd = cmd + "<transactionid>" + stoporder.transactionid.ToString() + "</transactionid>"; cmd = cmd + "</command>"; string res = TXmlConnector.ConnectorSendCommand(cmd); } }
private void dataGridViewMyInstruments_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridView myObject = (DataGridView)sender; if (myObject.CurrentRow == null) { return; } string seccode = myObject.CurrentRow.Cells[2].Value.ToString(); int decimals = (int)myObject.CurrentRow.Cells[4].Value; int market = (int)myObject.CurrentRow.Cells[5].Value; string board = myObject.CurrentRow.Cells[6].Value.ToString(); OportunityMonitor.monitoredSecurityOnHMI = new Security(seccode, board, decimals, market); OportunityMonitor.addSecurityForMonitoring(new Security(seccode, board, decimals, market)); string cmd = "<command id=\"subscribe\">"; cmd = cmd + " <quotations><security><board>" + board + "</board><seccode>" + seccode + "</seccode></security></quotations>"; cmd = cmd + "</command>"; string res = TXmlConnector.ConnectorSendCommand(cmd); }
//================================================================================ void MainFormLoad(object sender, EventArgs e) { ctl_Tabs.SelectTab("tab_Param"); // параметры по умолчанию ServerIP = "tr1.finam.ru"; ServerPort = "3900"; loadLogginDetails(); session_timeout = 25; request_timeout = 10; comboBox1.Items.Add(new ComboboxItem() { Text = "FORTS", Value = 4 }); comboBox1.Items.Add(new ComboboxItem() { Text = "ММВБ", Value = 1 }); comboBox1.Items.Add(new ComboboxItem() { Text = "SPBEX", Value = 7 }); comboBox1.Items.Add(new ComboboxItem() { Text = "INF", Value = 8 }); comboBox1.Items.Add(new ComboboxItem() { Text = "MMA", Value = 14 }); comboBox1.Items.Add(new ComboboxItem() { Text = "ETS", Value = 8 }); comboBox1.SelectedIndex = 0; edt_Login.Text = sLogin; edt_Password.Text = sPassword; edt_IP.Text = ServerIP; edt_Port.Text = ServerPort; bConnected = false; bConnecting = false; Enable_Password_Controls(false); Init_Data(); // открытие лог-файла log.StartLogging(AppDir + "log" + DateTime.Now.ToString("yyMMdd") + ".txt"); TXmlConnector.statusTimeout = session_timeout * 1000; TXmlConnector.ConnectorSetCallback(OnNewFormData, OnNewSecurity, OnNewTimeframe, OnNewStatus); this.onNewFormDataEvent += new NewStringDataHandler(Add_FormData); this.onNewSecurityEvent += new NewStringDataHandler(Add_Security); this.onNewTimeframeEvent += new NewStringDataHandler(Add_Timeframe); this.onNewStatusEvent += new NewBoolDataHandler(ConnectionStatusReflect); TXmlConnector.Orders4HMISubscribe(OrdersSubscriber); this.onOrdersPublished += new NewStringDataHandler(processOrdersDistribution); OportunityMonitor.init(); TXmlConnector.FormReady = true; string LogPath = AppDir + "\0"; if (TXmlConnector.ConnectorInitialize(LogPath, 3)) { TXmlConnector.statusDisconnected.Set(); } OportunityMonitor.subscribeQuotationUpdate(quotationCall); this.onQuotation += new quotationDelegate(setQuotationPrice); OportunityMonitor.PositionPublisherCallback(PositionPublisherCall); onPositionSuscriber += new PositionDelegate(setTakingClosingPosition); MamuschkaRepeater.mamushkaStatusSubscribe(mamuschkaStatusCall); onMamushkaStatusResponse += new NewStringDataHandler(setMamushkaServerStatus); MamuschkaRepeater.monitorMamuschkaServer(); }
void Transaq_Connect() { // чтение параметров из формы switch (chs_Server.Text) { case "АО \"Финам\"": ServerIP = "tr1.finam.ru"; break; case "АО \"Банк Финам\"": ServerIP = "tr1.finambank.ru"; break; case "Демо": ServerIP = "tr1-demo5.finam.ru"; break; } if (chs_Server.Text != "АО \"Финам\"" && chs_Server.Text != "АО \"Банк Финам\"" && chs_Server.Text != "Демо" && chs_Server.Text != "tr1.finam.ru" && chs_Server.Text != "tr1.finambank.ru" && chs_Server.Text != "tr1-demo5.finam.ru") { ServerIP = chs_Server.Text; } sLogin = edt_Login.Text; sPassword = edt_Password.Text; ServerPort = edt_Port.Text; // проверка наличия параметров if (sLogin.Length == 0) { ShowStatus("Не указан логин"); return; } if (sPassword.Length == 0) { ShowStatus("Не указан пароль"); return; } if (ServerIP.Length == 0) { ShowStatus("Не указан IP-адрес"); return; } if (ServerPort.Length == 0) { ShowStatus("Не указан порт"); return; } ConnectingReflect(); // очистка таблиц с данными DTS.t_timeframe.Clear(); DTS.t_security.Clear(); DTS.t_candle.Clear(); // формирование текста команды string cmd = "<command id=\"connect\">"; cmd = cmd + "<login>" + sLogin + "</login>"; cmd = cmd + "<password>" + sPassword + "</password>"; cmd = cmd + "<host>" + ServerIP + "</host>"; cmd = cmd + "<port>" + ServerPort + "</port>"; cmd = cmd + "<rqdelay>100</rqdelay>"; cmd = cmd + "<session_timeout>" + session_timeout.ToString() + "</session_timeout> "; cmd = cmd + "<request_timeout>" + request_timeout.ToString() + "</request_timeout>"; cmd = cmd + "</command>"; // отправка команды log.WriteLog("SendCommand: <command id=\"connect\"><login>" + sLogin + "</login><password>*</password><host>" + ServerIP + "</host><port>" + ServerPort + "</port><logsdir>" + AppDir + "</logsdir><rqdelay>100</rqdelay></command>"); TXmlConnector.statusDisconnected.Reset(); string res = TXmlConnector.ConnectorSendCommand(cmd); log.WriteLog("ServerReply: " + res); }
public static void init() { monitoredSecurities = new List <Security>(); TXmlConnector.NewQuotationCallback(NewQuotationCall); TXmlConnector.OrdersSubscribe(OrdersSubscriber); TXmlConnector.MarketsSubscribe(MarketsSubscriber); TXmlConnector.ClientSubscribe(ClientSubscriber); onNewQuotationEvent += new NewStringDataHandler(processQuotationsDistribution); onOrdersPublished += new NewStringDataHandler(processOrdersDistribution); onMarketsPublished += new NewStringDataHandler(processMarketsDistribution); onClientPublished += new NewStringDataHandler(processClientDistribution); XmlRootAttribute rootNodeQuotations = new XmlRootAttribute { ElementName = "quotations" }; XmlRootAttribute rootNodeOrders = new XmlRootAttribute { ElementName = "orders" }; XmlRootAttribute rootNodeResult = new XmlRootAttribute { ElementName = "result" }; XmlRootAttribute rootNodeMarkets = new XmlRootAttribute { ElementName = "markets" }; XmlRootAttribute rootNodeClient = new XmlRootAttribute { ElementName = "client" }; Type deserializeType = typeof(quotations); serializer4quotations = new XmlSerializer(deserializeType, rootNodeQuotations); deserializeType = typeof(orders); serializer4orders = new XmlSerializer(deserializeType, rootNodeOrders); deserializeType = typeof(result); serializer4results = new XmlSerializer(deserializeType, rootNodeResult); deserializeType = typeof(NewStopOrder); serializer4newStopOrders = new XmlSerializer(deserializeType); deserializeType = typeof(markets); serializer4markets = new XmlSerializer(deserializeType, rootNodeMarkets); deserializeType = typeof(client); serializer4client = new XmlSerializer(deserializeType, rootNodeClient); emptyNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }); settingsXmlWriter.Indent = true; settingsXmlWriter.OmitXmlDeclaration = true; xs = new XmlReaderSettings { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment, ProhibitDtd = false }; }