public static NewStopOrderElement CreateStopLoss(TransaqOrderCondition cond) { if (cond == null) throw new ArgumentNullException(nameof(cond)); return new NewStopOrderElement { ActivationPrice = cond.StopLossActivationPrice, OrderPrice = cond.StopLossOrderPrice.To<string>(), ByMarket = cond.StopLossByMarket, Quantity = cond.StopLossVolume.To<string>(), UseCredit = cond.StopLossUseCredit, GuardTime = cond.StopLossProtectionTime, BrokerRef = cond.StopLossComment }; }
public static NewStopOrderElement CreateStopLoss(TransaqOrderCondition cond) { if (cond == null) { throw new ArgumentNullException("cond"); } return(new NewStopOrderElement { ActivationPrice = cond.StopLossActivationPrice, OrderPrice = cond.StopLossOrderPrice.To <string>(), ByMarket = cond.StopLossByMarket, Quantity = cond.StopLossVolume.To <string>(), UseCredit = cond.StopLossUseCredit, GuardTime = cond.StopLossProtectionTime, BrokerRef = cond.StopLossComment }); }
public static bool CheckConditionUnitType(this TransaqOrderCondition cond) { if (cond == null) { throw new ArgumentNullException("cond"); } if ((cond.StopLossOrderPrice != null && cond.StopLossOrderPrice.Type != UnitTypes.Absolute & cond.StopLossOrderPrice.Type != UnitTypes.Percent) || (cond.StopLossVolume != null && cond.StopLossVolume.Type != UnitTypes.Absolute & cond.StopLossVolume.Type != UnitTypes.Percent) || (cond.TakeProfitVolume != null && cond.TakeProfitVolume.Type != UnitTypes.Absolute & cond.TakeProfitVolume.Type != UnitTypes.Percent) || (cond.TakeProfitCorrection != null && cond.TakeProfitCorrection.Type != UnitTypes.Absolute & cond.TakeProfitCorrection.Type != UnitTypes.Percent) || (cond.TakeProfitProtectionSpread != null && cond.TakeProfitProtectionSpread.Type != UnitTypes.Absolute & cond.TakeProfitProtectionSpread.Type != UnitTypes.Percent)) { return(false); } return(true); }
public static NewStopOrderElement CreateTakeProfit(TransaqOrderCondition cond) { if (cond == null) { throw new ArgumentNullException("cond"); } return(new NewStopOrderElement { ActivationPrice = cond.TakeProfitActivationPrice, ByMarket = cond.TakeProfitByMarket, Quantity = cond.TakeProfitVolume.To <string>(), UseCredit = cond.TakeProfitUseCredit, GuardTime = cond.TakeProfitProtectionTime, BrokerRef = cond.TakeProfitComment, Correction = cond.TakeProfitCorrection.To <string>(), Spread = cond.TakeProfitProtectionSpread.To <string>() }); }
private void OnOrdersResponse(OrdersResponse response) { foreach (var order in response.Orders.Cast <TransaqBaseOrder>().Concat(response.StopOrders)) { var stockSharpTransactionId = _orders.TryGetValue(order.TransactionId); if (stockSharpTransactionId == 0) { stockSharpTransactionId = order.TransactionId; // если заявка пришла от терминала, то просто идентификатор транзакции ассоциируем как стокшарповский _orders.Add(order.TransactionId, order.TransactionId); _ordersTypes.Add(order.TransactionId, order is TransaqStopOrder ? OrderTypes.Conditional : OrderTypes.Limit); } var execMsg = new ExecutionMessage { SecurityId = new SecurityId { Native = order.SecId }, Side = order.BuySell.FromTransaq(), OriginalTransactionId = stockSharpTransactionId, PortfolioName = order.Client, ExpiryDate = order.ExpDate == null ? (DateTimeOffset?)null : order.ExpDate.Value.ApplyTimeZone(TimeHelper.Moscow), ExecutionType = ExecutionTypes.Order, }; var usualOrder = order as TransaqOrder; if (usualOrder != null) { execMsg.OrderId = usualOrder.OrderNo; execMsg.Balance = usualOrder.Balance; execMsg.ServerTime = usualOrder.WithdrawTime ?? usualOrder.Time ?? usualOrder.AcceptTime ?? DateTimeOffset.MinValue; execMsg.Comment = usualOrder.BrokerRef; execMsg.SystemComment = usualOrder.Result; execMsg.Price = usualOrder.Price; execMsg.Volume = usualOrder.Quantity; execMsg.OrderType = usualOrder.Price == 0 ? OrderTypes.Market : OrderTypes.Limit; execMsg.Commission = usualOrder.MaxCommission; if (usualOrder.ConditionType != TransaqAlgoOrderConditionTypes.None) { execMsg.OrderType = OrderTypes.Conditional; execMsg.Condition = new TransaqOrderCondition { AlgoType = usualOrder.ConditionType, AlgoValue = usualOrder.ConditionValue.To <decimal>(), AlgoValidAfter = usualOrder.ValidAfter, AlgoValidBefore = usualOrder.ValidBefore, }; } } else { var stopOrder = (TransaqStopOrder)order; execMsg.OrderId = stopOrder.ActiveOrderNo; execMsg.OrderType = OrderTypes.Conditional; execMsg.ServerTime = stopOrder.AcceptTime == null ? DateTimeOffset.MinValue : stopOrder.AcceptTime.Value.ApplyTimeZone(TimeHelper.Moscow); var stopCond = new TransaqOrderCondition { Type = stopOrder.StopLoss != null && stopOrder.TakeProfit != null ? TransaqOrderConditionTypes.TakeProfitStopLoss : (stopOrder.StopLoss != null ? TransaqOrderConditionTypes.StopLoss : TransaqOrderConditionTypes.TakeProfit), ValidFor = stopOrder.ValidBefore, LinkedOrderId = stopOrder.LinkedOrderNo, }; if (stopOrder.StopLoss != null) { stopCond.StopLossActivationPrice = stopOrder.StopLoss.ActivationPrice; stopCond.StopLossOrderPrice = stopOrder.StopLoss.OrderPrice; stopCond.StopLossByMarket = stopOrder.StopLoss.OrderPrice == null; stopCond.StopLossVolume = stopOrder.StopLoss.Quantity; //stopCond.StopLossUseCredit = stopOrder.StopLoss.UseCredit.To<bool>(); if (stopOrder.StopLoss.GuardTime != null) { stopCond.StopLossProtectionTime = (int)stopOrder.StopLoss.GuardTime.Value.TimeOfDay.TotalMinutes; } stopCond.StopLossComment = stopOrder.StopLoss.BrokerRef; } if (stopOrder.TakeProfit != null) { stopCond.TakeProfitActivationPrice = stopOrder.TakeProfit.ActivationPrice; stopCond.TakeProfitByMarket = stopOrder.TakeProfit.GuardSpread == null; stopCond.TakeProfitVolume = stopOrder.TakeProfit.Quantity; //stopCond.TakeProfitUseCredit = stopOrder.TakeProfit.UseCredit.To<bool>(); if (stopOrder.TakeProfit.GuardTime != null) { stopCond.TakeProfitProtectionTime = (int)stopOrder.TakeProfit.GuardTime.Value.TimeOfDay.TotalMinutes; } stopCond.TakeProfitComment = stopOrder.TakeProfit.BrokerRef; stopCond.TakeProfitCorrection = stopOrder.TakeProfit.Correction; stopCond.TakeProfitProtectionSpread = stopOrder.TakeProfit.GuardSpread; } } execMsg.OrderState = order.Status.ToStockSharpState(); //execMsg.OrderStatus = order2.Status.ToStockSharpStatus(); if (order.Status != TransaqOrderStatus.cancelled) { if (execMsg.OrderState == OrderStates.Failed && usualOrder != null) { execMsg.Error = new InvalidOperationException(usualOrder.Result); } } SendOutMessage(execMsg); //if (order.Condition != null && order.DerivedOrder == null && order2.ConditionType != TransaqAlgoOrderConditionTypes.None && order2.OrderNo != 0) // AddDerivedOrder(security, order2.OrderNo, order, (stopOrder, limitOrder) => stopOrder.DerivedOrder = limitOrder); } }
private void OnOrdersResponse(OrdersResponse response) { foreach (var order in response.Orders.Cast<TransaqBaseOrder>().Concat(response.StopOrders)) { var stockSharpTransactionId = _orders.TryGetValue(order.TransactionId); if (stockSharpTransactionId == 0) { stockSharpTransactionId = order.TransactionId; // если заявка пришла от терминала, то просто идентификатор транзакции ассоциируем как стокшарповский _orders.Add(order.TransactionId, order.TransactionId); _ordersTypes.Add(order.TransactionId, order is TransaqStopOrder ? OrderTypes.Conditional : OrderTypes.Limit); } var execMsg = new ExecutionMessage { SecurityId = new SecurityId { Native = order.SecId }, Side = order.BuySell.FromTransaq(), OriginalTransactionId = stockSharpTransactionId, PortfolioName = order.Client, ExpiryDate = order.ExpDate?.ApplyTimeZone(TimeHelper.Moscow), ExecutionType = ExecutionTypes.Transaction, }; var usualOrder = order as TransaqOrder; if (usualOrder != null) { execMsg.OrderId = usualOrder.OrderNo; execMsg.Balance = usualOrder.Balance; execMsg.ServerTime = (usualOrder.WithdrawTime ?? usualOrder.Time ?? usualOrder.AcceptTime ?? DateTime.MinValue).ToDto(); execMsg.Comment = usualOrder.BrokerRef; execMsg.SystemComment = usualOrder.Result; execMsg.OrderPrice = usualOrder.Price; execMsg.OrderVolume = usualOrder.Quantity; execMsg.OrderType = usualOrder.Price == 0 ? OrderTypes.Market : OrderTypes.Limit; execMsg.Commission = usualOrder.MaxCommission; if (usualOrder.ConditionType != TransaqAlgoOrderConditionTypes.None) { execMsg.OrderType = OrderTypes.Conditional; execMsg.Condition = new TransaqOrderCondition { AlgoType = usualOrder.ConditionType, AlgoValue = usualOrder.ConditionValue.To<decimal>(), AlgoValidAfter = usualOrder.ValidAfter.ToDto(), AlgoValidBefore = usualOrder.ValidBefore.ToDto(), }; } } else { var stopOrder = (TransaqStopOrder)order; execMsg.OrderId = stopOrder.ActiveOrderNo; execMsg.OrderType = OrderTypes.Conditional; execMsg.ServerTime = stopOrder.AcceptTime?.ToDto() ?? DateTimeOffset.MinValue; var stopCond = new TransaqOrderCondition { Type = stopOrder.StopLoss != null && stopOrder.TakeProfit != null ? TransaqOrderConditionTypes.TakeProfitStopLoss : (stopOrder.StopLoss != null ? TransaqOrderConditionTypes.StopLoss : TransaqOrderConditionTypes.TakeProfit), ValidFor = stopOrder.ValidBefore.ToDto(), LinkedOrderId = stopOrder.LinkedOrderNo, }; if (stopOrder.StopLoss != null) { stopCond.StopLossActivationPrice = stopOrder.StopLoss.ActivationPrice; stopCond.StopLossOrderPrice = stopOrder.StopLoss.OrderPrice; stopCond.StopLossByMarket = stopOrder.StopLoss.OrderPrice == null; stopCond.StopLossVolume = stopOrder.StopLoss.Quantity; //stopCond.StopLossUseCredit = stopOrder.StopLoss.UseCredit.To<bool>(); if (stopOrder.StopLoss.GuardTime != null) stopCond.StopLossProtectionTime = (int)stopOrder.StopLoss.GuardTime.Value.TimeOfDay.TotalMinutes; stopCond.StopLossComment = stopOrder.StopLoss.BrokerRef; } if (stopOrder.TakeProfit != null) { stopCond.TakeProfitActivationPrice = stopOrder.TakeProfit.ActivationPrice; stopCond.TakeProfitByMarket = stopOrder.TakeProfit.GuardSpread == null; stopCond.TakeProfitVolume = stopOrder.TakeProfit.Quantity; //stopCond.TakeProfitUseCredit = stopOrder.TakeProfit.UseCredit.To<bool>(); if (stopOrder.TakeProfit.GuardTime != null) stopCond.TakeProfitProtectionTime = (int)stopOrder.TakeProfit.GuardTime.Value.TimeOfDay.TotalMinutes; stopCond.TakeProfitComment = stopOrder.TakeProfit.BrokerRef; stopCond.TakeProfitCorrection = stopOrder.TakeProfit.Correction; stopCond.TakeProfitProtectionSpread = stopOrder.TakeProfit.GuardSpread; } } execMsg.OrderState = order.Status.ToStockSharpState(); //execMsg.OrderStatus = order2.Status.ToStockSharpStatus(); if (order.Status != TransaqOrderStatus.cancelled) { if (execMsg.OrderState == OrderStates.Failed && usualOrder != null) execMsg.Error = new InvalidOperationException(usualOrder.Result); } SendOutMessage(execMsg); //if (order.Condition != null && order.DerivedOrder == null && order2.ConditionType != TransaqAlgoOrderConditionTypes.None && order2.OrderNo != 0) // AddDerivedOrder(security, order2.OrderNo, order, (stopOrder, limitOrder) => stopOrder.DerivedOrder = limitOrder); } }
public static NewStopOrderElement CreateTakeProfit(TransaqOrderCondition cond) { if (cond == null) throw new ArgumentNullException(nameof(cond)); return new NewStopOrderElement { ActivationPrice = cond.TakeProfitActivationPrice, ByMarket = cond.TakeProfitByMarket, Quantity = cond.TakeProfitVolume.To<string>(), UseCredit = cond.TakeProfitUseCredit, GuardTime = cond.TakeProfitProtectionTime, BrokerRef = cond.TakeProfitComment, Correction = cond.TakeProfitCorrection.To<string>(), Spread = cond.TakeProfitProtectionSpread.To<string>() }; }