protected override void OnExecution(IExecution execution) { mitOrder mo = new mitOrder(); mo.Token = execution.Order.Token; int i = blist.IndexOf(mo); if (i >= 0) { blist[i].State = execution.Order.OrderState; blist[i].FillPrice = execution.Order.AvgFillPrice; blist[i].Remaining = blist[i].Remaining - execution.Quantity; dgv.Refresh(); } if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.Cancelled || execution.Order.OrderState == OrderState.Rejected) { if (olist.Contains(execution.Order)) { olist.Remove(execution.Order); if (i >= 0) { blist.RemoveAt(i); } } } //lblMsg.Text = olist.Count.ToString() + " orders remaining"; if (Position.MarketPosition == MarketPosition.Long) { lblMsg.Text = Position.MarketPosition.ToString() + ": Quantity: " + Position.Quantity.ToString() + " Price: " + Position.AvgPrice.ToString(); lblMsg.ForeColor = Color.Blue; } else if (Position.MarketPosition == MarketPosition.Short) { lblMsg.Text = Position.MarketPosition.ToString() + ": Quantity: " + Position.Quantity.ToString() + " Price: " + Position.AvgPrice.ToString(); lblMsg.ForeColor = Color.Brown; } else if (Position.MarketPosition == MarketPosition.Flat) { lblMsg.Text = ""; //lblMsg.Text = olist.Count.ToString() + " orders pending"; lblMsg.ForeColor = Color.Black; } }
protected override void OnOrderUpdate(IOrder order) { if (order.OrderState == OrderState.Cancelled) { if (olist.Contains(order)) { olist.Remove(order); } mitOrder mo = new mitOrder(); mo.Token = order.Token; int i = blist.IndexOf(mo); if (i >= 0) { blist.RemoveAt(i); } } //lblMsg.Text = olist.Count.ToString(); }
private void btnSubmitOrderClick(object state) { OrderAction oAction = (OrderAction)Enum.Parse(typeof(OrderAction), cbOrderAction.SelectedItem.ToString()); OrderType oType = (OrderType)Enum.Parse(typeof(OrderType), cbOrderType.SelectedItem.ToString()); double limitprice = 0; double stopprice = 0; if (oType == OrderType.Limit) { limitprice = (double)nudLmtPrice.Value; } else if (oType == OrderType.Stop) { stopprice = (double)nudStopPrice.Value; if (oAction == OrderAction.Buy) { if (stopprice <= Close[0]) { MessageBox.Show("Stop Price cannot be less than Last traded price"); return; } } else if (oAction == OrderAction.Sell) { if (stopprice >= Close[0]) { MessageBox.Show("Stop Price cannot be greater than Last traded price"); return; } } } else if (oType == OrderType.StopLimit) { limitprice = (double)nudLmtPrice.Value; stopprice = (double)nudStopPrice.Value; if (oAction == OrderAction.Buy) { if (stopprice <= Close[0]) { MessageBox.Show("Stop Price cannot be less than Last traded price"); return; } if (limitprice < stopprice) { MessageBox.Show("Limit Price cannot be less than Stop Price"); return; } } else if (oAction == OrderAction.Sell) { if (stopprice >= Close[0]) { MessageBox.Show("Stop Price cannot be greater than Last traded price"); return; } if (limitprice > stopprice) { MessageBox.Show("Limit Price cannot be greater than Stop Price"); return; } } } IOrder order = SubmitOrder(0, oAction, oType, (int)nudQuantity.Value, limitprice, stopprice, "", oType.ToString() + oAction.ToString()); olist.Add(order); mitOrder morder = new mitOrder(); morder.Action = oAction; morder.StopPrice = stopprice; morder.FillPrice = order.AvgFillPrice; morder.LimitPrice = limitprice; morder.Quantity = (int)nudQuantity.Value; morder.Remaining = morder.Quantity; morder.State = OrderState.Working; morder.TimeStamp = order.Time; morder.Token = order.Token; morder.Type = oType; blist.Add(morder); dgv.DataSource = blist; }