コード例 #1
0
ファイル: RedisRepository.cs プロジェクト: galyamichevp/pet
        public async Task <CacheExchangeInfo> GetExchangeInfo(ExchangeType @base, ExchangeType target)
        {
            try
            {
                var exchangeInfoCache = await _distributedCache.GetAsync(@base.ToString());

                if (exchangeInfoCache == null)
                {
                    return new CacheExchangeInfo
                           {
                               BaseType = @base,
                               Rates    = Enumerable.Empty <ExchangeRateInfo>().ToList()
                           }
                }
                ;

                var exchangeInfoList = ZeroFormatterSerializer.Deserialize <CacheExchangeInfo>(exchangeInfoCache);

                return(target == ExchangeType.NONE
                    ? exchangeInfoList
                    : exchangeInfoList.FilterRatesByType(target));
            }
            catch (InvalidOperationException ex)
            {
                _logger.LogError(ex, ex.Message);
                throw ex;
            }
        }
コード例 #2
0
        public ServiceResponse <ExchangeModel> GetExchangeByName(ExchangeType exchangeType)
        {
            var response = new ServiceResponse <ExchangeModel>(null);

            //Check Redis
            var cacheKey = "Exchange:" + (int)exchangeType;
            var result   = _redisCacheManager.Get <ExchangeModel>(cacheKey);

            //-------------------------------
            if (result != null)
            {
                response.Entity = result;
                return(response);
            }
            else
            {
                var exchangeResult = _context.Exchange.Where(ex => ex.Name == exchangeType.ToString()).FirstOrDefault();
                if (exchangeResult != null)
                {
                    var model = _mapper.Map <ExchangeModel>(exchangeResult);
                    response.Entity       = model;
                    response.IsSuccessful = true;
                    _redisCacheManager.Set(cacheKey, response.Entity, DateTime.Now.AddMinutes(1));
                }
            }
            return(response);
        }
コード例 #3
0
 public static string GetTradeHistoryCachedDataFileName(ExchangeType e, string baseCurrency, string marketCurrency, DateTime start, DateTime end)
 {
     return(e.ToString() + "_" + baseCurrency + "_" + marketCurrency + "_" +
            DateTime2String(start) + "_" +
            DateTime2String(end) + "_" +
            "TradeHistory.xml");
 }
コード例 #4
0
 public static string GetCandlestickCachedDataFileName(ExchangeType e, string baseCurrency, string marketCurrency, int intervalMin, DateTime start, DateTime end)
 {
     return(e.ToString() + "_" + baseCurrency + "_" + marketCurrency + "_" + intervalMin + "_" +
            DateTime2String(start) + "_" +
            DateTime2String(end) + "_" +
            "CandlestickData.xml");
 }
コード例 #5
0
 public ExchangeDeclareParameters(string brokerName, ExchangeType exchangeType, bool exchangeDurable = false, bool exchangeAutoDelete = false)
 {
     BrokerName         = brokerName;
     ExchangeType       = exchangeType.ToString().ToLower();
     ExchangeDurable    = exchangeDurable;
     ExchangeAutoDelete = exchangeAutoDelete;
 }
コード例 #6
0
ファイル: RabbitMqProvider.cs プロジェクト: drtk712/Chegevala
        /// <summary>
        /// 为指定名称的channel创建Exchange
        /// </summary>
        /// <param name="channelName"></param>
        /// <param name="exchangeType"></param>
        /// <param name="exchangeName"></param>
        /// <returns></returns>
        public bool ConstructMqExchange(string channelName, ExchangeType exchangeType, string exchangeName)
        {
            if (string.IsNullOrEmpty(exchangeName))
            {
                LogHelper.LogError("Exchange Name Must Not Be NULL");
                return(false);
            }
            ConnectChannel channel = channelList.Find(n => n.ChannelName == channelName);

            if (channel == null)
            {
                LogHelper.LogError($"Channel {channelName} Not Exist.");
                return(false);
            }
            channel.ExchangeType = exchangeType;
            channel.ExchangeName = exchangeName;
            try
            {
                channel.ConsumerChannel.ExchangeDeclare(exchangeName, exchangeType.ToString(), true);
                return(true);
            }
            catch (Exception e)
            {
                LogHelper.LogError(e.Message);
                return(false);
            }
        }
コード例 #7
0
        internal void Declare(IModel channel)
        {
            if (DeclaredName == string.Empty)
            {
                return;
            }
            var exchangeTypeName = ExchangeType.ToString().ToLower();

            channel.ExchangeDeclare(DeclaredName, exchangeTypeName, IsDurable, AutoDelete, Arguments);
        }
