public IHttpActionResult Get(int id, int start = 0, int end = 0, string indicator = "")
        {
            int             MINI_TICKER = 30;
            TickerViewModel tickerVM    = new TickerViewModel();
            List <Ticker>   tickerList  = null;

            IndicatorBLL iBLL = new IndicatorBLL(_unit);


            try
            {
                if (end == 0)
                {
                    end = DateHelper.DateToInt(DateTime.Now);
                }

                tickerList = new TickerBLL(_unit).GetTickerListByShareDB(id, start, end);

                // Load indicators
                tickerVM.TickerList = tickerList;

                if (!string.IsNullOrEmpty(indicator) && tickerList.Count >= MINI_TICKER)
                {
                    tickerVM.Indicators = iBLL.GetIndicators(tickerList, indicator);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(tickerVM));
        }
        public async void TestGetEMA()
        {
            IndicatorBLL indBll = new IndicatorBLL(this.s3_bucket_name, this.tempTickerFolder);

            var smaResult = await indBll.GetEMA("CCL", 20, 2, 20100101);

            Console.WriteLine(ObjectHelper.ToJson(smaResult));
        }
        public void Test_SearchShareByWatch()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            var tickerList = iBLL.SearchShareByWatch(15, 20160427, false);

            tickerList = iBLL.SearchShareByWatch(15, 20160427, true);
        }
        public void Test_GetIndicatorListByShareDate()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            var iList = iBLL.GetIndicatorListByShareDate(1585, 0, 0);

            Assert.IsTrue(iList.Count > 0);
        }
        public void Test_GetIndicators()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);
            TickerBLL    tBll = new TickerBLL(_unit);

            var tickerList = tBll.GetTickerListByShareDB(1585, 20100101, 20160520);

            iBLL.GetIndicators(tickerList, "sma,10|ema,20");
        }
        public void Test_UpdateIndicatorsBatchDB()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            List <Indicator> iList = (from c in _unit.DataContext.Indicator
                                      where c.ShareId == 1585
                                      select c).ToList();

            iBLL.UpdateIndicatorsBatchDB(iList);
        }
        public void Test_SearchShareDayTicker()
        {
            var tickerLast = new TickerBLL(_unit).GetLastTicker(1585, null);

            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            if (tickerLast != null)
            {
                iBLL.SearchShareDayTicker(tickerLast.TradingDate, tickerLast.TradingDate);
            }
        }
Exemple #8
0
        private List <Entity.Indicator> GetIndicatorsForTrade(TradePosition position, int dateToProcess)
        {
            List <Entity.Indicator> iList = new List <Entity.Indicator>();

            int startDate = this.GetPositionStartDate(position);

            IndicatorBLL iBll = new IndicatorBLL(_unit);

            iList = iBll.GetIndicatorListByShareDate(position.ShareId, startDate, dateToProcess).OrderByDescending(p => p.TradingDate).ToList();
            List <Ticker> tList = new TickerBLL(_unit).GetTickerListByShareDB(position.ShareId, startDate, dateToProcess).OrderByDescending(p => p.TradingDate).ToList();

            iBll.PopulateIndicatorsWithTickers(iList, tList);

            return(iList.OrderBy(p => p.TradingDate).ToList());
        }
        public IHttpActionResult SearchStockDailyLatest()
        {
            List <OutStockSearchResult> sList = new List <OutStockSearchResult>();

            try
            {
                sList = new IndicatorBLL(_unit).GetShareDayTickerLatest();
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(sList));
        }
        public IHttpActionResult SearchStockDailyByWatch(int watchId, int tradingDate, bool reverse)
        {
            List <OutStockSearchResult> sList = new List <OutStockSearchResult>();

            try
            {
                sList = new IndicatorBLL(_unit).SearchShareByWatch(watchId, tradingDate, reverse);
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(sList));
        }
