Пример #1
0
        // add records into database
        private async Task BackTestFirstBuyOperationAsync(decimal buyPrice)
        {
            IReadOnlyList <IStockPriceHistory> items = await DatabaseOperations.GetStockPriceHistoryAsync(_memberStock.Country, _memberStock.StockId, BaseData.CurrentTime, 1).ConfigureAwait(false);

            if (items == null || items.Count == 0)
            {
                if (!_testStatus)
                {
                    _ = BaseData.GetLogger().WriteToErrorLogAsync(BaseData.Country, BaseData.CurrentTime, "TurtleBuyStrategy", new Exception($"BuyStockRunner: No stock price history data on previous business day of {BaseData.CurrentTime:yyyy-MM-dd}"));
                }

                return;
            }

            IStockPriceHistory item = items.FirstOrDefault();

            if (item == null)
            {
                return;
            }

            decimal N = -1m;

            // TODO : refactor
            switch (_memberStock.Strategy)
            {
            case BuySellStrategyType.N20:
                if (item.N20 != null)
                {
                    N = item.N20.Value;
                }

                break;

            case BuySellStrategyType.N40:
                if (item.N40 != null)
                {
                    N = item.N40.Value;
                }

                break;

            case BuySellStrategyType.N60:
                if (item.N60 != null)
                {
                    N = item.N60.Value;
                }

                break;
            }

            if (N == -1m)
            {
                return;
            }

            await DatabaseOperations.AddMemberBuyStockAsync(_memberStock.MemberEmail,
                                                            _memberStock.Country,
                                                            _memberStock.StockId,
                                                            buyPrice,
                                                            N,
                                                            _memberStock.Strategy,
                                                            BaseData.CurrentTime).ConfigureAwait(false);
        }