static void ExecuteOneStock(StockData stockData) { /* * var revokeItems = GetRevokeItems(); * foreach(var item in revokeItems) * { * if(item.StockCode.Contains("xxxxxxx") // stockcode || item.ItemType == RevokeItem.Type.Buy // item type || item.Price > 0.00 || item.Amount > 10 || ) || { || Trader.RevokeByItemId(item.Id); || } ||} */ var CurrentAvailability = GetCurrentAvailabilityAmount(stockData.Code);//当前可用数量 if (CurrentAvailability == null) { Logger.Warn($"未找到 {stockData.Code} 持仓信息,终止执行"); return; } var position = GetCurrentAmount(stockData.Code); //当前持仓数目 Logger.Info($"{stockData.Code} 当前持仓数目: {position}"); if (position < 0) { Logger.Warn($"未找到 {stockData.Code} 持仓信息,终止执行"); return; } if (position <= stockData.Basebottom)// 如果某只股票的当前持仓数目小于设置的底舱数目,停止该只股票今日的所有操作 { Logger.Info($"{stockData.Code} 当前仓持仓 <= 底仓数目,停止操作"); AddStockToUnusedList(stockData); } else { if ((stockData.Totalinvestment - position * stockData.BasePrice) < stockData.FloorPrice * stockData.Intervalnumber) { Logger.Info($"{stockData.Code} 满仓,停止操作"); AddStockToUnusedList(stockData); } else { var stockStatus = Utils.GetStockStatus(stockData.Code, stockData.Market); Logger.Info($"{stockData.Code} {stockStatus.Name} 当前股价: {stockStatus.CurrentPrice} 基准:{ stockData.BasePrice},上限:{ stockData.CeilPrice},下限:{ stockData.FloorPrice}"); Logger.Info($"{stockData.Code} {stockStatus.Name} 初始持仓:{stockData.Initialposition} 当前持仓数目:{position}"); var currentPrice = stockStatus.CurrentPrice; if (currentPrice > stockData.CeilPrice) { Logger.Info($"{stockData.Code} {stockStatus.Name} 当前估价大于上限价格,判断为 卖出 成交一次"); //Logger.Info($"{stockData.Code} {stockStatus.Name} 卖出 成交一次"); Trader.Revoke(stockData.Code); CurrentAvailability = GetCurrentAvailabilityAmount(stockData.Code); Logger.Info($"{stockData.Code} {stockStatus.Name} 执行撤单 当前可用数量:{CurrentAvailability}"); if (CurrentAvailability == 0)// 如果某只股票的当前可用数量为0,停止该只股票今日的所有操作 { Logger.Info($"{stockData.Code} 可用数量为0,停止操作"); AddStockToUnusedList(stockData); } else { stockData.Initialposition = position; stockData.BasePrice = stockData.CeilPrice; var Price = AssignPrice(stockData.Code, stockData.BasePrice, stockData.PriceFix); stockData.FloorPrice = Price[0]; stockData.CeilPrice = Price[1]; Logger.Info($"初始化赋值 {stockData.Code} {stockStatus.Name} 基准:{stockData.BasePrice},上限:{stockData.CeilPrice},下限:{stockData.FloorPrice}"); Trader.Buy(stockData.Code, stockData.FloorPrice, stockData.Intervalnumber, stockStatus.Name); Trader.Sell(stockData.Code, stockData.CeilPrice, stockData.Intervalnumber, stockStatus.Name); } } else if (currentPrice < stockData.FloorPrice) { Logger.Info($"{stockData.Code} {stockStatus.Name} 当前股价小于下限价格,判断为 买入 成交一次"); //Logger.Info($"{stockData.Code} {stockStatus.Name} 买入 成交一次"); Trader.Revoke(stockData.Code); CurrentAvailability = GetCurrentAvailabilityAmount(stockData.Code); Logger.Info($"{stockData.Code} {stockStatus.Name} 执行撤单 当前可用数量:{CurrentAvailability}"); if (CurrentAvailability == 0)// 如果某只股票的当前可用数量为0,停止该只股票今日的所有操作 { Logger.Info($"{stockData.Code} 可用数量为0,停止操作"); AddStockToUnusedList(stockData); } else { stockData.Initialposition = position; stockData.BasePrice = stockData.FloorPrice; var Price = AssignPrice(stockData.Code, stockData.BasePrice, stockData.PriceFix); stockData.FloorPrice = Price[0]; stockData.CeilPrice = Price[1]; Logger.Info($"初始化赋值 {stockData.Code} {stockStatus.Name} 基准:{stockData.BasePrice},上限:{stockData.CeilPrice},下限:{stockData.FloorPrice}"); Trader.Buy(stockData.Code, stockData.FloorPrice, stockData.Intervalnumber, stockStatus.Name); Trader.Sell(stockData.Code, stockData.CeilPrice, stockData.Intervalnumber, stockStatus.Name); } } else //((currentPrice >= stockData.FloorPrice) && (currentPrice <= stockData.CeilPrice)) { if (position == (stockData.Initialposition + stockData.Intervalnumber)) { Logger.Info($"{stockData.Code} {stockStatus.Name} 持仓数量增加一个标准数量,判断为 买入 成交一次"); //Logger.Info($"{stockData.Code} {stockStatus.Name} 买入 成交一次"); Trader.Revoke(stockData.Code); CurrentAvailability = GetCurrentAvailabilityAmount(stockData.Code); Logger.Info($"{stockData.Code} {stockStatus.Name} 执行撤单 当前可用数量:{CurrentAvailability}"); if (CurrentAvailability == 0)// 如果某只股票的当前可用数量为0,停止该只股票今日的所有操作 { Logger.Info($"{stockData.Code} 可用数量为0,停止操作"); AddStockToUnusedList(stockData); } else { stockData.Initialposition = position; stockData.BasePrice = stockData.FloorPrice; var Price = AssignPrice(stockData.Code, stockData.BasePrice, stockData.PriceFix); stockData.FloorPrice = Price[0]; stockData.CeilPrice = Price[1]; Logger.Info($"初始化赋值 {stockData.Code} {stockStatus.Name} 基准:{stockData.BasePrice},上限:{stockData.CeilPrice},下限:{stockData.FloorPrice}"); Trader.Buy(stockData.Code, stockData.FloorPrice, stockData.Intervalnumber, stockStatus.Name); Trader.Sell(stockData.Code, stockData.CeilPrice, stockData.Intervalnumber, stockStatus.Name); } } if (position == (stockData.Initialposition - stockData.Intervalnumber)) { Logger.Info($"{stockData.Code} {stockStatus.Name} 持仓数量 减少 一个标准数量,判断为 卖出 成交一次"); //Logger.Info($"{stockData.Code} {stockStatus.Name} 卖出 成交一次"); Trader.Revoke(stockData.Code); CurrentAvailability = GetCurrentAvailabilityAmount(stockData.Code); Logger.Info($"{stockData.Code} {stockStatus.Name} 执行撤单 当前可用数量:{CurrentAvailability}"); if (CurrentAvailability == 0)// 如果某只股票的当前可用数量为0,停止该只股票今日的所有操作 { Logger.Info($"{stockData.Code} 可用数量为0,停止操作"); AddStockToUnusedList(stockData); } else { stockData.Initialposition = position; stockData.BasePrice = stockData.CeilPrice; var Price = AssignPrice(stockData.Code, stockData.BasePrice, stockData.PriceFix); stockData.FloorPrice = Price[0]; stockData.CeilPrice = Price[1]; Logger.Info($"初始化赋值 {stockData.Code} {stockStatus.Name} 基准:{stockData.BasePrice},上限:{stockData.CeilPrice},下限:{stockData.FloorPrice}"); Trader.Buy(stockData.Code, stockData.FloorPrice, stockData.Intervalnumber, stockStatus.Name); Trader.Sell(stockData.Code, stockData.CeilPrice, stockData.Intervalnumber, stockStatus.Name); } } } } } }
static void AddStockToUnusedList(StockData stockData) { //结束程序 自动关机 发个邮件提醒(因当当前可用数量为0,所以停止 stockData.Code 股票操作 Logger.Info($"添加 {stockData} 至待移除列表"); UnusedStockDataList.Add(stockData); }