Пример #1
0
        public static ConcurrentQueue<output> _queue = new ConcurrentQueue<output>();// dict store all surrounding Info
        public static void requestFlow(output x)
        {
            lock (reqFlow.locker0)
            {
                try
                {
                    _queue.Enqueue(x);
                    DepthOfBkHndlr dobkUnderhndlr = new MktSrvcAPI.DepthOfBkHndlr((_instr, _ts, _partid, _mod, _numbid, _numask, _bidexch, _askexch, _bidbk, _askbk) => respFlow.dobkUnderhndlr(_instr, _ts, _partid, _mod, _numbid, _numask, _bidexch, _askexch, _bidbk, _askbk));
                    Conn._dobkUnderClient.depofbkhndlr = dobkUnderhndlr;

                    Conn._dobkUnderClient.Subscribe(new InstrInfo
                    {
                        sym = x.under,
                        type = InstrInfo.EType.EQUITY,
                    });
                    //Console.WriteLine("request: " + x.under + x.callput);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }

                //Console.WriteLine("000 "+((ConcurrentQueue<output>)_Dict[0][6]).Count);
            }
        }
Пример #2
0
        //public static void requestFlow(output x)
        //{
        //    try
        //    {
        //        _queue.Enqueue(x);
        //        DepthOfBkHndlr depofbkhndlr0 = new MktSrvcAPI.DepthOfBkHndlr((_instr, _ts, _partid, _mod, _numbid, _numask, _bidexch, _askexch, _bidbk, _askbk) => respFlow2.depofbkhndlr(_instr, _ts, _partid, _mod, _numbid, _numask, _bidexch, _askexch, _bidbk, _askbk));
        //        Conn._DepthofBkClient.depofbkhndlr = depofbkhndlr0;
        //        Conn._DepthofBkClient.Subscribe(x.instr);
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex.Message);
        //    }
        //}

        public static void requestFlow(output x1, output x2)
        {
            try
            {
                _queue.Enqueue(x1);
                _queue.Enqueue(x2);
                DepthOfBkHndlr depofbkhndlr0 = new MktSrvcAPI.DepthOfBkHndlr((_instr, _ts, _partid, _mod, _numbid, _numask, _bidexch, _askexch, _bidbk, _askbk) => respFlow2.depofbkhndlr(_instr, _ts, _partid, _mod, _numbid, _numask, _bidexch, _askexch, _bidbk, _askbk));
                Conn._DepthofBkClient.depofbkhndlr = depofbkhndlr0;
                Conn._DepthofBkClient.Subscribe(x1.instr);
                Conn._DepthofBkClient.Subscribe(x2.instr);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #3
0
        public static void StartListening(string ip)
        {
            // Data buffer for incoming data.
            byte[] bytes = new Byte[1024];

            // Establish the local endpoint for the socket.
            // Dns.GetHostName returns the name of the 
            // host running the application.
            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress ipAddress = IPAddress.Parse(ip);
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 15000);

            // Create a TCP/IP socket.
            Socket listener = new Socket(AddressFamily.InterNetwork,
                SocketType.Stream, ProtocolType.Tcp);

            // Bind the socket to the local endpoint and 
            // listen for incoming connections.
            try
            {
                listener.Bind(localEndPoint);
                listener.Listen(10);

                // Start listening for connections.
                while (true)
                {
                    Console.WriteLine("Waiting for a connection...");
                    // Program is suspended while waiting for an incoming connection.
                    Socket handler = listener.Accept();
                    data = null;

                    // An incoming connection needs to be processed.
                    while (true)
                    {
                        bytes = new byte[1024];
                        int bytesRec = handler.Receive(bytes);
                        data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                        if (data.IndexOf("<EOF>") > -1)
                        {
                            // All the data has been read from the 
                            // client. Display it on the console.
                            Console.WriteLine("\n\n start:");
                            Console.WriteLine("Read {0} bytes from socket: {1} port: {2} \n Data : {3}",
                                data.Length, IPAddress.Parse(((IPEndPoint)handler.RemoteEndPoint).Address.ToString()), ((IPEndPoint)handler.RemoteEndPoint).Port.ToString(), data);
                            // Echo the data back to the client.
                            //Send(handler, content);

                            //add analytic for the data (under + exp + callput) => find out live stock price + (-10% ~ +10% strikes) at the money qoutes + (weighted) svwaps / wbid / wask .
                            //trigger the quote processing after receive the data
                            //then calculate the svwap
                            //sent back to client 

                            string content = data.Split('<')[0];
                            if (content != "start")
                            {
                                Console.WriteLine(content);
                                output x = new output
                                {
                                    under = content.Split('|')[0],
                                    exp = Convert.ToInt32(content.Split('|')[1]),
                                    callput = content.Split('|')[2],
                                    ip = ((IPEndPoint)handler.RemoteEndPoint).Address.ToString(),
                                };

                                if (Conn.Dict.ContainsKey(x.under + x.exp + x.callput))
                                {
                                    reqFlow.requestFlow(x);
                                    break;
                                }
                            }
                        }
                    }

                    // Show the data on the console.
                    Console.WriteLine("Text received : {0}", data);

                    // Echo the data back to the client.
                    byte[] msg = Encoding.ASCII.GetBytes(data);

                    handler.Send(msg);
                    handler.Shutdown(SocketShutdown.Both);
                    handler.Close();
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.WriteLine("\nPress ENTER to continue...");
            Console.Read();
        }
Пример #4
0
        public static void subtask(InstrInfo instr, uint ts, byte[] bidexch, byte[] askexch, Quote[] bidbk, Quote[] askbk, output x)
        {
            string _quoteinstrument = instr.sym + instr.maturity + instr.callput + instr.strike;


            #region Quote Filtering
            List<FilteredQuote> _Bidbk = new List<FilteredQuote>();
            List<FilteredQuote> _Askbk = new List<FilteredQuote>();
            List<char> _Bidexch = new List<char>();
            List<char> _Askexch = new List<char>();
            calib.QuoteFiltering(bidexch, bidbk, _Bidbk, _Bidexch);
            calib.QuoteFiltering(askexch, askbk, _Askbk, _Askexch);
            #endregion

            x._Wbidsz = calib.CalculateWsz(_Bidbk);
            x._Wasksz = calib.CalculateWsz(_Askbk);

            if (x._Wbidsz == 0)
            {
                x._Wbidprc = 0;
            }
            else
            {
                x._Wbidprc = calib.CalculateWprc(_Bidbk) / x._Wbidsz;
            }

            if (x._Wasksz == 0)
            {
                x._Waskprc = 0;
            }
            else
            {
                x._Waskprc = calib.CalculateWprc(_Askbk) / x._Wasksz;
            }


            if (x._Wbidprc == 0)
            {
                //low the weight by (wbidprc = 0 + waskprc + askprc[0]) / 3
                x._Wmidpt = (x._Waskprc + _Askbk[0]._prc) / 3;
                x._Vwap = x._Wmidpt;
            }
            else if (x._Waskprc == 0)
            {
                x._Wmidpt = (x._Wbidprc + _Bidbk[0]._prc) / 3;
                x._Vwap = x._Wmidpt;
            }
            else
            {
                x._Wmidpt = (x._Wbidprc + x._Waskprc) / 2;
                x._Vwap = calib.CalculateVWAP(_Bidbk, _Askbk);
            }
            x.svwap = (x._Wmidpt + x._Vwap) / 2;

            Console.WriteLine(_quoteinstrument + "  " + x.svwap);
            //asynsocketclient.StartSend("10.0.7.218",15000, x.stock + "|" + x.svwap);
            //sclient.start("10.0.7.182", x.stock + "|" + x.svwap);



            if (x.flag == true)
            {
                sclient.start(x.ip, x.stock + "|" + x.svwap);
            }
            else
            {
                x.flag = true;
                if (x.index == 1)
                {
                    while (x.nearby.flag != true)
                    {
                        Thread.Sleep(30);
                    }

                    if (x.instr.strike > x.stock)
                    {
                        float svwap = x.svwap * (x.stock - x.nearby.instr.strike) / (x.instr.strike - x.nearby.instr.strike) + x.nearby.svwap * (x.instr.strike - x.stock) / (x.instr.strike - x.nearby.instr.strike);
                        sclient.start(x.ip, x.stock + "|" + svwap);
                    }
                }
            }

            Console.WriteLine("ip: " + x.ip);
        }
Пример #5
0
        public static void subtask(InstrInfo instr, uint ts, byte[] bidexch, byte[] askexch, Quote[] bidbk, Quote[] askbk, output x)
        {
            lock (locker)
            {
                x.instr = new InstrInfo
                {
                    sym = x.under,
                    maturity = x.exp,
                    callput = (MktSrvcAPI.InstrInfo.ECallPut)(x.callput == "CALL" ? 1 : 0),
                    type = InstrInfo.EType.OPTION
                };


                if (bidexch != null && askexch != null)
                {
                    x.stock = (bidbk[0].prc + askbk[0].prc) / 2;
                }
                else if (bidexch != null && askexch == null)
                {
                    x.stock = bidbk[0].prc;
                }
                else if (bidexch == null && askexch != null)
                {
                    x.stock = askbk[0].prc;
                }
                else
                {
                    x.stock = 0.0f;
                }

                Console.WriteLine(x.under + "   " + x.stock);


                //ATM
                List<float> strikes = Conn.Dict[x.under + x.exp + x.callput];
                strikes.Sort();
                if (strikes[0] < x.stock && strikes[strikes.Count - 1] > x.stock)
                {
                    foreach (float s in strikes)
                    {
                        if (s - x.stock >= 0)
                        {

                            if (s - x.stock == 0)
                            {
                                x.instr.strike = s;
                                x.flag = true;
                                reqFlow2.requestFlow(x, x);
                            }
                            else
                            {
                                output y = new output();
                                x.instr.strike = s;
                                y.instr = new InstrInfo
                                {
                                    sym = x.under,
                                    maturity = x.exp,
                                    callput = (MktSrvcAPI.InstrInfo.ECallPut)(x.callput == "CALL" ? 1 : 0),
                                    type = InstrInfo.EType.OPTION
                                };
                                y.under = x.under;
                                y.exp = x.exp;
                                y.callput = x.callput;
                                y.ip = x.ip;
                                y.instr.strike = strikes[strikes.IndexOf(s) - 1];
                                x.flag = false;
                                y.flag = false;
                                x.nearby = y;
                                y.nearby = x;
                                x.index = 1;
                                y.index = 0;
                                reqFlow2.requestFlow(y, x);
                            }

                            break;
                        }
                    }
                }
                else if (strikes[0] == x.stock)
                {
                    x.instr.strike = strikes[0];
                    reqFlow2.requestFlow(x, x);
                }
                else if (strikes[strikes.Count - 1] == x.stock)
                {
                    x.instr.strike = strikes[strikes.Count - 1];
                    reqFlow2.requestFlow(x, x);
                }
                else
                {
                    //pass
                }
            }
        }