Ejemplo n.º 1
0
 public MacdMAStrategy()
 {
     _jobService         = new JobService();
     _watchlistService   = new WatchlistService();
     _userSessionService = new UserSessionService();
     _strategyService    = new StrategyService();
 }
Ejemplo n.º 2
0
        public WatchlistController()
        {
            var clientId     = ConfigurationManager.AppSettings["ClientId"];
            var clientSecret = ConfigurationManager.AppSettings["ClientSecret"];

            _watchlistService = WatchlistApiClientFactory.Create(Environment.UAT, clientId, clientSecret);
        }
        public async Task MovieIsInUserWatchlistShouldReturnCorrectResult()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var movie1 = new Movie
            {
                Name        = "movie1",
                ReleaseDate = DateTime.Parse("24 July 2019"),
                Description = "description1",
                Length      = 160,
                Genre       = new Genre {
                    Name = "genre1"
                },
                Director       = artist1,
                CoverImageLink = "cover1",
                TrailerLink    = "trailer1",
            };
            var movieUser = new MovieUser
            {
                User  = user1,
                Movie = movie1,
            };
            await dbContext.Users.AddAsync(user1);

            await dbContext.Movies.AddAsync(movie1);

            await dbContext.MovieUsers.AddAsync(movieUser);

            await dbContext.SaveChangesAsync();

            var userId  = user1.Id;
            var movieId = movie1.Id;

            var watchlistService = new WatchlistService(dbContext, mapper);

            var movieResult = await watchlistService.MovieIsInUserWatchlistAsync(userId, movieId);

            var invalid1 = await watchlistService.MovieIsInUserWatchlistAsync("invalidUserId", movieId);

            var invalid2 = await watchlistService.MovieIsInUserWatchlistAsync(userId, "invalidMovieId");

            Assert.True(movieResult);
            Assert.False(invalid1);
            Assert.False(invalid2);
        }
        public async Task GetItemsInUserWatchlistShouldReturnEmptyListWithEmptyDb()
        {
            var watchlistService = new WatchlistService(dbContext, mapper);

            var expectedResult = new List <WatchlistAllViewModel>();

            var actualResult = await watchlistService.GetItemsInUserWatchlistAsync("userId");

            Assert.Equal(expectedResult, actualResult);
        }
        public async Task IsIdMovieOrTVShowIdShouldReturnCorrectResult()
        {
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var movie1 = new Movie
            {
                Name        = "movie1",
                ReleaseDate = DateTime.Parse("24 July 2019"),
                Description = "description1",
                Length      = 160,
                Genre       = new Genre {
                    Name = "genre1"
                },
                Director       = artist1,
                CoverImageLink = "cover1",
                TrailerLink    = "trailer1",
            };
            var tvShow1 = new TVShow
            {
                Name        = "tvShow1",
                Description = "description2",
                Genre       = new Genre {
                    Name = "genre2"
                },
                Creator        = artist1,
                CoverImageLink = "cover2",
                TrailerLink    = "trailer2",
            };
            await dbContext.Movies.AddAsync(movie1);

            await dbContext.TVShows.AddAsync(tvShow1);

            await dbContext.SaveChangesAsync();

            var movieId  = movie1.Id;
            var tvShowId = tvShow1.Id;

            var watchlistService = new WatchlistService(dbContext, mapper);

            var movieResult = await watchlistService.IsIdMovieOrTVShowIdAsync(movieId);

            var seasonResult = await watchlistService.IsIdMovieOrTVShowIdAsync(tvShowId);

            var invalid = await watchlistService.IsIdMovieOrTVShowIdAsync("invalidId");

            Assert.Equal("Movie", movieResult);
            Assert.Equal("TV Show", seasonResult);
            Assert.Equal("Neither", invalid);
        }
        public async Task TVShowIsInUserWatchlistShouldReturnCorrectResult()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var tvShow1 = new TVShow
            {
                Name        = "tvShow1",
                Description = "description2",
                Genre       = new Genre {
                    Name = "genre2"
                },
                Creator        = artist1,
                CoverImageLink = "cover2",
                TrailerLink    = "trailer2",
            };
            var tvShowUser = new TVShowUser
            {
                User   = user1,
                TVShow = tvShow1,
            };
            await dbContext.Users.AddAsync(user1);

            await dbContext.TVShows.AddAsync(tvShow1);

            await dbContext.TVShowUsers.AddAsync(tvShowUser);

            await dbContext.SaveChangesAsync();

            var userId   = user1.Id;
            var tvShowId = tvShow1.Id;

            var watchlistService = new WatchlistService(dbContext, mapper);

            var tvShowResult = await watchlistService.TVShowIsInUserWatchlistAsync(userId, tvShowId);

            var invalid1 = await watchlistService.TVShowIsInUserWatchlistAsync("invalidUserId", tvShowId);

            var invalid2 = await watchlistService.TVShowIsInUserWatchlistAsync(userId, "invalidTvShowId");

            Assert.True(tvShowResult);
            Assert.False(invalid1);
            Assert.False(invalid2);
        }
        public async Task RemoveMovieFromUserWatchlistShouldShouldRemoveMovieFromWatchlistProperly()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var movie1 = new Movie
            {
                Name        = "movie1",
                ReleaseDate = DateTime.Parse("24 July 2019"),
                Description = "description1",
                Length      = 160,
                Genre       = new Genre {
                    Name = "genre1"
                },
                Director       = artist1,
                CoverImageLink = "cover1",
                TrailerLink    = "trailer1",
            };
            var movieUser = new MovieUser
            {
                User  = user1,
                Movie = movie1,
            };
            await dbContext.Users.AddAsync(user1);

            await dbContext.Movies.AddAsync(movie1);

            await dbContext.MovieUsers.AddAsync(movieUser);

            await dbContext.SaveChangesAsync();

            var userId  = user1.Id;
            var movieId = movie1.Id;

            var watchlistService = new WatchlistService(dbContext, mapper);

            Assert.True(dbContext.MovieUsers.Count() == 1);

            await watchlistService.RemoveMovieFromUserWatchlistAsync(userId, movieId);

            Assert.True(dbContext.MovieUsers.Count() == 0);
        }
        public async Task WeeklyWatchlistIsProfitableOrNot()
        {
            List <PositionTestModel> positionWeekTestModels = new List <PositionTestModel>();
            //Get All Candles according to
            MAStrategy mAStrategy         = new MAStrategy();
            var        watchlistService   = new WatchlistService();
            var        userSessionService = new UserSessionService();

            var symbols = await watchlistService.GetSymbols(1);

            var userSession = await userSessionService.GetCurrentSession();

            var weekStart = 5;

            if (userSession != null)
            {
                var zeropdhaService = new ZerodhaBroker(new UserSessionModel()
                {
                    AccessToken = userSession.AccessToken,
                    ApiKey      = userSession.ApiKey,
                    AppSecret   = userSession.AppSecret,
                    PublicToken = userSession.PublicToken,
                    UserId      = userSession.UserId
                });

                for (int i = 0; i < 5; i++)
                {
                    List <PositionTestModel> positionTestModels = new List <PositionTestModel>();
                    Parallel.ForEach(symbols.Take(50), symbol =>
                    {
                        var candles = zeropdhaService.GetData(
                            symbol, mAStrategy._HistoricalDataTimeframe,
                            new DateTime(2018, 3, weekStart + i, 18, 0, 0).AddDays(mAStrategy._HistoricalDataInDays),
                            //DateTime.Now
                            new DateTime(2018, 3, weekStart + i, 18, 0, 0),
                            false);

                        positionTestModels.Add(GetProfitOfDay(symbol, candles));
                    });

                    positionWeekTestModels.Add(new PositionTestModel()
                    {
                        dateTime       = new DateTime(2018, 3, weekStart + i, 0, 0, 0),
                        NoOfPositions  = positionTestModels.Where(x => x != null).Sum(x => x.NoOfPositions),
                        NoOfProfitable = positionTestModels.Where(x => x != null).Sum(x => x.NoOfProfitable),
                        NoOfStopHit    = positionTestModels.Where(x => x != null).Sum(x => x.NoOfStopHit),
                        Profit         = positionTestModels.Where(x => x != null).Sum(x => x.Profit)
                    });
                }
            }
            Assert.IsTrue(positionWeekTestModels.Where(x => x != null).Sum(x => x.Profit) > 1, "Week is Not Profitable");
        }