Exemple #11
0
        public IHttpActionResult GetSMA(int id, int period, int start = 0, int end = 0, bool byCalculate = true)
        {
            List <SMAViewModel> smaList = null;

            try
            {
                IndicatorBLL iBLL = new IndicatorBLL(_unit);

                smaList = iBLL.GetSMAByShareID(id, period, start, end);
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(smaList));
        }
        public void PopulateReview(TradeReview review)
        {
            TransactionBLL   tBLL  = new TransactionBLL(_unit);
            TradePositionBLL tpBll = new TradePositionBLL(_unit);
            IndicatorBLL     iBll  = new IndicatorBLL(_unit);
            TickerBLL        tkBll = new TickerBLL(_unit);

            OutPosition pos = tpBll.GetOutPositionById(review.TradePositionId);

            Transaction entryTr = tBLL.GetByID(pos.EntryTransactionId);

            Entity.Indicator entryInd = iBll.GetIndicatorByShareDate(pos.ShareId, entryTr.TradingDate);
            Ticker           entryT   = tkBll.GetTickerByDate(pos.ShareId, entryTr.TradingDate);

            iBll.PopulateIndicatorWithTicker(entryInd, entryT);

            review.IsEntryLong = pos.Size > 0 ? true : false;

            if (entryInd.BB_Low.HasValue && entryInd.BB_High.HasValue)
            {
                review.BBEntryPercent = 100 * (entryTr.Price - entryInd.BB_Low.Value) / (entryInd.BB_High.Value - entryInd.BB_Low.Value);
            }

            review.EntryPercent = 100 * (entryTr.Price - entryInd.Low.Value) / (entryInd.High.Value - entryInd.Low.Value);

            if (pos.ExitTransactionId.HasValue)
            {
                Transaction      exitTr  = new TransactionBLL(_unit).GetByID(pos.ExitTransactionId.Value);
                Entity.Indicator exitInd = new IndicatorBLL(_unit).GetIndicatorByShareDate(pos.ShareId, exitTr.TradingDate);
                Ticker           exitT   = tkBll.GetTickerByDate(pos.ShareId, exitTr.TradingDate);
                iBll.PopulateIndicatorWithTicker(exitInd, exitT);

                if (exitInd.BB_Low.HasValue && exitInd.BB_High.HasValue)
                {
                    review.BBExitPercent = 100 * (exitTr.Price - exitInd.BB_Low.Value) / (exitInd.BB_High.Value - exitInd.BB_Low.Value);
                }

                review.ExitPercent = 100 * (exitTr.Price - exitInd.Low.Value) / (exitInd.High.Value - exitInd.Low.Value);

                review.DaysSpan = pos.Days;
                review.Diff     = pos.Diff;
                review.Diff_Per = pos.Diff_Per;
            }
        }
Exemple #13
0
        public async Task <ActionResult> Get_ATR(string code, int period = 14, int start = 0, int end = 0, string type = "day")
        {
            IndicatorBLL bll = new IndicatorBLL(this.s3_bucket_name, this.local_temp_folder);

            IndSingleValueEntity[] resultList;

            if (type.ToLower() == "day")
            {
                resultList = await bll.GetATR(code, period, start, end, "day");
            }
            else if (type.ToLower() == "week")
            {
                resultList = await bll.GetATR(code, period, start, end, "week");
            }
            else
            {
                return(BadRequest($"Wrong type input: {type}"));
            }

            return(Ok(resultList));
        }
Exemple #14
0
        public async Task <ActionResult> Get_MACD(string code, int slow = 26, int fast = 12, int signal = 9, int start = 0, int end = 0, string type = "day")
        {
            IndicatorBLL bll = new IndicatorBLL(this.s3_bucket_name, this.local_temp_folder);

            IndMACDEntity[] resultList;

            if (type.ToLower() == "day")
            {
                resultList = await bll.GetMACD(code, slow, fast, signal, start, end, "day");
            }
            else if (type.ToLower() == "week")
            {
                resultList = await bll.GetMACD(code, slow, fast, signal, start, end, "week");
            }
            else
            {
                return(BadRequest($"Wrong type input: {type}"));
            }

            return(Ok(resultList));
        }
        public IHttpActionResult SearchStockDaily(int tradingDate)
        {
            List <OutStockSearchResult> sList = new List <OutStockSearchResult>();

            if (tradingDate <= 0)
            {
                return(BadRequest("trading date must be provided..."));
            }

            try
            {
                sList = new IndicatorBLL(_unit).SearchShareDayTicker(tradingDate, tradingDate);
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                return(InternalServerError(ex));
            }

            return(Ok(sList));
        }
