Beispiel #1
0
        static void Main(string[] args)
        {
            loadSettings();
            loadEventHandlers();

            log.StartLogging(sAppDir + "log" + DateTime.Now.ToString("yyMMdd") + ".txt");

            TXmlConnector.statusTimeout = session_timeout * 1000;
            TXmlConnector.ConnectorSetCallback(OnNewFormData, OnNewSecurity, OnNewTimeframe, OnNewStatus);
            TXmlConnector.FormReady = true;
            if (TXmlConnector.ConnectorInitialize(sLogPath, 3))
            {
                TXmlConnector.statusDisconnected.Set();
            }

            OportunityMonitor.init();
            OportunityMonitor.PositionPublisherCallback(PositionPublisherCall);

            MyTcpServer tcpServer = new MyTcpServer();

            tcpServer.start();
        }
Beispiel #2
0
        private void doRequest()
        {
            try{
                NetworkStream ns = clientSocket.GetStream(); //networkstream is used to send/receive messages

                while (clientSocket.Connected)               //while the client is connected, we look for incoming messages
                {
                    String       request = String.Empty;
                    StreamReader reader  = new StreamReader(ns, Encoding.UTF8);
                    request = reader.ReadLine();

                    XmlReaderSettings xs = new XmlReaderSettings();
                    xs.IgnoreWhitespace = true;
                    xs.ConformanceLevel = ConformanceLevel.Fragment;
                    XmlReader xr = XmlReader.Create(new System.IO.StringReader(request), xs);

                    while (xr.Read())
                    {
                        if (xr.Depth == 0 && xr.NodeType == XmlNodeType.Element)
                        {
                            if (xr.Name == "connect")
                            {
                                Program.Transaq_Connect();
                                Console.WriteLine(request);
                            }
                            if (xr.Name == "disconnect")
                            {
                                Program.Transaq_Disconnect();
                                Console.WriteLine(request);
                            }
                            if (xr.Name == "cancelAll")
                            {
                                OportunityMonitor.sendCancelAll2Transaq();
                                Console.WriteLine(request);
                            }
                            if (xr.Name == "position")
                            {
                                Console.WriteLine(request);

                                positionXML receivedPosition = (positionXML)serializer4Postion.Deserialize(xr);
                                if (receivedPosition == null)
                                {
                                    Console.WriteLine("receivedPosition == null ... returning"); return;
                                }
                                client client = OportunityMonitor.clients.Find(c => c.market == receivedPosition.market);
                                if (client == null)
                                {
                                    Console.WriteLine("Uppsss there is no client for this Market  "); return;
                                }

                                Position position2forward = new Position(
                                    receivedPosition.board,
                                    receivedPosition.seccode,
                                    client.id,
                                    client.union,
                                    receivedPosition.price,
                                    receivedPosition.quantity,
                                    receivedPosition.buysell,
                                    receivedPosition.stopLoss,
                                    receivedPosition.takeProfit,
                                    receivedPosition.decimals
                                    );

                                OportunityMonitor.sendOrder2Transaq(position2forward);
                            }
                            if (xr.Name == "statusCheck")
                            {
                                StreamWriter writer = new StreamWriter(ns, Encoding.UTF8);
                                writer.Flush();

                                if (Program.bConnected)
                                {
                                    writer.WriteLine("connected");
                                }
                                else
                                {
                                    writer.WriteLine("disconnected");
                                }
                                writer.Flush();
                            }
                            xr.Close();
                        }
                    }
                    reader.Close();
                    clientSocket.Close();
                }
            }
            catch (global::System.Exception)
            {
                return;
            }
        }