//Sends an alert to the web service for the mobile app private void SendExecutionAlertToServer(string orderID, Orders.Status OrderStatus, string symbol, DateTime ExecTime, Orders.Side Side, int Quantity, double EntryPrice, Order.OrderType OrderType, Order.Expiration Expires, double Limit) { string key = "ALERT|" + Convert.ToString(ExecTime) + "|ORDER|" + symbol + "|" + orderID; string data = orderID + "|" + Orders.StatusToString(OrderStatus) + "|" + symbol + "|" + Convert.ToString(ExecTime) + "|" + Orders.SideToString(Side) + "|" + Convert.ToString(Quantity) + "|" + Convert.ToString(EntryPrice) + "|" + Order.OrderTypeToString(OrderType) + "|" + Order.ExpirationToString(Expires) + "|" + Convert.ToString(Limit); try { svc.SetUserData(frmMain2.ClientId, frmMain2.ClientPassword, frmMain2.LicenseKey, key, data); } catch (Exception) { return; } }
//############################# //WARNING! Example code only! //Your order entry API is responsible for returning order status events to update the portfolio! //############################# //Call this routine when your order entry API returns a fill, cancel, reject, etc. message //If the orderID is not found, it is created //Orderid, status, time, symbol, type, qty, entry, last, $ gain, % gain public void ExecuteOrder(string orderID, Orders.Status OrderStatus, string symbol, DateTime ExecTime, Orders.Side Side, int Quantity, double EntryPrice, Order.OrderType OrderType, Order.Expiration Expires, double Limit) { //Details for the order including order type, expiration and limit price (if not market) string details; if (OrderType != Order.OrderType.Market) { details = Order.OrderTypeToString(OrderType) + " (" + Convert.ToString(Limit) + ") " + Order.ExpirationToString(Expires); } else { details = Order.OrderTypeToString(OrderType) + " " + Order.ExpirationToString(Expires); } if ((DateTime.Compare(ExecTime, DateTime.MinValue) != 0) | (DateTime.Compare(ExecTime, Convert.ToDateTime("12:00:00 AM")) == 0)) { ExecTime = DateTime.Now; //Time must be valid } //Try to find the order to update it for (int n = 0; n <= m_PortfolioGrid.Rows.Count - 1; n++) { if (m_PortfolioGrid.Rows[n].Cells["orderID"].Value.ToString().ToLower() != orderID.ToLower()) { continue; } if (OrderStatus != Orders.Status.Unknown) { m_PortfolioGrid.Rows[n].Cells["Status"].Value = Orders.StatusToString(OrderStatus); } if (OrderType != Order.OrderType.Unknown) { m_PortfolioGrid.Rows[n].Cells["Details"].Value = details; } if (symbol != "") { m_PortfolioGrid.Rows[n].Cells["symbol"].Value = symbol; } if (Side != Orders.Side.Unknown) { m_PortfolioGrid.Rows[n].Cells["Type"].Value = Orders.SideToString(Side); } if (Quantity != 0) { m_PortfolioGrid.Rows[n].Cells["Qty"].Value = Quantity; } if (EntryPrice != 0.0) { m_PortfolioGrid.Rows[n].Cells["Entry"].Value = EntryPrice; } //Send an alert SendExecutionAlertToServer(orderID, OrderStatus, symbol, ExecTime, Side, Quantity, EntryPrice, OrderType, Expires, Limit); //Speak the order change 'TODO: optional string text = Orders.StatusToString(OrderStatus); //m_frmMain.Speak("an order has been updated to," + text + ",for,symbol,[" + symbol + "]"); return; } //Couldn't find the order so add it try { m_PortfolioGrid.Rows.Add(new object[] { orderID, Orders.StatusToString(OrderStatus), details, ExecTime, symbol, Orders.SideToString(Side), Quantity, EntryPrice }); //Send an alert SendExecutionAlertToServer(orderID, OrderStatus, symbol, ExecTime, Side, Quantity, EntryPrice, OrderType, Expires, Limit); ////Speak the order 'TODO: optional //switch (Side) //{ // case Orders.Side.LongSide: // m_frmMain.Speak("a buy order has been submitted,[" + Convert.ToString(Quantity) + "],shares of,symbol,[" + // symbol + "]"); // break; // case Orders.Side.ShortSide: // m_frmMain.Speak("a sell order has been submitted,[" + Convert.ToString(Quantity) + // "]symbol,shares of,symbol,[" + symbol + "]"); // break; //} } catch (Exception) { //Form was closing when adding an order to the grid } UpdatePortolioScreen(); //Refresh the data grid view // Send an update to twitter, if requested //if (frmMain2.GInstance.TweetTrades) //{ // string trade = Side.ToString().Replace("Side", "") + " " + symbol + " @ " + EntryPrice; // TODO: change message as desired // frmMain2.GInstance.SendTweet(trade); //} }