Esempio n. 1
0
        /// <summary>
        /// 更新当天数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private void dayrefrash(object data)
        {
            day = BotUnit.getDay();
            addSummary();
            String result = getRequest.future_kline(symbol, "1day", contractType, "1", "");

            String[] sArray = result.Split(',');
            double.TryParse(sArray[1], out dayBegin);
        }
Esempio n. 2
0
        /// <summary>
        /// 添加交易信息
        /// </summary>
        /// <param name="str">添加的信息内容</param>
        /// <returns></returns>
        public void 交易信息_Add(String str)
        {
            String add = BotUnit.getLocalTime() + ": " + str;

            交易信息.Text += add + CSRF;
            this.交易信息.Focus();
            this.交易信息.Select(this.交易信息.TextLength, 0);
            this.交易信息.ScrollToCaret();
            fw.WriteLine(add);
            fw.Flush();
        }
Esempio n. 3
0
 /// <summary>
 /// 主线程运行函数,每秒执行一次查询
 /// </summary>
 /// <returns></returns>
 private void run()
 {
     while (true)
     {
         ThreadPool.QueueUserWorkItem(getPrice, null);
         if (day != BotUnit.getDay())
         {
             ThreadPool.QueueUserWorkItem(dayrefrash, null);
         }
         if (timecount != minBetween)
         {
             timecount++;
         }
         if (wait != -1 && wait != 60)
         {
             wait++;
         }
         Thread.Sleep(1000);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// “开始”按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        private void 开始_Click(object sender, EventArgs e)
        {
            String time     = BotUnit.getLocalTime();
            int    day      = BotUnit.getDay();
            String filename = "log" + time + ".txt";

            filename = filename.Replace(" ", "");
            filename = filename.Replace(":", "");
            filename = filename.Replace("\\", "");
            filename = filename.Replace("/", "");
            FileStream fs = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);

            fw = new StreamWriter(fs);
            try
            {
                double   initCoin;
                double   exchangeCoin;
                int      minBetween;
                String   symbol;
                String   contractType;
                String   type;
                Strategy strategy;
                {
                    if (!double.TryParse(初始币数.Text, out initCoin) ||
                        !double.TryParse(单次交易.Text, out exchangeCoin))
                    {
                        throw new Exception("初始币数与单次交易必须为数字");
                    }
                    if (!int.TryParse(最短间隔.Text, out minBetween))
                    {
                        throw new Exception("最短间隔必须为数字");
                    }
                    if (MACD_choice.Checked)
                    {
                        double rate;
                        if (!double.TryParse(MACD_rate.Text, out rate))
                        {
                            throw new Exception("交易策略比率为必填");
                        }
                        strategy    = new Strategy("MACD");
                        strategy.p1 = rate;
                    }
                    else if (KDJ_choice.Checked)
                    {
                        double rate;
                        if (!double.TryParse(KDJ_rate.Text, out rate))
                        {
                            throw new Exception("交易策略比率为必填");
                        }
                        strategy    = new Strategy("KDJ");
                        strategy.p1 = rate;
                    }
                    else if (MA_choice.Checked)
                    {
                        int rate1, rate2;
                        if (!int.TryParse(MAsmall.Text, out rate1))
                        {
                            throw new Exception("交易策略比率为必填");
                        }
                        if (!int.TryParse(MAbig.Text, out rate2))
                        {
                            throw new Exception("交易策略比率为必填");
                        }
                        if (rate1 > 60 || rate2 > 60)
                        {
                            throw new Exception("MA策略参数过大,最大60");
                        }
                        strategy    = new Strategy("MA");
                        strategy.p1 = rate1;
                        strategy.p2 = rate2;
                    }
                    else
                    {
                        throw new Exception("交易策略必须选择");
                    }
                    if (BTC.Checked)
                    {
                        symbol = "btc_usd";
                    }
                    else if (LTC.Checked)
                    {
                        symbol = "ltc_usd";
                    }
                    else if (ETH.Checked)
                    {
                        symbol = "eth_usd";
                    }
                    else if (ETC.Checked)
                    {
                        symbol = "etc_usd";
                    }
                    else if (BCH.Checked)
                    {
                        symbol = "bch_usd";
                    }
                    else if (BTG.Checked)
                    {
                        symbol = "btg_usd";
                    }
                    else if (XRP.Checked)
                    {
                        symbol = "xrp_usd";
                    }
                    else if (EOS.Checked)
                    {
                        symbol = "eos_usd";
                    }
                    else
                    {
                        throw new Exception("请选择一个合约");
                    }
                    if (本周.Checked)
                    {
                        contractType = "this_week";
                    }
                    else if (周.Checked)
                    {
                        contractType = "next_week";
                    }
                    else if (季度.Checked)
                    {
                        contractType = "quarter";
                    }
                    else
                    {
                        throw new Exception("请选择一个合约期限");
                    }
                    if (一分钟.Checked)
                    {
                        type = "1min";
                    }
                    else if (分钟.Checked)
                    {
                        type = "3min";
                    }
                    else if (五分钟.Checked)
                    {
                        type = "5min";
                    }
                    else if (十五分钟.Checked)
                    {
                        type = "15min";
                    }
                    else if (十分钟.Checked)
                    {
                        type = "30min";
                    }
                    else if (一小时.Checked)
                    {
                        type = "1hour";
                    }
                    else if (两小时.Checked)
                    {
                        type = "2hour";
                    }
                    else if (四小时.Checked)
                    {
                        type = "4hour";
                    }
                    else if (六小时.Checked)
                    {
                        type = "6hour";
                    }
                    else if (十二小时.Checked)
                    {
                        type = "12hour";
                    }
                    else if (日.Checked)
                    {
                        type = "1day";
                    }
                    else if (周.Checked)
                    {
                        type = "1week";
                    }
                    else
                    {
                        throw new Exception("请选择时间梯度");
                    }
                }
                thread = new MainThread(this, initCoin, exchangeCoin, strategy, symbol, contractType, type, minBetween, time, day);
            } catch (Exception err)
            {
                交易信息_Add("系统启动失败");
                交易信息_Add(err.Message);
                return;
            }
            set策略选择Unable();
        }