Ejemplo n.º 1
0
        private void checkBuyAction(DateTime currentDate, List <DailyChartInformation> copyOfNextDayDailyChart)
        {
            foreach (var action in actionList.FindAll(x => x.action == "buy"))
            {
                var matchStock = copyOfNextDayDailyChart.Find(x => x.stockID == action.ID);
                if (matchStock != null && matchStock.N_low <= action.bidPrice)
                {
                    decimal actualBuyPrice   = Math.Min(matchStock.N_open, action.bidPrice);
                    var     newStockPosition = new TradeRecord(matchStock.stockID, currentDate, actualBuyPrice);


                    newStockPosition.inMoney = action.buyAmount;
                    currentMoney            -= action.buyAmount;

                    currentStockPositions.Add(newStockPosition);
                    action.excuteMessage = $"success to buy for ${actualBuyPrice.round(2)}";
                }
                else if (matchStock != null)
                {
                    action.excuteMessage = $"fail to buy, N_low is ${matchStock.N_low}";
                }
                else
                {
                    action.excuteMessage = $"fail to buy, stock ID not found";
                }
                actionHistory.Add(action);
                actionList.Remove(action);
            }
        }
Ejemplo n.º 2
0
        private void forceSell(TradeRecord stockPositionToSell)
        {
            var price     = stockPositionToSell.lastAvailablePrice;
            var date      = stockPositionToSell.lastAvailableDate;
            var newAction = new TradeAction(date, "force sell", stockPositionToSell.ID, price);

            newAction.excuteMessage = $"force sell order on {date.ToString("yyyy-MM-dd")} for ${price}";
            actionHistory.Add(newAction);

            currentMoney += stockPositionToSell.currentValue;
            stockPositionToSell.sell(stockPositionToSell.lastAvailableDate, stockPositionToSell.lastAvailablePrice);
        }