コード例 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="exchange"></param>
 /// <param name="exchangeType"></param>
 /// <param name="arguments"></param>
 public void ExchangeDeclare(string exchange, ExchangeType exchangeType, IDictionary <string, object> arguments = null)
 {
     try
     {
         Channel.ExchangeDeclare(exchange, exchangeType.ToString().ToLower(), IsDurable, false, arguments);
     }
     catch (Exception e)
     {
         var msg = $"ExchangeDeclare exchange:{exchange} is exception {DateTime.Now}";
         EnterLogEvent(LogLevel.Error, msg, e);
         throw;
     }
 }
コード例 #9
0
ファイル: Publisher.cs プロジェクト: onetcore/gentings
        /// <summary>
        /// 发布对象实例。
        /// </summary>
        /// <param name="exchange">交换机名称。</param>
        /// <param name="exchangeType">交换机类型。</param>
        /// <param name="routingKey">路由键。</param>
        /// <param name="body">发送对象。</param>
        /// <param name="queue">队列名称。</param>
        /// <param name="persistent">是否永久性保存。</param>
        /// <param name="expires">过期时间(秒)。</param>
        /// <param name="headers">头部实例。</param>
        /// <param name="settingName">配置名称。</param>
        /// <returns>返回发布结果。</returns>
        public ApiResult Queue(
            string exchange,
            ExchangeType exchangeType,
            string routingKey,
            object body,
            string queue    = null,
            bool persistent = true,
            int expires     = 0,
            IDictionary <string, object> headers = null,
            string settingName = "Default")
        {
            try
            {
                if (body == null)
                {
                    return new ApiResult {
                               Message = Resources.ErrorCode_NullBody, Code = (int)ErrorCode.NullBody
                    }
                }
                ;
                var channel = _configuration.GetOrCreateChannel(routingKey, settingName);
                channel.ExchangeDeclare(exchange, exchangeType.ToString().ToLower(), persistent, false, null);
                if (!string.IsNullOrEmpty(queue))
                {
                    channel.QueueDeclare(queue, true, false, false, null);

                    channel.QueueBind(queue, exchange, routingKey, null);
                }

                var properties = channel.CreateBasicProperties();
                properties.Persistent = persistent;
                if (expires > 0)
                {
                    properties.Expiration = (expires * 1000).ToString();
                }
                properties.Headers = headers ?? new Dictionary <string, object>();

                var buffer = Encoding.UTF8.GetBytes(body.ToJsonString());
                channel.BasicPublish(exchange, routingKey, properties, buffer);
                return(ApiResult.Success);
            }
            catch (Exception exception)
            {
                return(new ApiResult {
                    Message = exception.Message, Code = (int)ErrorCode.Failure
                });
            }
        }
