Exemplo n.º 1
0
        public TradeBotBase(String stockid, string brokerid, string account, ushort BuyQty, Intelligence.QuoteCom quotecom, Smart.TaiFexCom taifexcom, int amountthreshold, BuyMode buymode, StopLossMode stoplossmode, LockGainMode lockgainmode)
        {
            this.stockid   = stockid;
            this.quotecom  = quotecom;
            this.taifexcom = taifexcom;
            this.brokerid  = brokerid;
            this.account   = account;
            this.BuyQty    = BuyQty;
            //this.StopLossRatio = stoplossratio;
            //this.LockGainPrice = lockgainprice;
            this.AmountThreshold = amountthreshold;
            this.buy_mode        = buymode;
            this.stoplossmode    = stoplossmode;
            this.lockgainmode    = lockgainmode;

            this.trade_status = TradeStatus.StandBy;
            OnStatusChange(this.trade_status, stockid + ":待命中");

            //初始化成交明細下載目錄
            this.MatchLogFolder = Path.Combine(Directory.GetCurrentDirectory(), DateTime.Now.ToString("yyyyMMdd"));
            //建立目錄
            if (!Directory.Exists(this.MatchLogFolder))
            {
                Directory.CreateDirectory(this.MatchLogFolder);
            }
        }
Exemplo n.º 2
0
        private double StopLossRatio     = 0.0;                  //停損百分比

        public TradeBot(String stockid, string brokerid, string account, ushort BuyQty, Intelligence.QuoteCom quotecom, Smart.TaiFexCom taifexcom, double stoplossratio)
        {
            this.stockid       = stockid;
            this.quotecom      = quotecom;
            this.taifexcom     = taifexcom;
            this.brokerid      = brokerid;
            this.account       = account;
            this.BuyQty        = BuyQty;
            this.StopLossRatio = stoplossratio;
        }
Exemplo n.º 3
0
 public TradeBotBase(String stockid, string brokerid, string account, ushort BuyQty, Intelligence.QuoteCom quotecom, Smart.TaiFexCom taifexcom, double stoplossratio, double lockgainprice, int amountthreshold, BuyMode buymode, StopLossMode stoplossmode, LockGainMode lockgainmode)
 {
     this.stockid       = stockid;
     this.quotecom      = quotecom;
     this.taifexcom     = taifexcom;
     this.brokerid      = brokerid;
     this.account       = account;
     this.BuyQty        = BuyQty;
     this.StopLossRatio = stoplossratio;
     this.LockGainPrice = lockgainprice;
     this.buy_mode      = buymode;
     this.stoplossmode  = stoplossmode;
     this.lockgainmode  = lockgainmode;
 }
Exemplo n.º 4
0
 GetTrade(String groupid)
 {
     quoteCom = new Intelligence.QuoteCom(host, port, SID, Token);
     quoteCom.OnRcvMessage    += OnQuoteRcvMessage;
     quoteCom.OnGetStatus     += OnQuoteGetStatus;
     quoteCom.OnRecoverStatus += OnRecoverStatus;
     quoteCom.QDebugLog        = false;
     quoteCom.FQDebugLog       = false;
     this.group          = groupid;
     this.downloadtarget = this.workspace + DateTime.Now.ToString("yyyyMMdd");
     //建立目錄
     if (!Directory.Exists(this.downloadtarget))
     {
         Directory.CreateDirectory(this.downloadtarget);
     }
 }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        public Form1()
        {
            InitializeComponent();
            #region Comfup Add
            InitializeComfup();
            #endregion
            quoteCom = new Intelligence.QuoteCom(cbHostStk.Text, 8000, tbSID.Text, tbToken.Text);
            quoteCom.OnRcvMessage    += OnQuoteRcvMessage;
            quoteCom.OnGetStatus     += OnQuoteGetStatus;
            quoteCom.OnRecoverStatus += OnRecoverStatus;
            quoteCom.QDebugLog        = false;
            quoteCom.FQDebugLog       = false;
            this.Text = "QuoteCom 範例程式 FOR 證券 [ Version : " + quoteCom.version + " ]";  //2014.6.19 ADD

            //先Create , 尚未正式連線,  IP 在正式連線時再輸入即可 ;
            tfcom = new TaiFexCom("10.4.99.71", 8000, "API");
            tfcom.OnRcvMessage    += OnTradeRcvMessage; //資料接收事件
            tfcom.OnGetStatus     += OnTradeGetStatus;  //狀態通知事件
            tfcom.OnRcvServerTime += OnRcvServerTime;   //接收主機時間
            tfcom.OnRecoverStatus += OnRecoverStatus;   //回補狀態通知
        }
Exemplo n.º 7
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);
                }
            }
        }