/** * Update the DataGridView based on the given PositionReport, thread-safe */ public void update(QuickFix44.PositionReport report) { if (grdTrades.InvokeRequired) { updateCallback2 d = new updateCallback2(update); this.Invoke(d, new object[] { report }); } else { String reportID = report.getString(9041); // FXCMPosID double pl = 0D; //try { pl = report.getDouble(9052); } // FXCMPosClosePNL //catch (Exception e) { } //String closeID = ""; //try { closeID = report.getString(9054); } //catch (Exception e) { } //double close = 0D; //try { close = report.getDouble(9043); } //catch (Exception e) { } // if the position is already in the DataGridView if (tradesMap.ContainsKey(reportID)) { // update the cells with the values that changed DataGridViewRow row = grdTrades.Rows[tradesMap[reportID]]; row.Cells["Status"].Value = ((report.getPosReqType().getValue() == QuickFix.PosReqType.POSITIONS) ? "O" : "C"); row.Cells["CloseID"].Value = 0; row.Cells["Open"].Value = report.getSettlPrice().getValue(); row.Cells["Close"].Value = 0; row.Cells["PL"].Value = pl; // scroll to the updated row grdTrades.CurrentCell = grdTrades[0, tradesMap[reportID]]; } else // otherwise add it to the DataGridView { tradesMap.Add(reportID, tradesMap.Count); grdTrades.Rows.Add( report.getAccount().getValue(), ((report.getPosReqType().getValue() == QuickFix.PosReqType.POSITIONS) ? "O" : "C"), reportID, report.getSymbol().getValue(), report.getString(37), // OrderID 0, report.getSettlPrice().getValue(), 0, pl ); // scroll to the added row grdTrades.CurrentCell = grdTrades[0, tradesMap.Count - 1]; } // force the interface to refresh Application.DoEvents(); } }
/** * Process the Position reports, adding them to the internal positoins map */ public override void onMessage(QuickFix44.PositionReport report, QuickFix.SessionID session) { // fire an event that a new message arrived if (this.messageRecieved != null) { this.messageRecieved(report); } // write to the Console a note about the report try { //Console.WriteLine( // "A position {0} updated on {1} for account {2} with PL {3:N2}", // report.getString(9041), // FXCMPosID // report.getSymbol().getValue(), // report.getAccount().getValue(), // report.getDouble(9052) // FXCMPosClosePNL //); } catch (Exception e) { Console.WriteLine( "A position {0} updated on {1} for account {2}", report.getString(9041), // FXCMPosID report.getSymbol().getValue(), report.getAccount().getValue() ); } }