private void OrderHandler_OnMessageIncoming(Teb.FIX.Model.Order order, string fixMessage) { try { if (order.SecurityType == CashDefinition.SECURITY_CASH || order.SecurityType == FutureDefinition.SECURITY_FUTURE || order.SecurityType == FutureDefinition.SECURITY_OPTION) { //if (Setting.DistributeFixMessages) //{ // FixMessage fm = new FixMessage() // { // Account = order.Account, // Message = fixMessage, // SecurityType = order.SecurityType, // DbID = order.DbID.ToString(), // TEBID = order.TEBID // }; // TradeDistrubuter.FixMsgDistQueue.Enqueue(new FixMessageQueueItem() { Message = fm }); //} } else { //Log(String.Format("{0} mesajının SecurityType = {1} değeri geçerli değildir", fixMessage, order.SecurityType)); } } catch (Exception ex) { TBYException tex = new TBYException(MethodInfo.GetCurrentMethod().GetFullName(), String.Format("{0} mesajı alıcılara gönderilirken hata oluştu", fixMessage), ex); Error(tex); } }
private void CashOrderHandler_OnOrderUpdated(Teb.FIX.Model.Order order) { try { if (order.ServerStatus != ContentServerStatus.Waiting) { const int orderFee = 0; QuantConnect.Orders.Order quantOrder = convertHelper.ConvertToOrder(order); OrderStatus status = convertHelper.ConvertToStatus(order); var orderEvent = new OrderEvent(quantOrder, Algorithm.UtcTime, orderFee) { Status = status }; OnOrderEvent(orderEvent); } _tradeDbHelper.UpdateOrder(order); } catch (Exception ex) { TBYException tex = new TBYException(MethodInfo.GetCurrentMethod().GetFullName(), String.Format("DbID:{0} TEBID:{1} emir veritabanında güncellenirken hata oluştu", order == null ? "-1" : order.DbID.ToString(), order == null ? "-1" : order.TEBID), ex); Error(tex); } }
//public string Convert2Side(Orders.OrderDirection direction) //{ // switch (direction) // { // case OrderDirection.Buy: // return CashDefinition.SIDE_BUY; // case OrderDirection.Sell: // return CashDefinition.SIDE_SELL; // default: // throw new InvalidEnumArgumentException("order.OrderDirection", (int)direction, typeof(Orders.OrderDirection)); // } //} public QuantConnect.Orders.OrderStatus ConvertToStatus(Teb.FIX.Model.Order fo) { switch (fo.ServerStatus) { case ContentServerStatus.BusinessReject: case ContentServerStatus.CancelReject: case ContentServerStatus.CancelReplaceReject: case ContentServerStatus.Rejected: case ContentServerStatus.SessionRejected: case ContentServerStatus.Expired: case ContentServerStatus.Canceled: return(OrderStatus.Canceled); case ContentServerStatus.Fill: return(OrderStatus.Filled); case ContentServerStatus.New: case ContentServerStatus.NewActivated: return(OrderStatus.Submitted); case ContentServerStatus.NewNotActivated: return(OrderStatus.New); case ContentServerStatus.PartialFill: return(OrderStatus.PartiallyFilled); case ContentServerStatus.Waiting: Log.Error("TEBBrokersBrokerage.ConvertOrderStatus(): ContentServerStatus.Waiting order"); return(OrderStatus.None); default: throw new InvalidEnumArgumentException("status", (int)fo.ServerStatus, typeof(ContentServerStatus)); } }
public int ConvertToQuantity(Teb.FIX.Model.Order tebOrder) { switch (tebOrder.Core.Side) { case CashDefinition.SIDE_BUY: return(tebOrder.OrderQty.HasValue ? tebOrder.OrderQty.Value : 0); case CashDefinition.SIDE_SELL: return(-(tebOrder.OrderQty.HasValue ? tebOrder.OrderQty.Value : 0)); default: throw new ArgumentOutOfRangeException(); } }
public QuantConnect.Orders.Order ConvertToOrder(Teb.FIX.Model.Order tebOrder) { QuantConnect.Orders.Order o = null; if (tebOrder.OrdType == CashDefinition.ORDTYPE_MARKET) { o = new QuantConnect.Orders.MarketOrder(); } else { o = new QuantConnect.Orders.LimitOrder(); (o as LimitOrder).LimitPrice = tebOrder.Price.HasValue ? tebOrder.Price.Value : 0; } o.Duration = ConvertToTimeInForce(tebOrder.Core.TimeInForce);; o.Id = int.Parse(tebOrder.ClOrdID.Replace("CS", "")); o.Price = tebOrder.Price.HasValue ? tebOrder.Price.Value : 0; o.Quantity = ConvertToQuantity(tebOrder); o.Status = ConvertToStatus(tebOrder); o.Time = tebOrder.TransactTime.HasValue ? tebOrder.TransactTime.Value : DateTime.Now; o.Symbol = tebOrder.Symbol; o.BrokerId.Add(tebOrder.ConnectionClOrdID); return(o); }