private void InsertToMock(Order order) { if (order.CloseOrders.Count == 0) { OnRspQryOrder(this, new OrderEventArgs(() => Add(order))); order.RemainVolume = order.Volume; order.OrderRef = tradeApi.MaxOrderRef++.ToString(); order.FrontID = tradeApi.FrontID; order.SessionID = tradeApi.SessionID; order.TradePrice = order.Price; order.TradeDate = tradeApi.TradingDay; order.TradeTime = DateTime.Now.ToString("HH:mm:ss"); order.StatusType = EnumOrderStatus.已开仓; } else { foreach (var closeOrder in order.GetClosingOrders()) { closeOrder.OrderRef = tradeApi.MaxOrderRef++.ToString(); closeOrder.FrontID = tradeApi.FrontID; closeOrder.SessionID = tradeApi.SessionID; closeOrder.StatusType = EnumOrderStatus.平仓中; closeOrder.OrderSysID = tradeApi.MaxOrderRef++.ToString(); var tradeField = new CThostFtdcTradeField(); tradeField.TradeID = tradeApi.MaxOrderRef++.ToString(); tradeField.OrderSysID = closeOrder.OrderSysID; tradeField.Price = closeOrder.Price; tradeField.TradeDate = tradeApi.TradingDay; tradeField.TradeTime = DateTime.Now.ToString("HH:mm:ss"); var o = UpdateTradeID(tradeField); if (o == null || o.StatusType != EnumOrderStatus.已平仓) continue; OnRspQryOrder(this, new OrderEventArgs(() => HandleOrderClose(o))); if (!HasMoney) HasMoney = true; } } }
public void ComplexEntityTest() { IRepository<Customer> _customerRepo = new MongoRepository<Customer>(); IRepository<Product> _productRepo = new MongoRepository<Product>(); var customer = new Customer(); customer.FirstName = "Erik"; customer.LastName = "Swaun"; customer.Phone = "123 99 8767"; customer.Email = "*****@*****.**"; customer.HomeAddress = new Address { Address1 = "Main bulevard", Address2 = "1 west way", PostCode = "89560", City = "Tempare", Country = "Arizona" }; var order = new Order(); order.PurchaseDate = DateTime.Now.AddDays(-2); var orderItems = new List<OrderItem>(); var shampoo = _productRepo.Add(new Product() { Name = "Palmolive Shampoo", Price = 5 }); var paste = _productRepo.Add(new Product() { Name = "Mcleans Paste", Price = 4 }); var item1 = new OrderItem { Product = shampoo, Quantity = 1 }; var item2 = new OrderItem { Product = paste, Quantity = 2 }; orderItems.Add(item1); orderItems.Add(item2); order.Items = orderItems; customer.Orders = new List<Order> { order }; _customerRepo.Add(customer); Assert.IsNotNull(customer.Id); Assert.IsNotNull(customer.Orders[0].Items[0].Product.Id); // get the orders var theOrders = _customerRepo.Where(c => c.Id == customer.Id).Select(c => c.Orders).ToList(); var theOrderItems = theOrders[0].Select(o => o.Items); Assert.IsNotNull(theOrders); Assert.IsNotNull(theOrderItems); }
private void HandleOrderClose(Order order) { var orderLog = new OrderLog(); ObjectUtils.Copy(order, orderLog); orderLog.Id = null; sw.EnterWriteLock(); orders.Remove(order); orderlogs.Add(orderLog); orderLogRepo.Add(orderLog); OrderRepository.Delete(order); sw.ExitWriteLock(); }
private void InsertToCTP(Order order) { if (order.CloseOrders.Count == 0) { OnRspQryOrder(this, new OrderEventArgs(() => Add(order))); int orderRef = tradeApi.OrderInsert(order.InstrumentId, order.OffsetFlag, order.Direction, order.Price, order.Volume); order.RemainVolume = order.Volume; order.OrderRef = orderRef.ToString(); order.FrontID = tradeApi.FrontID; order.SessionID = tradeApi.SessionID; order.StatusType = EnumOrderStatus.开仓中; } else { foreach (var closeOrder in order.GetClosingOrders()) { var orderRef = tradeApi.OrderInsert(closeOrder.InstrumentId, closeOrder.OffsetFlag, closeOrder.Direction, closeOrder.Price, closeOrder.Volume); closeOrder.OrderRef = orderRef.ToString(); closeOrder.FrontID = tradeApi.FrontID; closeOrder.SessionID = tradeApi.SessionID; closeOrder.StatusType = EnumOrderStatus.平仓中; } //order.StatusType = EnumOrderStatus.平仓中; } }
public void OrderInsert(Order order) { //InsertToMock(order); InsertToCTP(order); }
private Order Add(Order order) { sw.EnterWriteLock(); order.Id = null; orders.Add(order); var o = OrderRepository.Add(order); sw.ExitWriteLock(); return o; }
public void OpenOrder(string instrumentId, TThostFtdcDirectionType direction) { var order = new Order(); order.OffsetFlag = TThostFtdcOffsetFlagType.Open; order.Direction = direction; order.InstrumentId = instrumentId; order.Price = 0; order.Volume = 1; order.StrategyType = "Open Order By User"; OrderInsert(order); }
public void DeleteOrder(Order order) { OnRspQryOrder(this, new OrderEventArgs(() => HandleOrderClose(order))); }
public void CloseOrder(Order order) { var neworder = new Order { OffsetFlag = order.IsTodayOrder ? TThostFtdcOffsetFlagType.CloseToday : TThostFtdcOffsetFlagType.Close, Direction = order.Direction == TThostFtdcDirectionType.Buy ? TThostFtdcDirectionType.Sell : TThostFtdcDirectionType.Buy, InstrumentId = order.InstrumentId, Price = 0, Volume = order.RemainVolume, StrategyType = "Close Order By User" }; order.CloseOrders.Add(neworder); OrderInsert(order); }
public void ChangeCloseOrder(Order lastOrder, Order closeorder) { CancelOrder(lastOrder); lastOrder.CloseOrders[0] = closeorder; OrderInsert(lastOrder); }
public void CancelOrder(Order order) { if (order == null) return; sw.EnterWriteLock(); if (order.CloseOrders.Count == 0) { tradeApi.CancelOrder(order.OrderRef, order.FrontID, order.SessionID, order.InstrumentId); OnRspQryOrder(this, new OrderEventArgs(() => orders.Remove(order))); OrderRepository.Delete(order); } else { foreach (var item in order.GetClosingOrders()) { tradeApi.CancelOrder(item.OrderRef, item.FrontID, item.SessionID, item.InstrumentId); item.CloseOrders.Remove(item); } order.StatusType = EnumOrderStatus.已开仓; OrderRepository.Update(order); } sw.ExitWriteLock(); }