コード例 #1
0
        public Task SendToWait(string to, string subject, string content)
        {
            var t = Task.Factory.StartNew(() =>
            {
                try
                {
                    MailMessage mm     = new MailMessage();
                    MailAddress Fromma = new MailAddress(FromAddr);
                    MailAddress Toma   = new MailAddress(to, null);
                    mm.From            = Fromma;
                    //收件人
                    mm.To.Add(to);
                    //邮箱标题
                    mm.Subject    = subject;
                    mm.IsBodyHtml = true;
                    //邮件内容
                    mm.Body = content;
                    //内容的编码格式
                    mm.BodyEncoding = System.Text.Encoding.UTF8;
                    mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
                    mm.CC.Add(Toma);
                    sc.Send(mm);
                    var truncate = content.Length > 100 ? content.Substring(0, 100) : content;
                    log.Info(string.Format("{0}-{1}-{2}", to, subject, truncate));
                }
                catch (Exception e)
                {
                    log.Error(e, string.Format("{0}-{1}-{2}", to, subject, content.Length > 100?content.Substring(0, 100):content));
                }
            });

            return(t);
        }
コード例 #2
0
        public void Send(List <string> mobiles, string content, string corpid = "1", string proId = "1012818")
        {
            try
            {
                if (mobiles == null || mobiles.Count == 0 || string.IsNullOrEmpty(content))
                {
                    return;
                }

                //sname:提交用户
                //spwd:提交密码
                //scorpid:企业代码
                //sprdid:产品编号
                //sdst:接收号码,多个以','分割,不可超过100000个号码
                //smsg:短信内容
                ///submitdata/service.asmx/g_Submit?sname=string&spwd=string&scorpid=string&sprdid=string&sdst=string&smsg=string
                ///
                StringBuilder sb = new StringBuilder();
                sb.Append(url);
                sb.AppendFormat("/g_Submit?sname={0}&spwd={1}&scorpid={2}&sprdid={3}", name, pwd, corpid, proId);

                StringBuilder sb2 = new StringBuilder();
                foreach (var v in mobiles)
                {
                    sb2.AppendFormat("{0},", v);
                }
                if (sb2.Length > 0)
                {
                    sb2.Remove(sb2.Length - 1, 1);
                }
                sb.AppendFormat("&sdst={0}&smsg={1}", sb2.ToString(), content);

                var Url = sb.ToString();

                // CookieContainer cc = new CookieContainer();
                System.Net.HttpWebRequest wReq = (HttpWebRequest)System.Net.WebRequest.Create(Url);
                //wReq.CookieContainer = cc;

                // Get the response instance.
                System.Net.WebResponse wResp      = wReq.GetResponse();
                System.IO.Stream       respStream = wResp.GetResponseStream();
                string r = "";
                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.UTF8))
                {
                    r = reader.ReadToEnd();
                }
                log.Info(string.Format("{0}-{1}", sb.ToString(), r));
            }
            catch (Exception e)
            {
                log.Error(e);
            }
        }
コード例 #3
0
ファイル: BlockChainBtcPay.cs プロジェクト: 810912015/option
 T Except <T>(Func <T> f)
 {
     try
     {
         return(f());
     }
     catch (Exception e)
     {
         Log.Error(e, "btcPay");
         return(default(T));
     }
 }
