Exemple #1
0
        static void Main(string[] args)
        {
            ChannelFactory <IStockQuoteService> tcpChanelFactory          = new ChannelFactory <IStockQuoteService>("tcpEndpoint");
            ChannelFactory <IStockQuoteService> pipeChanelFactory         = new ChannelFactory <IStockQuoteService>("pipeEndpoint");
            ChannelFactory <IStockQuoteService> httpChanelFactory         = new ChannelFactory <IStockQuoteService>("httpEndpoint");
            ChannelFactory <IStockQuoteService> wsHttpChanelFactory       = new ChannelFactory <IStockQuoteService>("wsHttpEndpoint");
            ChannelFactory <IStockQuoteService> ws2007HttpChanelFactory   = new ChannelFactory <IStockQuoteService>("ws2007HttpEndpoint");
            ChannelFactory <IStockQuoteService> cutomBindingChanelFactory = new ChannelFactory <IStockQuoteService>("customBinding");

            //Consuming Two one-way duplex service
            waitForResponse = new AutoResetEvent(false);
            InstanceContext callBackInstance = new InstanceContext(new Program());

            using (StockQuoteDuplexServiceClient client = new StockQuoteDuplexServiceClient(callBackInstance))
            {
                client.SendQuoteRequest("MSFT");
                waitForResponse.WaitOne();
            }
            //

            IStockQuoteService tcpClient               = tcpChanelFactory.CreateChannel();
            IStockQuoteService pipeClient              = pipeChanelFactory.CreateChannel();
            IStockQuoteService httpClient              = httpChanelFactory.CreateChannel();
            IStockQuoteService wsHttpClient            = wsHttpChanelFactory.CreateChannel();
            IStockQuoteService ws2007HttpClient        = ws2007HttpChanelFactory.CreateChannel();
            IStockQuoteService customBindingHttpClient = cutomBindingChanelFactory.CreateChannel();


            Console.WriteLine("TCP client : {0}", tcpClient.GetQuote("YHOO"));
            Console.WriteLine("Pipe client : {0}", pipeClient.GetQuote("YHOO"));
            Console.WriteLine("HTTP client : {0}", httpClient.GetQuote("YHOO"));
            Console.WriteLine("WS HTTP client : {0}", wsHttpClient.GetQuote("YHOO"));
            Console.WriteLine("WS2007 HTTP client : {0}", ws2007HttpClient.GetQuote("YHOO"));
            Console.WriteLine("Custom Binding TCP client : {0}", customBindingHttpClient.GetQuote("YHOO"));
            StockQuoteResponse.MsMqStarService();


            Console.ReadLine();
        }
Exemple #2
0
        /// <summary>
        /// Calculates based on SL,TP, price per unit etc potential earnings, risk management and p&l
        /// </summary>
        /// <param name="parameters">Base parameters</param>
        /// <returns>List with all quotations between SL and TP</returns>
        public ICalculationResult CalculatePotentialEarnings(ICalculation parameters)
        {
            ICalculationResult result = new CalculationResult();

            if (parameters == null)
            {
                return(result);
            }

            if (parameters.PricePerUnit == 0 || parameters.InitialSl == 0 || parameters.Units == 0)
            {
                return(result);
            }

            if (parameters.PricePerUnit == parameters.InitialSl || parameters.InitialTp == parameters.InitialSl)
            {
                return(result);
            }

            //WKN
            result.Wkn = parameters.Wkn;

            //ATR
            result.Atr = _stockQuoteService.GetAtr(parameters.Wkn);

            //CRV
            result.Crv =
                decimal.Round(
                    (parameters.InitialTp - parameters.PricePerUnit - (parameters.OrderCosts / parameters.Units)) /
                    (parameters.PricePerUnit - parameters.InitialSl + (parameters.OrderCosts / parameters.Units)), 2);

            //Posion size
            result.PositionSize = parameters.Units * parameters.PricePerUnit;

            //Is underlying used
            result.IsUnderlyingUsed = parameters.Multiplier != 1;

            //Break Even
            var be = decimal.Round(((2 * parameters.OrderCosts) / parameters.Units) + parameters.PricePerUnit, 2);

            //Current quotation
            var cur = _stockQuoteService.GetQuote(parameters.Wkn);

            //Step size for list
            var maxValue = parameters.InitialTp < cur ? cur : parameters.InitialTp;
            var minValue = parameters.InitialSl > cur ? cur : parameters.InitialSl;
            var stepSize = (maxValue - minValue) * Convert.ToDecimal(0.015);

            if ((maxValue / stepSize) % 2 != 0)
            {
                maxValue = maxValue + stepSize;
            }


            var value     = parameters.InitialSl;
            var buyCalc   = false;
            var beCalc    = false;
            var tpCalc    = false;
            var quoteCalc = false;

            //TP+ 10%
            while (value <= maxValue)
            {
                ICalculationQuotation quote = new CalculationQuotation();
                quote.Quotation           = value;
                quote.QuotationUnderlying = CalculatePriceFromUnderlying(value, parameters.Multiplier,
                                                                         parameters.StrikePrice, parameters.IsLong);

                quote.PlAbsolute =
                    decimal.Round(
                        (quote.Quotation * parameters.Units) - (2 * parameters.OrderCosts) -
                        (parameters.Units * parameters.PricePerUnit), 2);
                quote.PlPercentage = decimal.Round((quote.PlAbsolute / result.PositionSize) * 100, 2);

                quote.IsStoppLoss  = value == parameters.InitialSl;
                quote.IsTakeProfit = value == parameters.InitialTp;
                quote.IsBuy        = value == parameters.PricePerUnit;
                quote.IsBreakEven  = value == be;

                if (cur != 0)
                {
                    quote.IsCurrentQuotation = value == cur;
                }

                result.Quotation.Add(quote);

                value += stepSize;

                if (!buyCalc && value > parameters.PricePerUnit)
                {
                    value   = parameters.PricePerUnit;
                    buyCalc = true;
                }

                if (!beCalc && value > be)
                {
                    value  = be;
                    beCalc = true;
                }

                if (cur != 0 && !quoteCalc && value > cur)
                {
                    value     = cur;
                    quoteCalc = true;
                }

                if (!tpCalc && value > parameters.InitialTp)
                {
                    value  = parameters.InitialTp;
                    tpCalc = true;
                }
            }

            return(result);
        }