Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string host = cbHostStk.Text;
            ushort port = ushort.Parse(tbPortStk.Text);
            string id   = tbIDStk.Text;
            string pwd  = tbPWDStk.Text;
            char   area = ' ';

            quoteCom.SourceId = tbSID.Text;
            quoteCom.Connect2Quote(host, port, id, pwd, area, "");
        }
Пример #2
0
        static void Main(string[] args)
        {
            quotecom                  = new Intelligence.QuoteCom(host, port, SID, Token); //接收證券行情物件
            quotecom.SourceId         = SID;
            quotecom.OnRcvMessage    += OnQuoteRcvMessage;
            quotecom.OnGetStatus     += OnQuoteGetStatus;
            quotecom.OnRecoverStatus += OnRecoverStatus;


            tfcom = new Smart.TaiFexCom(host, port, SID); // 券證下單物件

            tfcom.OnRcvMessage += OntfcomRcvMessage;      //資料接收事件
            tfcom.OnGetStatus  += OntfcomGetStatus;       //狀態通知事件
            //tfcom.OnRcvServerTime += OntfcomRcvServerTime;   //接收主機時間
            //tfcom.OnRecoverStatus += OntfcomRecoverStatus;   //回補狀態通知
            tfcom.LoginDirect(host, port, id, pwd, ' ');
            tfcom.AutoSubReportSecurity = true;
            tfcom.AutoRecoverReport     = true;
            Console.ReadLine();
            quotecom.Connect2Quote(host, port, id, pwd, area, "");
            Console.ReadLine();
            quotecom.SubQuotesDepth("6223");
            quotecom.SubQuotesMatch("6223");
            Console.ReadLine();
            TradeBotBase tb = new TradeBotQA("6223", brokerid, account, 1, quotecom, tfcom, 1.5, 109, 100, BuyMode.Auto, StopLossMode.Auto, LockGainMode.Auto);

            tb.StatusChange += ShowChanges;
            tb.Start();
            //AddInfo(tfcom.Accounts);
            //Console.WriteLine(brokerid);
            //Console.WriteLine(account);
            Console.ReadLine();
            tb.BuyStock();
            Console.ReadLine();
            tb.SellStock();
            //quotecom.SubQuotesDepth("2317");
            //quotecom.SubQuotesMatch("2317");
            //Console.ReadLine();
            //TradeBot tb2 = new TradeBot("2317", brokerid, account, 1, quotecom, tfcom,1.5);
            //tb2.StatusChange += ShowChanges;
            //tb2.Start();
        }
Пример #3
0
 public void connect()
 {
     quoteCom.SourceId = SID;
     quoteCom.Connect2Quote(host, port, id, pwd, area, "");
 }
Пример #4
0
        public static void initial()
        {
            msg Quotemsg = new msg();
            while (Login.kgiquote_test_mode == 2)
                Thread.Sleep(1000);
            if (Login.kgiquote_test_mode == 1)// 12 idx
            {
                int counter = 0;
                string line;
                string[] tradedata;
                Console.WriteLine("Study mode.\nDon't connect to Kgi server.");
                Console.WriteLine("Load r:\\taitest.txt");
                System.IO.StreamReader file = new System.IO.StreamReader("r:\\taitest.txt");
                while ((line = file.ReadLine()) != null)
                {
                    tradedata = line.Split(' ');
                    msg.kgitrademin_p[counter] = int.Parse(tradedata[1]);
                    msg.kgitrademin_v[counter] = int.Parse(tradedata[2]);
                    counter++;
                }
                msg.kgi_idx = counter;
            }
            if (Login.kgiquote_test_mode == 3)// all tick
            {
                Thread simticksrvinit = new Thread(msg.simtick_init);
                simticksrvinit.Start();
            }
            else if (Login.kgiquote_test_mode == 0) // Real Trade 
            {
                quoteCom = new Intelligence.QuoteCom(Login.Srv("Q"), Login.Port, "API", "b6eb"); // Host changed on Oct/01/2014
                quoteCom.OnRcvMessage += Quotemsg.OnQuoteRcvMessage;
                quoteCom.OnGetStatus += Quotemsg.OnQuoteGetStatus;
                quoteCom.OnRecoverStatus += Quotemsg.OnRecoverStatus;
                quoteCom.OnRcvServerTime += Quotemsg.OnRcvServerTime;   //接收主機時間
                quoteCom.SourceId = "API";

                while (true)
                {
                    while (msg.kgiQuotesrv == false)
                    {
                        quoteCom.Connect2Quote(Login.Srv("Q"), Login.Port, Login.ID, Login.PW(), ' ', "TW."+ Login.tradeobj);
                        Console.WriteLine("Register Trade Obj : " + "TW." + Login.tradeobj);
                        Console.WriteLine("Kgi srv try con.");
                        Thread.Sleep(3000);
                        if (msg.kgiQuotesrv == true)
                        {
                            msg.kgisrv_wdg = true;
                            Console.WriteLine("Kgi srv connected");
                        }
                    }
                    Thread.Sleep(1000);
                    if (msg.kgi_idx >= 0)
                    {
                        while (msg.kgisrv_wdg)
                        {
                            msg.kgisrv_wdg = false;
                            msg.kgiQuotesrv = false;
                            Thread.Sleep(8000);
                        }
                        Console.WriteLine("Kgi srv WDG false");
                        short wdgtest = quoteCom.RetriveClosePrice();
                    }
                    if (msg.kginowidx >= 1400)
                    {
                        Console.WriteLine("Trade Time is end !");
                        while (msg.kginowidx >= 1400)
                            Thread.Sleep(10000);
                    }
                    Thread.Sleep(1000);
                }
            }
        }