/// <summary>Handle messages from Tradee</summary> private void DispatchMsg(ITradeeMsg msg) { switch (msg.ToMsgType()) { default: Debug.WriteLine("Unknown Message Type {0} received".Fmt(msg.GetType().Name)); break; case EMsgType.HelloClient: HandleMsg((OutMsg.HelloClient)msg); break; case EMsgType.RequestAccountStatus: HandleMsg((OutMsg.RequestAccountStatus)msg); break; case EMsgType.RequestInstrument: HandleMsg((OutMsg.RequestInstrument)msg); break; case EMsgType.RequestInstrumentStop: HandleMsg((OutMsg.RequestInstrumentStop)msg); break; case EMsgType.RequestInstrumentHistory: HandleMsg((OutMsg.RequestInstrumentHistory)msg); break; case EMsgType.RequestTradeHistory: HandleMsg((OutMsg.RequestTradeHistory)msg); break; case EMsgType.PlaceMarketOrder: HandleMsg((OutMsg.PlaceMarketOrder)msg); break; } }
/// <summary>Handle messages received from the trade data source</summary> public void DispatchMsg(ITradeeMsg msg) { // Ignore messages after dispose if (!IsConnected) { return; } // Dispatch received messages switch (msg.ToMsgType()) { default: #region { Debug.WriteLine("Unknown Message Type {0} received".Fmt(msg.GetType().Name)); Owner.Status.SetStatusMessage(msg: "Unknown Message Type {0} received".Fmt(msg.GetType().Name), fr_color: Color.Red, display_time: TimeSpan.FromSeconds(5)); break; } #endregion case EMsgType.HelloTradee: #region { var m = (InMsg.HelloTradee)msg; MsgBox.Show(Owner, m.Text, "Test Msg Received"); break; } #endregion case EMsgType.CandleData: #region { var cd = (InMsg.CandleData)msg; if (cd.Candle != null) { MarketData[cd.SymbolCode].Add(cd.TimeFrame, cd.Candle); } if (cd.Candles != null) { MarketData[cd.SymbolCode].Add(cd.TimeFrame, cd.Candles); } break; } #endregion case EMsgType.AccountUpdate: #region { var acct = (InMsg.AccountUpdate)msg; Acct.Update(acct.Acct); break; } #endregion case EMsgType.PositionsUpdate: #region { var pos = (InMsg.PositionsUpdate)msg; Acct.Update(pos.Positions); Positions.Update(pos.Positions); break; } #endregion case EMsgType.PendingOrdersUpdate: #region { var orders = (InMsg.PendingOrdersUpdate)msg; Acct.Update(orders.PendingOrders); Positions.Update(orders.PendingOrders); break; } #endregion case EMsgType.SymbolData: #region { var sd = (InMsg.SymbolData)msg; MarketData[sd.Symbol].PriceData = sd.Data; break; } #endregion case EMsgType.HistoryData: #region { var hd = (InMsg.HistoryData)msg; Positions.Update(hd.Orders); break; } #endregion } }