Ejemplo n.º 9
0
        public Task Execute(IJobExecutionContext context)
        {
            ApplicationLogRepository applogs          = new ApplicationLogRepository();
            WatchlistService         WatchlistService = new WatchlistService();

            try
            {
                var resultswnt = WatchlistService.ExecuteWatchListMailAlertSWNT(WatchlistAlertFrequency.WhenAvailable);
                return(null);
            }
            catch (Exception ex)
            {
                applogs.AppLogManager("WatchListAvailAlertSWNT", "WatchListAlertJob", "Error: " + ex.ToString());
                return(null);
            }
        }
Ejemplo n.º 10
0
        public Task Execute(IJobExecutionContext context)
        {
            ApplicationLogRepository applogs          = new ApplicationLogRepository();
            WatchlistService         WatchlistService = new WatchlistService();

            try
            {
                var resultunsc = WatchlistService.GetUnscFromMappingNSendMail();
                return(null);
            }
            catch (Exception ex)
            {
                applogs.AppLogManager("WatchListAvailAlertUNSCSendMail", "WatchListAlertJob", "Error: " + ex.ToString());
                return(null);
            }
        }
        public async Task AddTVShowToUserWatchlistShouldShouldAddMovieTouserWatchlistProperly()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var tvShow1 = new TVShow
            {
                Name        = "movie1",
                Description = "description1",
                Genre       = new Genre {
                    Name = "genre1"
                },
                Creator        = artist1,
                CoverImageLink = "cover1",
                TrailerLink    = "trailer1",
            };
            await dbContext.Users.AddAsync(user1);

            await dbContext.TVShows.AddAsync(tvShow1);

            await dbContext.SaveChangesAsync();

            var userId   = user1.Id;
            var tvShowId = tvShow1.Id;

            var watchlistService = new WatchlistService(dbContext, mapper);

            Assert.True(dbContext.TVShowUsers.Count() == 0);

            await watchlistService.AddTVShowToUserWatchlistAsync(userId, tvShowId);

            Assert.True(dbContext.TVShowUsers.Count() == 1);

            Assert.Equal(dbContext.TVShowUsers.First().TVShow, tvShow1);
            Assert.Equal(dbContext.TVShowUsers.First().User, user1);
        }