Exemple #16
0
        public IHttpActionResult GetIndicatorByShareDate(int shareId, int tradingDate)
        {
            Screen2.Entity.Indicator indicator;
            Ticker t;

            t = new TickerBLL(_unit).GetTickerByDate(shareId, tradingDate);

            indicator = new IndicatorBLL(_unit).GetIndicatorByShareDate(shareId, tradingDate);


            if ((t != null) && (indicator != null))
            {
                indicator.Open          = t.Open;
                indicator.High          = t.High;
                indicator.Low           = t.Low;
                indicator.Volumn        = t.Volumn;
                indicator.AdjustedClose = t.AdjustedClose;
            }

            return(Ok(indicator));
        }
Exemple #17
0
        public Entity.Indicator[] LoadIndicators(int shareID, int startDate, int?endDate)
        {
            Screen2.Entity.Indicator[] indicatorResult = null;

            // -1 for no criteria
            int end = -1;

            if (endDate.HasValue)
            {
                end = endDate.Value;
            }

            indicatorResult = new IndicatorBLL(_unit).GetIndicatorListByShareDate(shareID, startDate, end).ToArray();

            var tickers = this.GetTickers(shareID, startDate, end).ToArray();

            this.PopulateIndicatorList(indicatorResult, tickers);

            this.Indicators = indicatorResult;

            return(indicatorResult);
        }
Exemple #18
0
        public List <OutStockSearchResult> SearchAlert(string userId, int tradingDate, bool force, int?zoneId)
        {
            List <OutStockSearchResult> searchResult = new List <OutStockSearchResult>();
            List <AlertResult>          arList       = this.GetAlertResultDB(tradingDate, zoneId);

            if (arList.Count == 0)
            {
                force = true;
            }

            if (force)
            {
                arList = new List <AlertResult>();
                var alertList = _unit.DataContext.Alert.Where(a => a.IsActive &&
                                                              a.Owner == userId &&
                                                              a.ZoneId == zoneId).ToList();

                foreach (Alert a in alertList)
                {
                    AlertResult aResult = CheckAlert(a, tradingDate);
                    arList.Add(aResult);
                }

                var arBll = new AlertResultBLL(_unit);
                // remove and add result
                arBll.DeleteAlertResultByAlert(tradingDate, zoneId);
                arBll.AddAlertResultBatch(arList);
            }
            arList = arList.Where(c => c.IsMatch).ToList();

            string shareListString = GetShareListString(arList);

            searchResult = new IndicatorBLL(_unit).SearchShareByShareString(shareListString, tradingDate);

            return(searchResult);
        }
        public void Test_GetSMAByShareID()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            iBLL.GetSMAByShareID(1585, 10, 20000000, 0);
        }
        public List <OutStockSearchResult> SearchScan(int tradingDate, int scanId, bool force)
        {
            DailyScanResultBLL          dsrBll       = new DailyScanResultBLL(_unit);
            DailyScanBLL                dsBll        = new DailyScanBLL(_unit);
            List <OutStockSearchResult> searchResult = new List <OutStockSearchResult>();
            List <DailyScanResult>      dsrList      = null;

            if (!force)
            {
                dsrList = dsrBll.GetDailyScanResult(tradingDate, scanId);

                if (dsrList.Count == 0)
                {
                    force = true;
                }
            }

            if (force)
            {
                dsrList = new List <DailyScanResult>();
                DailyScan       ds = dsBll.GetByID(scanId);
                DailyScanResult dsr;
                List <int>      shareIDs  = GetShareListByDailyScan(ds);
                string          className = string.Empty;
                string          formula   = string.Empty;

                if (ds.UseRule)
                {
                    var rule = new RuleBLL(_unit).GetByID(ds.RuleId.Value);

                    if (rule.Type.Equals("Assembly", StringComparison.InvariantCultureIgnoreCase))
                    {
                        className = rule.Assembly;
                    }
                    else
                    {
                        formula = rule.Formula;
                    }
                }
                else
                {
                    formula = ds.Formula;
                }

                if (string.IsNullOrEmpty(className))
                {
                    foreach (int shareId in shareIDs)
                    {
                        try
                        {
                            dsr = EvaluateScanShare(shareId, tradingDate, formula, ds);

                            if (dsr.IsMatch)
                            {
                                dsrList.Add(dsr);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error(_log, string.Format("Error Process daily on share ({0}) at {1}. ", shareId, tradingDate), ex);
                        }
                    }
                }
                else
                {
                    dsrList = this.RunDailyScanByAssembly(ds, className, tradingDate);
                }

                dsrBll.DeleteDailyScanResultByDailyScan(scanId, tradingDate);
                dsrBll.AddDailyScanResultBatch(dsrList);
            }

            dsrList = dsrList.Where(c => c.IsMatch).ToList();

            string shareListString = GetShareListString(dsrList);

            searchResult = new IndicatorBLL(_unit).SearchShareByShareString(shareListString, tradingDate);

            return(searchResult);
        }
        public void Test_GetLatestIndicator()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            Indicator ind = iBLL.GetLatestIndicator(2);
        }
        public void Test_UpdateDeltIndicatorsFull()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            iBLL.UpdateDeltIndicatorsFull();
        }
        public void Test_GetLatestTradingDate()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            var tDate = iBLL.GetLatestTradingDate();
        }