コード例 #4
0
        void monitorTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                monitorTimer.Stop();
                var tl = GetTraderExceptRobot();

                foreach (var v in tl)
                {
                    var ratio         = v.GetMaintainRatio();
                    var shouldMonitor = ratio < SysPrm.Instance.MonitorParams.AlarmMaintainRatio;
                    var isMonitoring  = v.IsMonitoring();

                    if (shouldMonitor)
                    {
                        if (!isMonitoring)
                        {
                            log.Info(string.Format("开始监视:人{0}-率{1}-爆{2}-线程{3}",
                                                   v.Name, ratio, v.IsBlasting(),
                                                   Thread.CurrentThread.ManagedThreadId));
                            Monitor(v);
                        }
                    }
                    else
                    {
                        if (isMonitoring)
                        {
                            //log.Info(string.Format("",v.Name,ratio))
                            log.Info(string.Format("结束监视:人{0}-率{1}-爆{2}-线程{3}",
                                                   //"爆仓检查定时器:人{0}-监视信号{1}-爆仓信号{2}-线程{3}",
                                                   v.Name, ratio, v.IsBlasting(),
                                                   Thread.CurrentThread.ManagedThreadId));
                            Clear(v);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            finally
            {
                monitorTimer.Start();
            }
        }
コード例 #5
0
ファイル: Global.asax.cs プロジェクト: 810912015/option
        void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                t.Stop();

                Execute();
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
            finally
            {
                log.Info(thisLog.ToString());
                t.Start();
            }
        }
コード例 #6
0
ファイル: ArrangeChecker.cs プロジェクト: 810912015/option
 void t_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         t.Stop();
         Check();
     }
     catch (Exception ex)
     {
         log.Error(ex, "arrangeChecker");
     }
     finally
     {
         if (t != null)
         {
             t.Start();
         }
     }
 }
コード例 #7
0
 /// <summary>
 /// 成交后
 /// 持仓操作
 ///     开仓则增加持仓
 ///     平仓则减少持仓
 /// 保证金操作
 ///     如果是卖保证金,则冻结保证金
 ///     如果卖出去的权利仓自己又买回来了,则保证金解冻
 /// </summary>
 /// <param name="o"></param>
 /// <param name="count"></param>
 void MatchPosition(Order o, int count)
 {
     try
     {
         UserPosition up = new UserPosition //用户当前持仓
         {
             Id       = IdService <UserPosition> .Instance.NewId(),
             Order    = o,
             Trader   = o.Trader,
             DealTime = DateTime.Now,
             Count    = count
         };
         RaiseChanged(o.Trader, new List <UserPosition> {
             up
         }, o.IsPositionable()? true:false);
     }
     catch (Exception e)
     {
         log.Error(e, "持仓更新异常");
     }
 }
コード例 #8
0
ファイル: Blaster.cs プロジェクト: 810912015/option
 /// <summary>
 /// 计算平仓比率:需要平仓的份数
 /// 每份合约得到的资金数=释放的维持保证金-买入价格
 /// </summary>
 /// <param name="up"></param>
 /// <returns></returns>
 decimal CalRatio(Trader t, PositionSummary up, decimal needed)
 {
     try
     {
         if (up == null)
         {
             Log.Info(string.Format("计算比例时合约为空:仓{0}-人{1}", up.CName, t.Name));
             return(0);
         }
         var cp = Market.Get(up.CName).NewestDealPrice;
         var pp = up.GetReleasePerPos((a) => { return(model.Contracts.Where(c => c.Code == a).FirstOrDefault()); }, cp);
         var r  = needed / pp;
         Log.Info(string.Format("平仓份数:{0}-{1}-价{2}-释{3}-份{4}", t.Name, up.CName, cp, pp, r));
         return(r);
     }
     catch (Exception ex)
     {
         Log.Error(ex);
         return(0);
     }
 }
コード例 #9
0
 void t_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         t.Stop();
         //如果有1单则下对手单,否则按最新价加(-10,10)的随机数报单
         foreach (var v in tradeObjects)
         {
             decimal count = 0;
             decimal price = 0;
             int     dir   = 0;
             if (mu.GetS1Count(v) > 0)
             {
                 count = mu.GetS1Price(v);
                 price = mu.GetS1Price(v);
                 dir   = 1;
             }
             else if (mu.GetB1Count(v) > 0)
             {
                 count = mu.GetB1Count(v); price = mu.GetB1Count(v); dir = 2;
             }
             else
             {
                 count = new Random(DateTime.Now.Millisecond).Next(0, 10);
                 price = new Random(DateTime.Now.Millisecond).Next(-10, 10);
                 dir   = new Random(DateTime.Now.Millisecond).Next(1, 3);
             }
             om.OrderIt(v, count, price, dir, "");
         }
     }
     catch (Exception ex)
     {
         Log.Error(ex);
     }
     finally
     {
         t.Start();
     }
 }