Ejemplo n.º 12
0
 public WatchListController()
 {
     WatchlistService = new WatchlistService();
 }
        public async Task GetItemsInUserWatchlistShouldReturnWatchlistProperly()
        {
            var user1 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar",
            };
            var user2 = new MovieDatabaseUser
            {
                UserName   = "******",
                Email      = "*****@*****.**",
                AvatarLink = "avatar2",
            };
            var artist1 = new Artist
            {
                FullName  = "name1",
                Biography = "biography1",
                BirthDate = DateTime.Parse("25 July 2019"),
                PhotoLink = "photo1",
            };
            var movie1 = new Movie
            {
                Name        = "movie1",
                ReleaseDate = DateTime.Parse("24 July 2019"),
                Description = "description1",
                Length      = 160,
                Genre       = new Genre {
                    Name = "genre1"
                },
                Director       = artist1,
                CoverImageLink = "cover1",
                TrailerLink    = "trailer1",
            };
            var tvShow1 = new TVShow
            {
                Name        = "tvShow1",
                Description = "description2",
                Genre       = new Genre {
                    Name = "genre2"
                },
                Creator        = artist1,
                CoverImageLink = "cover2",
                TrailerLink    = "trailer2",
            };
            var season1 = new Season
            {
                TVShow           = tvShow1,
                SeasonNumber     = 1,
                Episodes         = 20,
                LengthPerEpisode = 45,
                ReleaseDate      = DateTime.Parse("24 July 2019"),
            };
            var movieUser = new MovieUser
            {
                User  = user1,
                Movie = movie1,
            };
            var movieUser2 = new MovieUser
            {
                User  = user2,
                Movie = movie1,
            };
            var movieReview = new MovieReview
            {
                User    = user1,
                Movie   = movie1,
                Content = "content1",
                Rating  = 6,
                Date    = DateTime.UtcNow,
            };
            var tvShowUser = new TVShowUser
            {
                User   = user1,
                TVShow = tvShow1,
            };
            var seasonReview = new SeasonReview
            {
                User    = user1,
                Season  = season1,
                Content = "content2",
                Rating  = 5,
                Date    = DateTime.UtcNow,
            };
            await dbContext.Users.AddAsync(user1);

            await dbContext.Movies.AddAsync(movie1);

            await dbContext.TVShows.AddAsync(tvShow1);

            await dbContext.Seasons.AddAsync(season1);

            await dbContext.MovieUsers.AddAsync(movieUser);

            await dbContext.MovieUsers.AddAsync(movieUser2);

            await dbContext.TVShowUsers.AddAsync(tvShowUser);

            await dbContext.MovieReviews.AddAsync(movieReview);

            await dbContext.SeasonReviews.AddAsync(seasonReview);

            await dbContext.SaveChangesAsync();

            var userId    = user1.Id;
            var movie1Id  = movie1.Id;
            var tvShow1Id = tvShow1.Id;

            var watchlistService = new WatchlistService(dbContext, mapper);

            var expectedResult = new List <WatchlistAllViewModel>
            {
                new WatchlistAllViewModel
                {
                    Id             = movie1Id,
                    Name           = "movie1",
                    ReleaseDate    = DateTime.Parse("24 July 2019"),
                    Description    = "description1....",
                    CoverImageLink = "cover1",
                    Category       = "Movies",
                    Rating         = 6,
                },
                new WatchlistAllViewModel
                {
                    Id             = tvShow1Id,
                    Name           = "tvShow1",
                    ReleaseDate    = DateTime.Parse("24 July 2019"),
                    Description    = "description2....",
                    CoverImageLink = "cover2",
                    Category       = "TVShows",
                    Rating         = 5,
                }
            };

            var actualResult = await watchlistService.GetItemsInUserWatchlistAsync(userId);

            Assert.True(actualResult.Count() == 2);

            Assert.Equal(expectedResult[0].Id, actualResult[0].Id);
            Assert.Equal(expectedResult[0].Name, actualResult[0].Name);
            Assert.Equal(expectedResult[0].ReleaseDate, actualResult[0].ReleaseDate);
            Assert.Equal(expectedResult[0].Description, actualResult[0].Description);
            Assert.Equal(expectedResult[0].CoverImageLink, actualResult[0].CoverImageLink);
            Assert.Equal(expectedResult[0].Category, actualResult[0].Category);
            Assert.Equal(expectedResult[0].Rating, actualResult[0].Rating);

            Assert.Equal(expectedResult[1].Id, actualResult[1].Id);
            Assert.Equal(expectedResult[1].Name, actualResult[1].Name);
            Assert.Equal(expectedResult[1].ReleaseDate, actualResult[1].ReleaseDate);
            Assert.Equal(expectedResult[1].Description, actualResult[1].Description);
            Assert.Equal(expectedResult[1].CoverImageLink, actualResult[1].CoverImageLink);
            Assert.Equal(expectedResult[1].Category, actualResult[1].Category);
            Assert.Equal(expectedResult[1].Rating, actualResult[1].Rating);
        }
        public async Task RegressionMonthlyWatchlistIsProfitableOrNot()
        {
            List <PositionTestModel> positionWeekTestModels = new List <PositionTestModel>();
            //Get All Candles according to
            MAStrategy mAStrategy         = new MAStrategy();
            var        watchlistService   = new WatchlistService();
            var        userSessionService = new UserSessionService();

            var symbols = await watchlistService.GetSymbols(1);

            var userSession = await userSessionService.GetCurrentSession();

            var weekStart = new DateTime(2018, 2, 5, 9, 0, 0).StartOfWeek(DayOfWeek.Monday);

            IList <PositionTestModel> positionTestModels = new List <PositionTestModel>();

            for (int emaShortPeriodCounter = 3; emaShortPeriodCounter < 20; emaShortPeriodCounter++)
            {
                for (int emaLongPeriodCounter = emaShortPeriodCounter += 1; emaLongPeriodCounter < 25; emaLongPeriodCounter++)
                {
                    mAStrategy._EmaShortPeriod = emaShortPeriodCounter;
                    mAStrategy._EmaLongPeriod  = emaLongPeriodCounter;
                    for (int weekCounter = 0; weekCounter < 4; weekCounter++)
                    {
                        DateTime tempWeekStart = weekStart.AddDays(weekCounter * 7);
                        if (userSession != null)
                        {
                            var zeropdhaService = new ZerodhaBroker(new UserSessionModel()
                            {
                                AccessToken = userSession.AccessToken,
                                ApiKey      = userSession.ApiKey,
                                AppSecret   = userSession.AppSecret,
                                PublicToken = userSession.PublicToken,
                                UserId      = userSession.UserId
                            });

                            for (int dayCounter = 0; dayCounter < 5; dayCounter++)
                            {
                                Parallel.ForEach(symbols.Take(50), symbol =>
                                {
                                    var candles = zeropdhaService.GetData(
                                        symbol, mAStrategy._HistoricalDataTimeframe,
                                        new DateTime(2018, 3, tempWeekStart.Day + dayCounter, 9, 0, 0).AddDays(mAStrategy._HistoricalDataInDays),
                                        //DateTime.Now
                                        new DateTime(2018, 3, tempWeekStart.Day + dayCounter, 18, 0, 0),
                                        false);

                                    positionTestModels.Add(GetProfitOfDay(symbol, candles, mAStrategy));
                                });

                                positionWeekTestModels.Add(new PositionTestModel()
                                {
                                    EMA            = emaShortPeriodCounter + ", " + emaLongPeriodCounter,
                                    Period         = mAStrategy._HistoricalDataTimeframe,
                                    dateTime       = new DateTime(2018, 3, tempWeekStart.Day + dayCounter, 0, 0, 0),
                                    NoOfPositions  = positionTestModels.Where(x => x != null).Sum(x => x.NoOfPositions),
                                    NoOfProfitable = positionTestModels.Where(x => x != null).Sum(x => x.NoOfProfitable),
                                    NoOfStopHit    = positionTestModels.Where(x => x != null).Sum(x => x.NoOfStopHit),
                                    Profit         = positionTestModels.Where(x => x != null).Sum(x => x.Profit)
                                });
                            }
                        }
                    }
                }
            }

            positionWeekTestModels.WriteCSV(@"D:\Work\Autotrading\Results\RegressionMonth-" + mAStrategy._HistoricalDataTimeframe + ".csv");
            Assert.IsTrue(positionWeekTestModels.Where(x => x != null).Sum(x => x.Profit) > 1, "Week is Not Profitable");
        }