public void DayClosing() { stopTrading = true; var symbols = assetLoader.Elements.Select(e => e.Symbol); foreach (var account in accountList) { foreach (var orderElement in account.Value.OrderContainer.Orders) { if (symbols.Contains(orderElement.Contract.Symbol) && orderTypes.Contains(orderElement.OrderState.Status)) { clientSocket.cancelOrder(orderElement.Order.OrderId); } } foreach (var positionElement in account.Value.PositionContainer.Positions) { if (symbols.Contains(positionElement.Contract.Symbol)) { clientSocket.reqIds(-1); var orderAction = positionElement.Position > 0 ? "SELL" : "BUY"; var order = OrderSamples.MarketOrder(orderAction, Math.Abs(positionElement.Position)); clientSocket.placeOrder(nextValidOrderId, positionElement.Contract, order); } } } Console.WriteLine("Day've been closed"); }
private static void ConditionSamples(EClientSocket client, int nextOrderId) { //! [order_conditioning_activate] Order mkt = OrderSamples.MarketOrder("BUY", 100); //Order will become active if conditioning criteria is met mkt.ConditionsCancelOrder = true; mkt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false)); mkt.Conditions.Add(OrderSamples.ExecutionCondition("EUR.USD", "CASH", "IDEALPRO", true)); mkt.Conditions.Add(OrderSamples.MarginCondition(30, true, false)); mkt.Conditions.Add(OrderSamples.PercentageChangeCondition(15.0, 208813720, "SMART", true, true)); mkt.Conditions.Add(OrderSamples.TimeCondition("20160118 23:59:59", true, false)); mkt.Conditions.Add(OrderSamples.VolumeCondition(208813720, "SMART", false, 100, true)); client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), mkt); //! [order_conditioning_activate] //Conditions can make the order active or cancel it. Only LMT orders can be conditionally canceled. //! [order_conditioning_cancel] Order lmt = OrderSamples.LimitOrder("BUY", 100, 20); //The active order will be cancelled if conditioning criteria is met lmt.ConditionsCancelOrder = true; lmt.Conditions.Add(OrderSamples.PriceCondition(208813720, "SMART", 600, false, false)); client.placeOrder(nextOrderId++, ContractSamples.EuropeanStock(), lmt); //! [order_conditioning_cancel] }