コード例 #1
0
        public async Task DoSomething()
        {
            Console.WriteLine("Recurring job.");
            var quoateData = await alphaVantage.GetQuote("MSFT");

            Console.WriteLine(quoateData.Open + "for MSFT");
            var portfvalue = await portOper.GetPortfolioValue_Historical();

            Console.WriteLine("Portfolio value " + portfvalue);
        }
コード例 #2
0
        public async Task Execute()
        {
            TargetSymbols = await portOper.GetSymbols();

            Console.WriteLine("EXECUTING STRATEGY-------------------------------");
            foreach (var symbol in TargetSymbols)
            {
                var myq = await alphaVantage.GetQuote(symbol);

                if (myq != null)
                {
                    Console.WriteLine($" {DateTime.Now.ToShortDateString()} {symbol} Price: {myq.Price}");
                    if (await portOper.QuoteNotExists(symbol, myq.LatestTradingDay))
                    {
                        await portOper.AddQuoteToHistoryDB(myq);
                    }
                    else
                    {
                        //Console.WriteLine("Quote exists. Please don't add to DB");
                    }

                    //mark to market-portfolio
                    await portOper.MarkToMarket(myq);

                    var maxPrice = await portOper.GetMax(HistoricIntervalDays, symbol);

                    if (myq.Price >= maxPrice)
                    {
                        var myTransaction = await portOper.Buy(symbol, myq.Price, ExposurePerStock, PurchaseAmount);

                        if (myTransaction > 0)
                        {
                            Console.WriteLine($"--Decision: Buy {symbol} for {myq.Price} USD");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"--Condition not met to buy: {symbol} for {myq.Price} USD as maxPrice is {maxPrice}");
                    }

                    var avgPrice = await portOper.GetAverage(HistoricIntervalDays, symbol);

                    if (myq.Price <= avgPrice * (1 - lossPercentage / 100))
                    {
                        var myTransaction = await portOper.Sell(symbol, myq.Price);

                        if (myTransaction > 0)
                        {
                            Console.WriteLine($"--Decision: Sell all positions for Stock: {symbol} price: {myq.Price} USD");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"--Condition not met to sell: {symbol} for {myq.Price} USD as limit Price is {avgPrice * (1 - lossPercentage / 100)}");
                    }
                }
                Thread.Sleep(12000);
            }

            decimal Portfoliovalue = await portOper.GetPortfolioValue_Historical();

            Console.WriteLine($"Portfolio Value = {Portfoliovalue}\n =================================");
        }