Example #1
0
        public void ReloadHistoryPriceTicker(int shareId)
        {
            SettingBLL sBLL     = new SettingBLL(_unit);
            ShareBLL   shareBLL = new ShareBLL(_unit);

            try
            {
                //remove existing tickers
                this.RemoveHistoryPriceTicker(shareId);

                int historyYear = int.Parse(sBLL.Get(s => s.Key ==
                                                     SettingKey.HistoryDataYears.ToString()).Single().Value);

                DateTime start = DateTime.Now.AddYears(-1 * historyYear);

                Share share = shareBLL.GetByID(shareId);

                this.UploadHistoryPriceTicker(share.Symbol, start, DateTime.Now);
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, ex.ToString());
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Gets the daily share ticker from yahoo.
        /// </summary>
        /// <param name="symbol">The y symbol.</param>
        /// <param name="startDate">The start date.</param>
        /// <param name="endDate">The end date.</param>
        /// <returns></returns>
        public List <Ticker> GetDailyShareTickerFromYahoo(string symbol, DateTime startDate, DateTime endDate)
        {
            List <Ticker> enList = new List <Ticker>();

            HistQuotesDownload         hsDownload = new HistQuotesDownload();
            HistQuotesDownloadSettings settings   = new HistQuotesDownloadSettings();

            var share = new ShareBLL(_unit).GetShareBySymbol(symbol);

            try
            {
                if (share != null)
                {
                    settings.ID       = symbol;
                    settings.FromDate = startDate;
                    settings.ToDate   = endDate;
                    settings.Interval = HistQuotesInterval.Daily;

                    hsDownload.Settings = settings;

                    Response <HistQuotesResult> resp = hsDownload.Download();

                    if (resp != null && resp.Result != null && resp.Result.Chains.Length == 1)
                    {
                        var tickerArray = resp.Result.Chains[0];

                        foreach (var t in tickerArray)
                        {
                            Ticker en = new Ticker();

                            en.TradingDate   = DateHelper.DateToInt(t.TradingDate);
                            en.AdjustedClose = t.CloseAdjusted;
                            en.High          = t.High;
                            en.Low           = t.Low;
                            en.Open          = t.Open;
                            en.Close         = t.Close;
                            en.Volumn        = t.Volume;
                            en.ShareId       = share.Id;
                            en.JSTicks       = DateHelper.DateToJSTicks(t.TradingDate);

                            enList.Add(en);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(_log, "Error load share tickers from yahoo. ", ex);
                throw;
            }
            return(enList);
        }
Example #3
0
        public Transaction CreateTransaction(TradeOrder order, Entity.Indicator ind)
        {
            Share       s  = new ShareBLL(_unit).GetByID(order.ShareId);
            Transaction tr = new Transaction
            {
                Direction    = order.Direction,
                Message      = string.Format("{0} {1} * {2} @ ${3}", order.Direction, s.Symbol, order.Size, order.OrderPrice),
                ModifiedBy   = order.UpdatedBy,
                ModifiedDate = DateTime.Now,
                Price        = order.OrderPrice,
                Size         = order.Size,
                Fee          = order.Fee,
                TradingDate  = ind.TradingDate,
                TradeOrderId = order.Id
            };

            this.Create(tr);
            return(tr);
        }
Example #4
0
        public void UpoadHistoryPriceAllShares(DateTime start, DateTime end)
        {
            ShareBLL sBLL = new ShareBLL(_unit);

            List <Share> shareList = sBLL.GetList().ToList();

            string resultMessage;

            foreach (Share s in shareList)
            {
                try
                {
                    this.UploadHistoryPriceTicker(s.Symbol, start, end);

                    resultMessage = string.Format("Success load price for {0}", s.Symbol);
                }
                catch (Exception ex)
                {
                    resultMessage = string.Format("Fail load price for {0} \n {1}", s.Symbol, ex.ToString());
                }

                LogHelper.Info(_log, resultMessage);
            }
        }
Example #5
0
 public ShareInfoBLL(IUnitWork unit) : base(unit)
 {
     _sBLL     = new ShareBLL(_unit);
     _auditBLL = new AuditLogBLL(_unit);
 }