Exemple #24
0
        public IHttpActionResult GetLatestTradingDate()
        {
            var latestTradingDate = new IndicatorBLL(_unit).GetLatestTradingDate();

            return(Ok(latestTradingDate));
        }
Exemple #25
0
        public IHttpActionResult GetLatestTradingDateByShare(int shareId)
        {
            var latestTradingDate = new IndicatorBLL(_unit).GetLatestTradingDateByShare(shareId);

            return(Ok(latestTradingDate));
        }
        public void Test_GetShareDayTickerLatest()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            var stockList = iBLL.GetShareDayTickerLatest();
        }
        public void Test_GetShareDayTickerByWatch()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            var tickerList = iBLL.GetShareDayTickerByWatch(1, false);
        }
        public void Test_ProcessIndicator()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            iBLL.ProcessIndicator(1585);
        }
        public void Test_ProcessIndicatorFull()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            iBLL.ProcessIndicatorFull();
        }
        public void Test_SaveIndicatorsBatch()
        {
            IndicatorBLL iBLL = new IndicatorBLL(_unit);

            List <Indicator> lIndicator = new List <Indicator>();

            Indicator ind = new Indicator {
                TradingDate = 1,
                ShareId     = 1,
                Close       = 0.1,
                //PreviousClose = 0.1,
                SMA5   = 5,
                SMA10  = 10,
                SMA30  = 20,
                SMA50  = 50,
                SMA200 = 200
            };

            lIndicator.Add(ind);

            for (int i = 0; i < 1000; i++)
            {
                ind = new Indicator
                {
                    TradingDate  = 1,
                    ShareId      = 2,
                    Close        = 0.1,
                    SMA5         = i,
                    SMA10        = null,
                    SMA30        = 20,
                    SMA50        = 50,
                    SMA200       = 200,
                    EMA10        = 10,
                    EMA20        = 20,
                    EMA50        = 50,
                    ADX          = 1,
                    ADX_Minus    = 1,
                    ADX_Plus     = 2,
                    BB_High      = 1,
                    BB_Low       = 2,
                    BB_Middle    = 1.5,
                    Heikin_Close = 1,
                    Heikin_High  = 2,
                    Heikin_Low   = 1,
                    Heikin_Open  = 1,
                    MACD         = 1,
                    MACD_Hist    = 2,
                    MACD_Signal  = 3,
                    RSI          = 2,
                    Stochastic_D = 1,
                    Stochastic_K = 3,
                    WR           = 100
                };

                if (i % 3 == 0)
                {
                    //ind.PreviousClose = i;
                }

                lIndicator.Add(ind);
            }

            iBLL.SaveIndicatorsBatchDB(lIndicator);
        }