コード例 #10
0
        protected override bool GetTradesCore(ResizeableArray <TradeInfoItem> list, Ticker ticker, DateTime startTime, DateTime endTime)
        {
            string address = string.Format("https://www.bitmex.com/api/v1/trade?symbol={0}&count=1000&startTime={1}&endTime={2}", ticker.Name, DateToString(startTime), DateToString(endTime));
            string text    = string.Empty;

            try {
                text = GetDownloadString(address);

                if (string.IsNullOrEmpty(text))
                {
                    return(false);
                }
                if (text[0] == '{')
                {
                    JObject obj = JsonConvert.DeserializeObject <JObject>(text);
                    LogManager.Default.Add(LogType.Error, this, Type.ToString(), "error in GetTradesCore", obj.Value <string>("message"));
                    return(false);
                }
                JArray res = JsonConvert.DeserializeObject <JArray>(text);
                foreach (JObject obj in res.Children())
                {
                    TradeInfoItem item = new TradeInfoItem();
                    item.Ticker       = ticker;
                    item.RateString   = obj.Value <string>("price");
                    item.AmountString = obj.Value <string>("size");
                    item.Type         = obj.Value <string>("side")[0] == 'S' ? TradeType.Sell : TradeType.Buy;
                    item.TimeString   = obj.Value <string>("timestamp");
                    DateTime time = item.Time;
                    if (list.Last() == null || list.Last().Time <= time)
                    {
                        list.Add(item);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (Exception) {
                return(false);
            }
            return(true);
        }
コード例 #11
0
        internal void ConstructExchange()
        {
            if (String.IsNullOrEmpty(Exchange))
            {
                throw new ArgumentException("Set Exchange required");
            }

            creator.GetChannel().BasicQos(this.qosPrefetchSize, this.QosPreFetchLimit, this.qosGlobal);


            try{
                creator.GetChannel().ExchangeDeclare
                    (Exchange, ExchangeType.ToString(), Durable, AutoDelete);
            }
            catch (OperationInterruptedException e)
            {
                Console.WriteLine($"WARNING: {e.Message} so using EXISTING exchange");
                creator.GetChannel().ExchangeDeclarePassive(Exchange);
            }
        }
コード例 #12
0
ファイル: RabbitMqAgent.cs プロジェクト: SVemulapalli/jasper
        private void startNewConnection()
        {
            _connection = ConnectionActivator(ConnectionFactory);

            var channel = _connection.CreateModel();

            channel.CreateBasicProperties().Persistent = IsDurable;

            if (ExchangeName.IsNotEmpty())
            {
                channel.ExchangeDeclare(ExchangeName, ExchangeType.ToString().ToLowerInvariant(), IsDurable);
                channel.QueueDeclare(QueueName, IsDurable, autoDelete: false, exclusive: false);
                channel.QueueBind(QueueName, ExchangeName, "");
            }
            else
            {
                channel.QueueDeclare(QueueName, IsDurable, autoDelete: false, exclusive: false);
            }

            Channel = channel;
        }
コード例 #13
0
ファイル: RabbitMQAgent.cs プロジェクト: tmpreston/jasper
        public RabbitMqAgent(Uri uri)
        {
            if (uri.Scheme != "rabbitmq")
            {
                throw new ArgumentOutOfRangeException(nameof(uri), "The protocol must be 'rabbitmq'");
            }
            Uri = uri;

            ConnectionFactory.Port = uri.IsDefaultPort ? 5672 : uri.Port;


            var segments = uri.Segments.Where(x => x != "/").Select(x => x.TrimEnd('/')).ToArray();

            if (!segments.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(uri), "Unable to determine the routing key / queue for the Uri " + uri);
            }

            if (segments[0] == TransportConstants.Durable)
            {
                IsDurable = uri.IsDurable();
                segments  = segments.Skip(1).ToArray();
            }

            if (!segments.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(uri), "Unable to determine the routing key / queue for the Uri " + uri);
            }


            if (ExchangeType.TryParse <ExchangeType>(segments[0], out var exchangeType))
            {
                ExchangeType = exchangeType;
                segments     = segments.Skip(1).ToArray();
            }

            if (!segments.Any())
            {
                throw new ArgumentOutOfRangeException(nameof(uri), "Unable to determine the routing key / queue for the Uri " + uri);
            }


            if (segments.Length > 1)
            {
                ExchangeName = segments[0];
                QueueName    = segments.Skip(1).Join("/");
            }
            else
            {
                QueueName = segments.Single();
            }

            _connection = new Lazy <IConnection>(() => ConnectionActivator(ConnectionFactory));

            _model = new Lazy <IModel>(() =>
            {
                var channel = _connection.Value.CreateModel();
                channel.CreateBasicProperties().Persistent = IsDurable;

                if (ExchangeName.IsNotEmpty())
                {
                    channel.ExchangeDeclare(ExchangeName, ExchangeType.ToString(), IsDurable, false);
                    channel.QueueDeclare(QueueName, durable: IsDurable, autoDelete: false, exclusive: false);
                    channel.QueueBind(QueueName, ExchangeName, "");
                }
                else
                {
                    channel.QueueDeclare(QueueName, durable: IsDurable, autoDelete: false, exclusive: false);
                }

                return(channel);
            });
        }
コード例 #14
0
		public IExchangeConfigurationBuilder WithType(ExchangeType exchangeType)
		{
			Configuration.ExchangeType = exchangeType.ToString().ToLower();
			return this;
		}
コード例 #15
0
 /// <summary>
 /// 创建交换机
 /// </summary>
 /// <param name="Name"></param>
 /// <param name="Type"></param>
 public void CreateExchange(string Name, ExchangeType Type)
 {
     RabbitChannel.ExchangeDeclare(Name, Type.ToString(), true, false);
 }
 public IExchangeConfigurationBuilder WithType(ExchangeType exchangeType)
 {
     Configuration.ExchangeType = exchangeType.ToString().ToLower();
     return(this);
 }
コード例 #17
0
 public static string ToJsonString(this ExchangeType exchangeType)
 => exchangeType.ToString().ToLower();
コード例 #18
0
ファイル: RabbitMqAgent.cs プロジェクト: SVemulapalli/jasper
 public PublicationAddress PublicationAddress()
 {
     return(new PublicationAddress(ExchangeType.ToString(), ExchangeName, QueueName));
 }