Exemplo n.º 1
0
        private void Unsubscribe(string strategyName, StrategySubscription symbol, string cacheKey, ITradeStrategy tradeStrategy)
        {
            if (Caches.TryGetValue(cacheKey, out ISubscriptionCache cache))
            {
                cache.Unsubscribe(strategyName, symbol, tradeStrategy);

                if (!cache.HasSubscriptions)
                {
                    if (Caches.TryRemove(cacheKey, out ISubscriptionCache cacheDispose))
                    {
                        cacheDispose.Dispose();
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Unsubscribe(string strategyName, StrategySubscription strategySubscription, ITradeStrategy tradeStrategy)
        {
            if (strategySubscription == null)
            {
                throw new ArgumentNullException(nameof(strategySubscription));
            }

            if (tradeStrategy == null)
            {
                throw new ArgumentNullException(nameof(tradeStrategy));
            }

            if (strategySubscription.Subscribes.HasFlag(Subscribes.AccountInfo))
            {
                subscribeAccountInfo.Unsubscribe(strategyName, tradeStrategy.SubscribeAccountInfoException);
            }
        }
        public static StrategySubscription ToWpfStrategySubscription(this Core.TradeStrategy.StrategySubscription coreStrategySubscription)
        {
            if (coreStrategySubscription == null)
            {
                throw new ArgumentNullException(nameof(coreStrategySubscription));
            }

            var strategySubScription = new StrategySubscription
            {
                AccountName         = coreStrategySubscription.AccountName,
                Symbol              = coreStrategySubscription.Symbol,
                Limit               = coreStrategySubscription.Limit,
                ApiKey              = coreStrategySubscription.ApiKey,
                ApiPassPhrase       = coreStrategySubscription.ApiPassPhrase,
                SecretKey           = coreStrategySubscription.SecretKey,
                Exchange            = coreStrategySubscription.Exchange,
                CandlestickInterval = coreStrategySubscription.CandlestickInterval.ToString()
            };

            if ((coreStrategySubscription.Subscribes & Core.TradeStrategy.Subscribes.AccountInfo) == Core.TradeStrategy.Subscribes.AccountInfo)
            {
                strategySubScription.SubscribeAccount = true;
            }

            if ((coreStrategySubscription.Subscribes & Core.TradeStrategy.Subscribes.Trades) == Core.TradeStrategy.Subscribes.Trades)
            {
                strategySubScription.SubscribeTrades = true;
            }

            if ((coreStrategySubscription.Subscribes & Core.TradeStrategy.Subscribes.OrderBook) == Core.TradeStrategy.Subscribes.OrderBook)
            {
                strategySubScription.SubscribeOrderBook = true;
            }

            if ((coreStrategySubscription.Subscribes & Core.TradeStrategy.Subscribes.Candlesticks) == Core.TradeStrategy.Subscribes.Candlesticks)
            {
                strategySubScription.SubscribeCandlesticks = true;
            }

            return(strategySubScription);
        }
Exemplo n.º 4
0
        public static StrategySubscription ToWpfStrategySubscription(this Interface.Strategy.StrategySubscription interfaceStrategySubscription)
        {
            var strategySubScription = new StrategySubscription
            {
                AccountName         = interfaceStrategySubscription.AccountName,
                Symbol              = interfaceStrategySubscription.Symbol,
                Limit               = interfaceStrategySubscription.Limit,
                ApiKey              = interfaceStrategySubscription.ApiKey,
                ApiPassPhrase       = interfaceStrategySubscription.ApiPassPhrase,
                SecretKey           = interfaceStrategySubscription.SecretKey,
                Exchange            = interfaceStrategySubscription.Exchange,
                CandlestickInterval = interfaceStrategySubscription.CandlestickInterval.ToString().Replace("_", " ")
            };

            if ((interfaceStrategySubscription.Subscribe & Interface.Strategy.Subscribe.AccountInfo) == Interface.Strategy.Subscribe.AccountInfo)
            {
                strategySubScription.SubscribeAccount = true;
            }

            if ((interfaceStrategySubscription.Subscribe & Interface.Strategy.Subscribe.Trades) == Interface.Strategy.Subscribe.Trades)
            {
                strategySubScription.SubscribeTrades = true;
            }

            if ((interfaceStrategySubscription.Subscribe & Interface.Strategy.Subscribe.OrderBook) == Interface.Strategy.Subscribe.OrderBook)
            {
                strategySubScription.SubscribeOrderBook = true;
            }

            if ((interfaceStrategySubscription.Subscribe & Interface.Strategy.Subscribe.Candlesticks) == Interface.Strategy.Subscribe.Candlesticks)
            {
                strategySubScription.SubscribeCandlesticks = true;
            }

            return(strategySubScription);
        }
Exemplo n.º 5
0
        public static MarketView.Interface.TradeStrategy.StrategySubscription GetInterfaceStrategySubscription(this StrategySubscription strategySubscription)
        {
            int subscribe = 0;

            if (strategySubscription.SubscribeAccount)
            {
                subscribe += 1;
            }

            if (strategySubscription.SubscribeTrades)
            {
                subscribe += 2;
            }

            if (strategySubscription.SubscribeOrderBook)
            {
                subscribe += 4;
            }

            if (strategySubscription.SubscribeStatistics)
            {
                subscribe += 8;
            }

            var interfaceStrategySubscription = new MarketView.Interface.TradeStrategy.StrategySubscription
            {
                Symbol    = strategySubscription.Symbol,
                Limit     = strategySubscription.Limit,
                ApiKey    = strategySubscription.ApiKey,
                SecretKey = strategySubscription.SecretKey,
                Exchange  = strategySubscription.Exchange,
                Subscribe = (MarketView.Interface.TradeStrategy.Subscribe)subscribe
            };

            return(interfaceStrategySubscription);
        }
Exemplo n.º 6
0
        public static Interface.Strategy.StrategySubscription ToInterfaceStrategySubscription(this StrategySubscription strategySubscription)
        {
            int subscribe = 0;

            if (strategySubscription.SubscribeAccount)
            {
                subscribe += 1;
            }

            if (strategySubscription.SubscribeTrades)
            {
                subscribe += 2;
            }

            if (strategySubscription.SubscribeOrderBook)
            {
                subscribe += 4;
            }

            if (strategySubscription.SubscribeCandlesticks)
            {
                subscribe += 8;
            }

            var interfaceStrategySubscription = new Interface.Strategy.StrategySubscription
            {
                AccountName         = strategySubscription.AccountName,
                Symbol              = strategySubscription.Symbol,
                Limit               = strategySubscription.Limit,
                ApiKey              = strategySubscription.ApiKey,
                SecretKey           = strategySubscription.SecretKey,
                ApiPassPhrase       = strategySubscription.ApiPassPhrase,
                Exchange            = strategySubscription.Exchange,
                Subscribe           = (Interface.Strategy.Subscribe)subscribe,
                CandlestickInterval = strategySubscription.CandlestickInterval.GetCandlestickInterval()
            };

            return(interfaceStrategySubscription);
        }
Exemplo n.º 7
0
 public void Unsubscribe(string strategyName, StrategySubscription strategySubscription, ITradeStrategy tradeStrategy)
 {
     throw new System.NotImplementedException();
 }
        public static Core.TradeStrategy.StrategySubscription ToCoreStrategySubscription(this StrategySubscription strategySubscription)
        {
            if (strategySubscription == null)
            {
                throw new ArgumentNullException(nameof(strategySubscription));
            }

            int subscribe = 0;

            if (strategySubscription.SubscribeAccount)
            {
                subscribe += 1;
            }

            if (strategySubscription.SubscribeTrades)
            {
                subscribe += 2;
            }

            if (strategySubscription.SubscribeOrderBook)
            {
                subscribe += 4;
            }

            if (strategySubscription.SubscribeCandlesticks)
            {
                subscribe += 8;
            }

            var coreStrategySubscription = new Core.TradeStrategy.StrategySubscription
            {
                AccountName         = strategySubscription.AccountName,
                Symbol              = strategySubscription.Symbol,
                Limit               = strategySubscription.Limit,
                ApiKey              = strategySubscription.ApiKey,
                SecretKey           = strategySubscription.SecretKey,
                ApiPassPhrase       = strategySubscription.ApiPassPhrase,
                Exchange            = strategySubscription.Exchange,
                Subscribes          = (Core.TradeStrategy.Subscribes)subscribe,
                CandlestickInterval = strategySubscription.CandlestickInterval.GetCandlestickInterval()
            };

            return(coreStrategySubscription);
        }