Esempio n. 1
0
 public void Stop()
 {
     try
     {
         if (_respSockets != null)
         {
             foreach (var i in _respSockets)
             {
                 i.Dispose();
             }
             _respSockets = null;
         }
     }
     catch (Exception e)
     {
         Utils.CommonLog.Error("关闭ZMQ监听套接字出现问题,{0}", e.Message);
     }
     try
     {
         if (_pubSocket != null)
         {
             _pubSocket.Dispose();
             _pubSocket = null;
         }
     }
     catch (Exception e)
     {
         Utils.CommonLog.Error("关闭Pub监听套接字出现问题,{0}", e.Message);
     }
     EnableRunning = false;
     ServerContainer.FinishStop();
 }
Esempio n. 2
0
 public void Stop()
 {
     if (_fileWather != null)
     {
         _fileWather.Changed -= OnChanged;
         _fileWather.Dispose();
         _fileWather = null;
     }
     ServerContainer.FinishStop();
 }
Esempio n. 3
0
        private void CopyProc()
        {
            TradeInfoEventArgs item = null;
            var sql = string.Empty;

            while (Utils.SignalWait(ref EnableRunning, _signal))
            {
                _queNewTrades.TryDequeue(out item);
                try
                {
                    var trade_type = item.TradeType;
                    var trade      = item.Trade;
                    var key        = string.Empty;
                    var handler    = OnNewTrade;
                    //if (handler != null)
                    //    handler(this, item);
                    //continue;
                    try
                    {
                        if (string.IsNullOrWhiteSpace(InnerServer))
                        {
                            sql = "SELECT user_code FROM user WHERE mt4=@mt4_id";
                            using (var cmd = new SQLiteCommand(sql, Source.CopySource))
                            {
                                cmd.Parameters.AddWithValue("@mt4_id", item.Trade.login);
                                var user_code_obj = cmd.ExecuteScalar();
                                var user_code     = string.Empty;
                                if (user_code_obj != null)
                                {
                                    user_code = user_code_obj.ToString();
                                }
                                item.Usercode = user_code;
                            }
                            sql = "SELECT mt4_from FROM copy_order WHERE order_to=@order_id";
                            using (var cmd = new SQLiteCommand(sql, Source.CopySource))
                            {
                                cmd.Parameters.AddWithValue("@order_id", item.Trade.order);
                                var from_obj = cmd.ExecuteScalar();
                                if (from_obj != null)
                                {
                                    item.FromUsercode = from_obj.ToString();
                                    item.ToUsercode   = item.Usercode;
                                }
                            }
                        }
                        else
                        {
                            using (var reqSocket = _zmqContext.CreateSocket(SocketType.Req))
                            {
                                reqSocket.Connect(InnerServer);
                                dynamic reqBody = new ExpandoObject();
                                reqBody.__api    = "InnerSearchUsercode";
                                reqBody.mt4_id   = trade.login;
                                reqBody.order_id = trade.order;
                                var req = JsonConvert.SerializeObject(reqBody) as string;
                                reqSocket.Send(req);
                                var repBody = _jss.Deserialize <dynamic>(reqSocket.RecvString());
                                var code    = Convert.ToInt32(repBody["ucode"]);
                                if (code != 0)
                                {
                                    item.Usercode = code.ToString();
                                }
                                var from_code = Convert.ToInt32(repBody["from_ucode"]);
                                if (from_code != 0)
                                {
                                    item.FromUsercode = from_code.ToString();
                                    item.ToUsercode   = code.ToString();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Utils.CommonLog.Error("组装订单出现问题,订单号{0},{1},{2}",
                                              trade.order, e.Message, e.StackTrace);
                    }
                    if (handler != null)
                    {
                        handler(this, item);
                    }
                    if ((trade_type == TRANS_TYPE.TRANS_ADD || trade_type == TRANS_TYPE.TRANS_UPDATE) &&
                        trade.cmd <= (int)Utils.TRADE_COMMAND.OP_SELL)
                    {
                        var apiEquity = Poll.New();
                        var equity    = 0.0;
                        var balance   = 0.0;
                        var free      = 0.0;
                        apiEquity.GetEquity(trade.login, ref equity, ref free, ref balance);
                        Poll.Release(apiEquity);
                        dynamic reqBody = new ExpandoObject();
                        reqBody.mt4_id  = trade.login;
                        reqBody.balance = balance;
                        reqBody.__api   = "InnerCheckCopyBalance";
                        using (var reqSocket = _zmqContext.CreateSocket(SocketType.Req))
                        {
                            reqSocket.Connect(CopyCheckAddr);
                            var req = JsonConvert.SerializeObject(reqBody) as string;
                            reqSocket.Send(req);
                            reqSocket.RecvString();
                        }
                    }
                    if (!Enable)
                    {
                        continue;
                    }
                    if (trade_type == TRANS_TYPE.TRANS_ADD &&
                        trade.comment == "copy")
                    {
                        continue;
                    }
                    Task.Factory.StartNew(() => { StartLink(trade_type, trade); });
                }
                catch (Exception e)
                {
                    Utils.CommonLog.Error(string.Format("复制服务出错,{0},{1}",
                                                        e.Message, e.StackTrace));
                }
            }
            ServerContainer.FinishStop();
        }
Esempio n. 4
0
 public void Stop()
 {
     ServerContainer.FinishStop();
 }