private OrderInfo CloseInternal(string code, double price, OrderSide orderSide, int mount) { if (mount <= 0) { return(null); } if (!CanClose(code, orderSide, mount)) { return(null); } OrderInfo orderInfo = new OrderInfo(code, this.Time, OpenCloseType.Close, price, mount, orderSide, OrderType.Market); orderInfo.OrderID = Guid.NewGuid().ToString(); this.historyOrders.Add(orderInfo); this.waitingOrders.Add(orderInfo); if (orderInfo != null) { OnReturnOrder?.Invoke(this, ref orderInfo); } if (AccountSetting.TradeType == AccountTradeType.IMMEDIATELY || AccountSetting.TradeType == AccountTradeType.MARKETPRICE) { DoTrade(orderInfo); } return(orderInfo); }
private OrderInfo OpenInternal(string code, double price, OrderSide orderSide, int mount) { //准备委托 double buymoney; OrderInfo orderInfo = PrepareOrderInfo(code, price, orderSide, mount, out buymoney); if (orderInfo == null) { return(null); } //将委托加入列表,并锁定金额 this.waitingOrders.Add(orderInfo); this.historyOrders.Add(orderInfo); this.money -= buymoney; this.dic_OrderID_LockMoney.Add(orderInfo.OrderID, buymoney); //执行委托后事件 if (orderInfo != null) { OnReturnOrder?.Invoke(this, ref orderInfo); } //立即成交或用市场价格成交,则立即执行交易 if (AccountSetting.TradeType == AccountTradeType.IMMEDIATELY || accountSetting.TradeType == AccountTradeType.MARKETPRICE ) { this.DoTrade(orderInfo); } else if (AccountSetting.TradeType == AccountTradeType.DELAYTICK) { ITickData tickData = this.realTimeDataReader.GetRealTimeData(code).GetTickData(); if (tickData != null) { OrderDelayInfo delayInfo = new OrderDelayInfo(); delayInfo.orderTickIndex = tickData.BarPos; this.dic_Code_OrderDelayInfo.Add(orderInfo.OrderID, delayInfo); } } return(orderInfo); }