private void FireExecutionChanged(object o, DealingEventArgs e) { Execution execution = (Execution)e.Data; Execution oldExecution = (Execution)e.OldData; GTLTreeNode executionNode = null; foreach (GTLTreeNode node in data.Nodes) { if (node.Tag.Equals(execution.Id)) { executionNode = node; break; } } if (null != executionNode) { // // Update the columns that can change on an execution: // FireSubItem(executionNode, DatabaseObject.EXECUTION_STATUS, execution.ExecutionStatus()); FireSubItem(executionNode, DatabaseObject.UPDATED_DATETIME, execution.ToLocalTime(DatabaseObject.UPDATED_DATETIME)); FireSubItem(executionNode, DatabaseObject.UPDATED_BY, execution[DatabaseObject.UPDATED_BY]); } }
private void FireInvestmentSystemSelected(object sender, EventArgs e) { ToolStripMenuItem tsmi = (ToolStripMenuItem)sender; investmentSystemButton.Text = tsmi.Text; selectedInvestmentSystem = (InvestmentSystem)tsmi.Tag; // // Load the strategies for this investment system // strategies.Nodes.Clear(); foreach (Strategy strategy in selectedInvestmentSystem.Strategies) { GTLTreeNode strategyNode = new GTLTreeNode(); strategyNode.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(strategy[DatabaseObject.NAME]), new GTLSubItem("0") }); strategyNode.Tag = strategy[DatabaseObject.SIGNAL_ID]; strategies.Nodes.Add(strategyNode); } }
private void FireExecutionAdded(object o, DealingEventArgs e) { Execution execution = (Execution)e.Data; GTLTreeNode executionNode = CreateExecutionNode(execution); data.BeginUpdate(); data.BeginNodeListChange(); if (null != executionNode) { data.Nodes.Add(executionNode); } SortData(data.Columns[DatabaseObject.EXECUTION_ID]); data.EndNodeListChange(); data.EndUpdate(); for (int i = 0; i < executionNode.SubItems.Count; i++) { GTLSubItem sub = executionNode.SubItems[i]; ColorSubItem csi = new BlueColorSubItem( Color.White, executionNode.SubItems[i], executionNode.Tag + data.Columns[i].Text); colorNodes[csi.Tag] = csi; } }
private void FireBeforeCellEdit(object source, GTLEmbeddedControlEventArgs args) { args.Cancel = true; GTLTreeNode node = args.TreeNode; // // You can cancel replace as long as it's // // 'NEW' // 'PARTIALLY_FILLED' // 'REPLACED' // string status = node.SubItems[DatabaseObject.RELEASE_STATUS].Text; if (status.Equals("NEW") || status.Equals("PARTIALLY_FILLED") || status.Equals("REPLACED")) { GTLColumn col = data.Columns[args.Column]; if (col.Name.Equals(DatabaseObject.LIMIT_PRC) || col.Name.Equals(DatabaseObject.STOP_PRC)) { args.Cancel = false; } } }
private void FireReleaseAdded(object o, DealingEventArgs e) { Release release = (Release)e.Data; GTLTreeNode releaseNode = CreateReleaseNode(release); data.BeginUpdate(); data.BeginNodeListChange(); if (null != releaseNode) { data.Nodes.Add(releaseNode); } SortData(data.Columns[DatabaseObject.RELEASE_ID]); data.EndNodeListChange(); data.EndUpdate(); for (int i = 0; i < releaseNode.SubItems.Count; i++) { GTLSubItem sub = releaseNode.SubItems[i]; ColorSubItem csi = new BlueColorSubItem( Color.White, releaseNode.SubItems[i], releaseNode.Tag + data.Columns[i].Text); colorNodes[csi.Tag] = csi; } }
protected void FireSubItem(GTLTreeNode node, string key, string value) { if (!node.SubItems[key].Text.Equals(value)) { node.SubItems[key].Text = value; ColorSubItem csi = new BlueColorSubItem( Color.White, node.SubItems[key], node.Tag + data.Columns[key].Text); colorNodes[csi.Tag] = csi; } }
private void FireBeforeCellEdit(object source, GTLEmbeddedControlEventArgs args) { args.Cancel = true; GTLTreeNode node = args.TreeNode; GTLSubItem sub = node.SubItems[args.Column]; if (node.SubItems[args.Column].Text != null && node.SubItems[args.Column].Text != "") { args.Cancel = false; } }
private void FireReleaseChanged(object o, DealingEventArgs e) { Release release = (Release)e.Data; Release oldRelease = (Release)e.OldData; GTLTreeNode releaseNode = null; foreach (GTLTreeNode node in data.Nodes) { if (node.Tag.Equals(release.Id)) { releaseNode = node; break; } } if (null != releaseNode) { // // Update the columns that can change on a release: // // RELEASE_STATUS // RELEASE_TYPE // CLIENT_ORDER_ID // COUNTERPARTY_ORDER_ID // LIMIT_PRC // STOP_PRC // AVERAGE_PRC // RELEASE_QTY // EXECUTED_QTY // EXECUTED_VAL // UPDATED_DATETIME // UPDATED_BY // FireSubItem(releaseNode, DatabaseObject.RELEASE_STATUS, release.ReleaseStatus( )); FireSubItem(releaseNode, DatabaseObject.RELEASE_TYPE, release.ReleaseType( )); FireSubItem(releaseNode, DatabaseObject.CLIENT_ORDER_ID, release[DatabaseObject.CLIENT_ORDER_ID]); FireSubItem(releaseNode, DatabaseObject.COUNTERPARTY_ORDER_ID, release[DatabaseObject.COUNTERPARTY_ORDER_ID]); FireSubItem(releaseNode, DatabaseObject.LIMIT_PRC, release[DatabaseObject.LIMIT_PRC]); FireSubItem(releaseNode, DatabaseObject.STOP_PRC, release[DatabaseObject.STOP_PRC]); FireSubItem(releaseNode, DatabaseObject.AVERAGE_PRC, release[DatabaseObject.AVERAGE_PRC]); FireSubItem(releaseNode, DatabaseObject.RELEASE_QTY, release[DatabaseObject.RELEASE_QTY]); FireSubItem(releaseNode, DatabaseObject.EXECUTED_QTY, release[DatabaseObject.EXECUTED_QTY]); FireSubItem(releaseNode, DatabaseObject.EXECUTED_VAL, release[DatabaseObject.EXECUTED_VAL]); FireSubItem(releaseNode, DatabaseObject.UPDATED_DATETIME, release.ToLocalTime(DatabaseObject.UPDATED_DATETIME)); FireSubItem(releaseNode, DatabaseObject.UPDATED_BY, release[DatabaseObject.UPDATED_BY]); } }
private void FireAccountSelected(object sender, StringEventArgs args) { data.BeginUpdate(); data.BeginNodeListChange(); data.Nodes.Clear(); // // Load the selected account limits // Account account = controller.Cache.GetAccount(args.Data); ClientAdapterResponse response = controller.SendRpc( new GetAccountLimitsByAccountId(args.Data)); foreach (DatabaseEngineResponse.Types.ResultSet rs in response.DatabaseResponse.ResultSetList) { foreach (DatabaseEngineResponse.Types.ResultSet.Types.Row row in rs.RowList) { Hashtable fields = new Hashtable(); foreach (DatabaseEngineResponse.Types.ResultSet.Types.Row.Types.Column col in row.ColumnList) { fields.Add(col.Name, col.Value); } GTLTreeNode instrument_node = new GTLTreeNode( ); instrument_node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(account[DatabaseObject.ACCOUNT_ID]), // account_id new GTLSubItem((string)fields[DatabaseObject.SYMBOL]), // symbol new GTLSubItem((string)fields[DatabaseObject.SECURITY_EXCHANGE]), // security_exchange new GTLSubItem((string)fields[DatabaseObject.SESSION_ID]), // session_id new GTLSubItem((string)fields[DatabaseObject.MAX_OPEN_LONG_QTY]), // max_open_long_qty new GTLSubItem((string)fields[DatabaseObject.MAX_OPEN_SHORT_QTY]), // max_open_short_qty new GTLSubItem((string)fields[DatabaseObject.MAX_RELEASE_QTY]) }); // max_release_qty data.Nodes.Add(instrument_node); } } data.EndNodeListChange(); data.EndUpdate(); this.Enabled = true; }
private void LoadExecutions(ArrayList executions) { data.BeginUpdate(); data.BeginNodeListChange(); foreach (Execution execution in executions) { GTLTreeNode executionNode = CreateExecutionNode(execution); if (null != executionNode) { data.Nodes.Add(executionNode); } } SortData(data.Columns[DatabaseObject.EXECUTION_ID]); data.EndNodeListChange(); data.EndUpdate(); }
private void LoadReleases(ArrayList releases) { data.BeginUpdate(); data.BeginNodeListChange(); foreach (Release release in releases) { GTLTreeNode releaseNode = CreateReleaseNode(release); if (null != releaseNode) { data.Nodes.Add(releaseNode); } } SortData(data.Columns[DatabaseObject.RELEASE_ID]); data.EndNodeListChange(); data.EndUpdate(); }
private void LoadPositions(ArrayList positions) { data.BeginUpdate(); data.BeginNodeListChange(); foreach (AccountPosition account_position in positions) { foreach (InvestmentSystemPosition investment_system_position in account_position.AccountPositions) { GTLTreeNode positionNode = CreatePositionNode(investment_system_position); if (null != positionNode) { data.Nodes.Add(positionNode); } } } data.EndNodeListChange(); data.EndUpdate(); }
private void FireVisibleChanged(object o, EventArgs e) { if (this.Visible) { accounts.BeginUpdate(); accounts.BeginNodeListChange(); accounts.Nodes.Clear(); selectedAccount = null; //accounts.ContextMenu.MenuItems[ 2 ].Enabled = false; foreach (Account account in controller.Cache.Accounts) { GTLTreeNode account_node = new GTLTreeNode(account[DatabaseObject.NAME]); account_node.Tag = account[DatabaseObject.ACCOUNT_ID]; accounts.Nodes.Add(account_node); } accounts.EndNodeListChange(); accounts.EndUpdate(); } }
private GTLTreeNode CreateExecutionNode(Execution execution) { // // Get the instrument on the execution // Instrument instrument = controller.Cache.GetInstrument( execution[DatabaseObject.INSTRUMENT_ID]); if (null == instrument) { log.Warn("Unknown instrument: " + execution[DatabaseObject.INSTRUMENT_ID]); return(null); } // // Get the account on the execution // Account account = controller.Cache.GetAccount( execution[DatabaseObject.ACCOUNT_ID]); if (null == account) { log.Warn("Unknown account: " + execution[DatabaseObject.ACCOUNT_ID]); return(null); } if (!controller.Cache.HasInvestmentSystem( execution[DatabaseObject.INVESTMENT_SYSTEM_ID])) { log.Warn("Unknown investment_system: " + execution[DatabaseObject.INVESTMENT_SYSTEM_ID]); return(null); } GTLTreeNode executionNode = new GTLTreeNode(execution.Id); executionNode.Checked = false; executionNode.Collapse(); executionNode.Tag = execution.Id; executionNode.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(execution.ExecutionStatus( )), new GTLSubItem(execution[DatabaseObject.ORDER_ID]), new GTLSubItem(execution[DatabaseObject.RELEASE_ID]), new GTLSubItem(execution[DatabaseObject.INVESTMENT_SYSTEM_ID]), new GTLSubItem(execution[DatabaseObject.INSTRUMENT_ID]), new GTLSubItem(account[DatabaseObject.NAME]), // account_name new GTLSubItem(instrument[DatabaseObject.NAME]), // instrument_name new GTLSubItem(instrument[DatabaseObject.SYMBOL]), // symbol new GTLSubItem(execution[DatabaseObject.CLIENT_ORDER_ID]), new GTLSubItem(execution[DatabaseObject.SESSION_ID]), new GTLSubItem(execution[DatabaseObject.COUNTERPARTY_EXECUTION_ID]), new GTLSubItem(execution.SideCode( )), new GTLSubItem(execution[DatabaseObject.EXECUTION_CCY]), new GTLSubItem(execution[DatabaseObject.EXECUTION_PRC]), new GTLSubItem(execution[DatabaseObject.EXECUTION_QTY]), new GTLSubItem(execution[DatabaseObject.EXECUTION_VAL]), new GTLSubItem(execution[DatabaseObject.LEAVES_QTY]), new GTLSubItem(execution[DatabaseObject.AVERAGE_PRC]), new GTLSubItem(execution.ToLocalTime(DatabaseObject.ADDED_DATETIME)), new GTLSubItem(execution[DatabaseObject.ADDED_BY]), new GTLSubItem(execution.ToLocalTime(DatabaseObject.UPDATED_DATETIME)), new GTLSubItem(execution[DatabaseObject.UPDATED_BY]) }); return(executionNode); }
private void FireLogin(object sender, EventArgs e) { string request_id = Guid.NewGuid().ToString(); string timestamp = com.quantmodel.common.network.message.ClientMessage.getTimestamp(); InvestmentSystemOneRequest hades_request = InvestmentSystemOneRequest.CreateBuilder() .SetRequestId(request_id) .SetTimestamp(timestamp) .SetType(InvestmentSystemOneRequest.Types.RequestType.LOGIN) .Build(); InvestmentSystemResponse response = sendRPC( InvestmentSystemRequest.CreateBuilder() .SetRequestId(request_id) .SetSessionId(request_id) .SetTimestamp(timestamp) .SetType(InvestmentSystemRequest.Types.RequestType.COMMAND) .SetDelegate(System.Text.Encoding.UTF8.GetString(hades_request.ToByteArray())) .Build()); InvestmentSystemOneData invsys_one_data = InvestmentSystemOneData.ParseFrom(response.Delegate); foreach (Timebar timebar in invsys_one_data.TimebarList) { chartPanel.UpdateTimebarData(timebar, true); } foreach (Trend trend in invsys_one_data.TrendList) { chartPanel.AddTrendData(trend); } foreach (OrderExecution execution in invsys_one_data.OrderExecutionList) { chartPanel.AddOrderExecutionData(execution, true); GTLTreeNode node = new GTLTreeNode( EPOCH.AddSeconds(execution.Timestamp) .ToLocalTime().ToString()); if (execution.Type == OrderExecution.Types.ExecutionType.BUY) { node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(EPOCH.AddSeconds(execution.Timebar).ToLocalTime().ToString()), new GTLSubItem("BUY"), new GTLSubItem("" + execution.Quantity), new GTLSubItem("" + execution.Price) }); } else { node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(EPOCH.AddSeconds(execution.Timebar).ToLocalTime().ToString()), new GTLSubItem("SELL"), new GTLSubItem("" + execution.Quantity), new GTLSubItem("" + execution.Price) }); } data.Nodes.Insert(0, node); } chartPanel.Redraw(); loginFlag = true; }
private void FireVisibleChanged(object o, EventArgs args) { if (this.Visible) { // // Load the investment systems // foreach (InvestmentSystem investmentSystem in controller.Cache.InvestmentSystems) { ToolStripMenuItem tsmi = new ToolStripMenuItem(); tsmi.Name = investmentSystem[DatabaseObject.INVESTMENT_SYSTEM_ID]; tsmi.Text = investmentSystem[DatabaseObject.INVESTMENT_SYSTEM_ID]; tsmi.Size = new System.Drawing.Size(188, 22); tsmi.Click += new EventHandler(FireInvestmentSystemSelected); tsmi.Tag = investmentSystem; investmentSystemButtonDropDown.Items.Add(tsmi); } // // Load the symbols // ArrayList symbols = new ArrayList(); foreach (Instrument instrument in controller.Cache.Instruments) { if (!symbols.Contains(instrument[DatabaseObject.SYMBOL])) { symbols.Add(instrument[DatabaseObject.SYMBOL]); } } symbols.Sort(); foreach (string symbol in symbols) { ToolStripMenuItem tsmi = new ToolStripMenuItem(); tsmi.Name = symbol; tsmi.Text = symbol; tsmi.Size = new System.Drawing.Size(188, 22); tsmi.Click += new EventHandler(FireSymbolSelected); tsmi.Tag = symbol; symbolButtonDropDown.Items.Add(tsmi); } // // Load the active accounts // foreach (Account account in controller.Cache.Accounts) { if ("1".Equals(account[DatabaseObject.IS_ACTIVE])) { GTLTreeNode accountNode = new GTLTreeNode(); accountNode.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(account[DatabaseObject.NAME]), new GTLSubItem("0") }); accountNode.Tag = account.Id; accounts.Nodes.Add(accountNode); } } } else { investmentSystemButton.Text = "Investment System..."; investmentSystemButtonDropDown.Items.Clear(); symbolButton.Text = "Symbol..."; symbolButtonDropDown.Items.Clear(); instrumentButton.Text = "Instrument..."; instrumentButtonDropDown.Items.Clear(); accounts.Nodes.Clear(); strategies.Nodes.Clear(); buyButton.Enabled = false; sellButton.Enabled = false; accounts.Enabled = false; strategies.Enabled = false; } }
private void FirePositionChanged(object o, PositionEventArgs e) { double notional_pl; AccountPosition account_position = (AccountPosition)e.Data; accounts.BeginUpdate(); accounts.BeginNodeListChange(); // // Get the account on the position // Account account = controller.Cache.GetAccount(account_position.AccountId); if (null == account) { log.Warn("Unknown account: " + account_position.AccountId); return; } // // Calculate the notional_pl // notional_pl = 0.0; foreach (InstrumentPosition instrument_position in account_position.InstrumentPositions) { // // Get the instrument // Instrument instrument = controller.Cache.GetInstrument( instrument_position.InstrumentId); if (null == instrument) { log.Warn("Unknown instrument_id: " + instrument_position.InstrumentId); continue; } // // Calculate the notional PL // instrument_position.ProfitLoss(account, instrument); notional_pl += instrument_position.NotionalPL; } // // Find this account in our list? // bool found = false; foreach (GTLTreeNode account_node in accounts.Nodes) { if (account_node.Tag.Equals(account.Id)) { ((PercentSubItem)account_node.SubItems["notional_pl"]).Update(notional_pl); found = true; break; } } if (!found) { GTLTreeNode account_node = new GTLTreeNode(account[DatabaseObject.NAME]); account_node.SubItems.AddRange(new GTLSubItem [] { new PercentSubItem(notional_pl, true) }); account_node.Tag = account.Id; accounts.Nodes.Add(account_node); ToolStripMenuItem tsmi = new ToolStripMenuItem(); tsmi.Name = account.Id; tsmi.Size = new System.Drawing.Size(188, 22); tsmi.Text = account[DatabaseObject.NAME]; tsmi.Click += new EventHandler(FireFlattenAccount); splitButtonDropDown.Items.Add(tsmi); } accounts.EndNodeListChange(); accounts.EndUpdate(); }
private void LoadPositions(ArrayList positions) { double notional_pl; accounts.BeginUpdate(); accounts.BeginNodeListChange(); foreach (AccountPosition account_position in positions) { // // Get the account on the position // Account account = controller.Cache.GetAccount(account_position.AccountId); if (null == account) { log.Warn("Unknown account: " + account_position.AccountId); continue; } ToolStripMenuItem tsmi = new ToolStripMenuItem(); tsmi.Name = account.Id; tsmi.Size = new System.Drawing.Size(188, 22); tsmi.Text = account[DatabaseObject.NAME]; tsmi.Click += new EventHandler(FireFlattenAccount); splitButtonDropDown.Items.Add(tsmi); notional_pl = 0.0; GTLTreeNode account_node = new GTLTreeNode(account[DatabaseObject.NAME]); foreach (InstrumentPosition instrument_position in account_position.InstrumentPositions) { // // Get the instrument // Instrument instrument = controller.Cache.GetInstrument( instrument_position.InstrumentId); if (null == instrument) { log.Warn("Unknown instrument_id: " + instrument_position.InstrumentId); continue; } // // Calculate the PL // instrument_position.ProfitLoss(account, instrument); notional_pl += instrument_position.NotionalPL; } account_node.SubItems.AddRange(new GTLSubItem [] { new PercentSubItem(notional_pl, true) }); account_node.Tag = account.Id; accounts.Nodes.Add(account_node); } accounts.EndNodeListChange(); accounts.EndUpdate(); }
private GTLTreeNode CreateReleaseNode(Release release) { // // Get the instrument on the release // Instrument instrument = controller.Cache.GetInstrument( release[DatabaseObject.INSTRUMENT_ID]); if (null == instrument) { log.Warn("Unknown instrument: " + release[DatabaseObject.INSTRUMENT_ID]); return(null); } // // Get the account on the release // Account account = controller.Cache.GetAccount( release[DatabaseObject.ACCOUNT_ID]); if (null == account) { log.Warn("Unknown account: " + release[DatabaseObject.ACCOUNT_ID]); return(null); } if (!controller.Cache.HasInvestmentSystem( release[DatabaseObject.INVESTMENT_SYSTEM_ID])) { log.Warn("Unknown investment_system: " + release[DatabaseObject.INVESTMENT_SYSTEM_ID]); return(null); } GTLTreeNode releaseNode = new GTLTreeNode(release.Id); releaseNode.Checked = false; releaseNode.Collapse(); releaseNode.Tag = release.Id; releaseNode.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(release.ReleaseStatus( )), new GTLSubItem(release.ReleaseType( )), new GTLSubItem(release[DatabaseObject.ORDER_ID]), new GTLSubItem(release[DatabaseObject.INVESTMENT_SYSTEM_ID]), new GTLSubItem(release[DatabaseObject.INSTRUMENT_ID]), new GTLSubItem(account[DatabaseObject.NAME]), // account_name new GTLSubItem(instrument[DatabaseObject.NAME]), // instrument_name new GTLSubItem(instrument[DatabaseObject.SYMBOL]), // symbol new GTLSubItem(release[DatabaseObject.CLIENT_ORDER_ID]), new GTLSubItem(release[DatabaseObject.SESSION_ID]), new GTLSubItem(release[DatabaseObject.COUNTERPARTY_ORDER_ID]), new GTLSubItem(release[DatabaseObject.RELEASE_QTY]), new GTLSubItem(release[DatabaseObject.EXECUTED_QTY]), new GTLSubItem(release[DatabaseObject.LIMIT_PRC]), new GTLSubItem(release[DatabaseObject.STOP_PRC]), new GTLSubItem(release[DatabaseObject.AVERAGE_PRC]), new GTLSubItem(release[DatabaseObject.EXECUTED_VAL]), new GTLSubItem(release.ToLocalTime(DatabaseObject.ADDED_DATETIME)), new GTLSubItem(release[DatabaseObject.ADDED_BY]), new GTLSubItem(release.ToLocalTime(DatabaseObject.UPDATED_DATETIME)), new GTLSubItem(release[DatabaseObject.UPDATED_BY]) }); return(releaseNode); }
private void FireAfterCellEdit(object source, GTLEmbeddedControlEventArgs args) { args.Cancel = true; ColorSubItem csi = null; GTLTreeNode node = args.TreeNode; GTLColumn col = data.Columns[args.Column]; GTLSubItem sub = node.SubItems[args.Column]; if (col.Name.Equals(DatabaseObject.MAX_OPEN_LONG_QTY) || col.Name.Equals(DatabaseObject.MAX_OPEN_SHORT_QTY) || col.Name.Equals(DatabaseObject.MAX_RELEASE_QTY)) { TextBox tb = (TextBox)args.Control; // // Ensure that the text box value is an integer greater // than or equal to zero. // try { int qty = Int32.Parse(tb.Text); if (qty < 0) { MessageBox.Show( " Invalid Quantity: " + tb.Text, "UPDATE Account Limit Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); data.ClearSelection(); csi = new RedColorSubItem(Color.White, node.SubItems[args.Column], node.Tag + data.Columns[args.Column].Text); colorNodes[csi.Tag] = csi; return; } } catch (Exception) { MessageBox.Show( " Invalid Quantity: " + tb.Text, "UPDATE Account Limit Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); data.ClearSelection(); csi = new RedColorSubItem(Color.White, node.SubItems[args.Column], node.Tag + data.Columns[args.Column].Text); colorNodes[csi.Tag] = csi; return; } // // Update the account limit // string account_id, symbol, security_exchange, fix_session_id, max_open_long_qty, max_open_short_qty, max_release_qty; account_id = node.SubItems[DatabaseObject.ACCOUNT_ID].Text; symbol = node.SubItems[DatabaseObject.SYMBOL].Text; security_exchange = node.SubItems[DatabaseObject.SECURITY_EXCHANGE].Text; fix_session_id = node.SubItems[DatabaseObject.SESSION_ID].Text; if (col.Name.Equals(DatabaseObject.MAX_OPEN_LONG_QTY)) { max_open_long_qty = tb.Text; max_open_short_qty = node.SubItems[DatabaseObject.MAX_OPEN_SHORT_QTY].Text; max_release_qty = node.SubItems[DatabaseObject.MAX_RELEASE_QTY].Text; } else if (col.Name.Equals(DatabaseObject.MAX_OPEN_SHORT_QTY)) { max_open_long_qty = node.SubItems[DatabaseObject.MAX_OPEN_LONG_QTY].Text; max_open_short_qty = tb.Text; max_release_qty = node.SubItems[DatabaseObject.MAX_RELEASE_QTY].Text; } else { max_open_long_qty = node.SubItems[DatabaseObject.MAX_OPEN_LONG_QTY].Text; max_open_short_qty = node.SubItems[DatabaseObject.MAX_OPEN_SHORT_QTY].Text; max_release_qty = tb.Text; } ClientAdapterResponse response = controller.SendRpc(new UpdateAccountLimit( account_id, symbol, security_exchange, fix_session_id, max_open_long_qty, max_open_short_qty, max_release_qty, "1")); response = controller.SendRpc(new ReloadStaticData( )); csi = new BlueColorSubItem(Color.White, sub, node.Tag + data.Columns[args.Column].Text); colorNodes[csi.Tag] = csi; args.Cancel = false; data.ClearSelection(); } if (col.Name.Equals(DatabaseObject.SESSION_ID)) { TextBox tb = (TextBox)args.Control; if ("".Equals(tb.Text)) { MessageBox.Show( " Invalid FIX Session ID", "UPDATE Account Limit Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); data.ClearSelection(); csi = new RedColorSubItem(Color.White, node.SubItems[args.Column], node.Tag + data.Columns[args.Column].Text); colorNodes[csi.Tag] = csi; return; } // // Update the account limit // ClientAdapterResponse response = controller.SendRpc(new UpdateAccountLimit( node.SubItems[DatabaseObject.ACCOUNT_ID].Text, node.SubItems[DatabaseObject.SYMBOL].Text, node.SubItems[DatabaseObject.SECURITY_EXCHANGE].Text, tb.Text, node.SubItems[DatabaseObject.MAX_OPEN_LONG_QTY].Text, node.SubItems[DatabaseObject.MAX_OPEN_SHORT_QTY].Text, node.SubItems[DatabaseObject.MAX_RELEASE_QTY].Text, "1")); response = controller.SendRpc(new ReloadStaticData( )); csi = new BlueColorSubItem(Color.White, sub, node.Tag + data.Columns[args.Column].Text); colorNodes[csi.Tag] = csi; args.Cancel = false; data.ClearSelection(); } }
private void FireAfterCellEdit(object source, GTLEmbeddedControlEventArgs args) { args.Cancel = true; GTLTreeNode node = args.TreeNode; GTLColumn col = data.Columns[args.Column]; if (!controller.Cache.HasRelease(node.Tag)) { MessageBox.Show("Unknown release: " + node.Tag); data.ClearSelection(); return; } string release_type = node.SubItems[DatabaseObject.RELEASE_TYPE].Text; if (col.Name.Equals(DatabaseObject.LIMIT_PRC) && (release_type.Equals("LIMIT") || release_type.Equals("STOP_LIMIT"))) { // // Get the current release // Release release = controller.Cache.GetRelease(node.Tag); TextBox tb = (TextBox)args.Control; // // Ensure something changed... // double old_limit_prc = release.ToDouble(DatabaseObject.LIMIT_PRC); try { // // Test for a valid number // double limit_prc = Double.Parse(tb.Text); // // Ensure new limit price is >= 0 and != old limit price // if (limit_prc >= 0 && limit_prc != old_limit_prc) { controller.SendRpc( new CancelReplaceRelease( release.Id, release[DatabaseObject.STOP_PRC], Convert.ToString(limit_prc))); } } catch (Exception) { MessageBox.Show( " Invalid Limit Price: " + tb.Text, "REPLACE RELEASE Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } data.ClearSelection(); } if (col.Name.Equals(DatabaseObject.STOP_PRC) && (release_type.Equals("STOP") || release_type.Equals("STOP_LIMIT"))) { // // Get the current release // Release release = controller.Cache.GetRelease(node.Tag); TextBox tb = (TextBox)args.Control; // // Ensure something changed... // double old_stop_prc = release.ToDouble(DatabaseObject.STOP_PRC); try { // // Test for a valid number // double stop_prc = Double.Parse(tb.Text); // // Ensure new limit price is >= 0 and != old limit price // if (stop_prc >= 0 && stop_prc != old_stop_prc) { controller.SendRpc( new CancelReplaceRelease( release.Id, Convert.ToString(stop_prc), release[DatabaseObject.LIMIT_PRC])); } } catch (Exception) { MessageBox.Show( " Invalid Stop Price: " + tb.Text, "REPLACE RELEASE Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } data.ClearSelection(); } }
private void FirePositionChanged(object o, PositionEventArgs e) { AccountPosition account_position = (AccountPosition)e.Data; // // Get the account on the position // Account account = controller.Cache.GetAccount(account_position.AccountId); if (null == account) { log.Warn("Unknown account: " + account_position.AccountId); return; } // // Find this account + investment_system in our list? // foreach (InvestmentSystemPosition investment_system_position in account_position.AccountPositions) { if (!controller.Cache.HasInvestmentSystem(investment_system_position.InvestmentSystemId)) { log.Warn("Unknown investment_system: " + investment_system_position.InvestmentSystemId); continue; } bool account_found = false; double notional_pl, total_pl, open_pl, closed_pl; foreach (GTLTreeNode account_node in data.Nodes) { notional_pl = total_pl = open_pl = closed_pl = 0.0; if (account_node.SubItems["accountId"].Text.Equals(investment_system_position.AccountId) && account_node.SubItems["investmentSystemId"].Text.Equals(investment_system_position.InvestmentSystemId)) { account_found = true; foreach (InstrumentPosition instrument_position in investment_system_position.InvestmentSystemPositions) { Instrument instrument = controller.Cache.GetInstrument( instrument_position.InstrumentId); if (null == instrument) { log.Warn("Unknown instrument_id: " + instrument_position.InstrumentId); continue; } // // Calculate the PL // instrument_position.ProfitLoss(account, instrument); notional_pl += instrument_position.NotionalPL; total_pl += instrument_position.TotalPL; open_pl += instrument_position.OpenPL; closed_pl += instrument_position.ClosedPL; // // Try to find the instrument in the existing nodes // bool instrument_found = false; foreach (GTLTreeNode instrument_node in account_node.Nodes) { if (instrument.Id.Equals(instrument_node.Tag)) { instrument_found = true; // // Update the instrument row // ((PercentSubItem)instrument_node.SubItems["totalPctPL"]).Update(instrument_position.NotionalPL); ((CurrencySubItem)instrument_node.SubItems["totalPL"]).Update(instrument_position.TotalPL); ((CurrencySubItem)instrument_node.SubItems["openPL"]).Update(instrument_position.OpenPL); ((CurrencySubItem)instrument_node.SubItems["closedPL"]).Update(instrument_position.ClosedPL); instrument_node.SubItems["longPos"].Text = instrument_position.LongPosition.ToString(double_fmt); instrument_node.SubItems["shortPos"].Text = instrument_position.ShortPosition.ToString(double_fmt); instrument_node.SubItems["closedPos"].Text = instrument_position.ClosedPosition.ToString(double_fmt); instrument_node.SubItems["avgOpenPrc"].Text = instrument_position.OpenPrice.ToString(double_fmt); instrument_node.SubItems["lastPrc"].Text = instrument[DatabaseObject.LAST_PRC]; break; } } if (!instrument_found) { // // Create the instrument node // GTLTreeNode instrument_node = new GTLTreeNode( ); instrument_node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem( ), // account_name new GTLSubItem(account[DatabaseObject.ACCOUNT_ID]), // account_id new GTLSubItem(investment_system_position.InvestmentSystemId), // investment_system_id new GTLSubItem(instrument[DatabaseObject.INSTRUMENT_ID]), // instrument_id new GTLSubItem(instrument[DatabaseObject.NAME]), // instrument_name new PercentSubItem(instrument_position.NotionalPL, true), // pctPL new CurrencySubItem(instrument_position.TotalPL, true), // totalPL new CurrencySubItem(instrument_position.OpenPL, true), // openPL new CurrencySubItem(instrument_position.ClosedPL, true), // closedPL new GTLSubItem(instrument_position.LongPosition.ToString(double_fmt)), // longPos new GTLSubItem(instrument_position.ShortPosition.ToString(double_fmt)), // shortPos new GTLSubItem(instrument_position.ClosedPosition.ToString(double_fmt)), // closedPos new GTLSubItem(instrument_position.OpenPrice.ToString( )), // avgOpenPrc new GTLSubItem(instrument[DatabaseObject.LAST_PRC]) // lastPrc }); instrument_node.Tag = instrument.Id; account_node.Nodes.Add(instrument_node); account_node.SubItems[0].Span = 2; } } // // Update the aggregated account_node PL // ((PercentSubItem)account_node.SubItems["totalPctPL"]).Update(notional_pl); ((CurrencySubItem)account_node.SubItems["totalPL"]).Update(total_pl); ((CurrencySubItem)account_node.SubItems["openPL"]).Update(open_pl); ((CurrencySubItem)account_node.SubItems["closedPL"]).Update(closed_pl); break; } } if (!account_found) { // // We couldn't find this account + investment_system, so // create a new one. // data.BeginUpdate(); data.BeginNodeListChange(); GTLTreeNode positionNode = CreatePositionNode(investment_system_position); if (null != positionNode) { data.Nodes.Add(positionNode); } data.EndNodeListChange(); data.EndUpdate(); } } }
private void FireBroadcast(object o, BroadcastEventArgs e) { DateTime dateValue; InvestmentSystemBroadcast investment_system_broadcast = e.Data; if (investment_system_broadcast.Type == InvestmentSystemBroadcast.Types.BroadcastType.DATA) { InvestmentSystemOneData invsys_one_data = InvestmentSystemOneData.ParseFrom( investment_system_broadcast.Delegate); if (invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.SYSTEM) { DateTime.TryParseExact( invsys_one_data.UpdateTm, "HH:mm.ss", enUS, DateTimeStyles.AssumeUniversal, out dateValue); statusLabel.Text = invsys_one_data.Status; double ask = Convert.ToDouble(invsys_one_data.BestAsk); double bid = Convert.ToDouble(invsys_one_data.BestBid); openPLLabel.Text = invsys_one_data.OpenPl.ToString("0.00"); closedPLLabel.Text = invsys_one_data.ClosedPl.ToString("0.00"); if (invsys_one_data.OpenPl > 0) { openPLLabel.ForeColor = Color.Green; } else if (invsys_one_data.OpenPl < 0) { openPLLabel.ForeColor = Color.Red; } else { openPLLabel.ForeColor = Color.Black; } if (invsys_one_data.ClosedPl > 0) { closedPLLabel.ForeColor = Color.Green; } else if (invsys_one_data.ClosedPl < 0) { closedPLLabel.ForeColor = Color.Red; } else { closedPLLabel.ForeColor = Color.Black; } chartPanel.UpdateBidAsk(bid, ask); bidaskLabel.Text = ask.ToString(controller.PriceFormat) + " , " + bid.ToString(controller.PriceFormat); this.ParentForm.Text = controller.ConnectionElement.Name + " " + invsys_one_data.Status + " " + dateValue.ToLongTimeString(); if (invsys_one_data.TimebarList.Count == 1) { chartPanel.UpdateTimebarData(invsys_one_data.TimebarList[0], false); } } else if (loginFlag == true && invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.TIMEBAR) { foreach (Timebar timebar in invsys_one_data.TimebarList) { chartPanel.UpdateTimebarData(timebar, true); } } else if (loginFlag == true && invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.TREND) { foreach (Trend trend in invsys_one_data.TrendList) { chartPanel.AddTrendData(trend); } } else if (loginFlag == true && invsys_one_data.Type == InvestmentSystemOneData.Types.DataType.EXECUTION) { foreach (OrderExecution execution in invsys_one_data.OrderExecutionList) { chartPanel.AddOrderExecutionData(execution, true); GTLTreeNode node = new GTLTreeNode( EPOCH.AddSeconds(execution.Timestamp) .ToLocalTime().ToString()); if (execution.Type == OrderExecution.Types.ExecutionType.BUY) { node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(EPOCH.AddSeconds(execution.Timebar).ToLocalTime().ToString()), new GTLSubItem("BUY"), new GTLSubItem("" + execution.Quantity), new GTLSubItem("" + execution.Price) }); } else { node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(EPOCH.AddSeconds(execution.Timebar).ToLocalTime().ToString()), new GTLSubItem("SELL"), new GTLSubItem("" + execution.Quantity), new GTLSubItem("" + execution.Price) }); } data.Nodes.Insert(0, node); } } chartPanel.Redraw(); } }
private GTLTreeNode CreatePositionNode(InvestmentSystemPosition position) { // // Get the account on the position // Account account = controller.Cache.GetAccount(position.AccountId); if (null == account) { log.Warn("Unknown account: " + position.AccountId); return(null); } if (!controller.Cache.HasInvestmentSystem(position.InvestmentSystemId)) { log.Warn("Unknown investment_system: " + position.InvestmentSystemId); return(null); } GTLTreeNode account_node = new GTLTreeNode(" " + account[DatabaseObject.NAME] + " --> " + position.InvestmentSystemId); double notional_pl, total_pl, open_pl, closed_pl; notional_pl = total_pl = open_pl = closed_pl = 0.0; foreach (InstrumentPosition instrument_position in position.InvestmentSystemPositions) { // // Get the instrument // Instrument instrument = controller.Cache.GetInstrument( instrument_position.InstrumentId); if (null == instrument) { log.Warn("Unknown instrument_id: " + instrument_position.InstrumentId); continue; } // // Calculate the PL // instrument_position.ProfitLoss(account, instrument); // // Create the instrument node // GTLTreeNode instrument_node = new GTLTreeNode( ); instrument_node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem( ), // account_name new GTLSubItem(account[DatabaseObject.ACCOUNT_ID]), // account_id new GTLSubItem(position.InvestmentSystemId), // investment_system_id new GTLSubItem(instrument[DatabaseObject.INSTRUMENT_ID]), // instrument_id new GTLSubItem(instrument[DatabaseObject.NAME]), // instrument_name new PercentSubItem(instrument_position.NotionalPL, true), // pctPL new CurrencySubItem(instrument_position.TotalPL, true), // totalPL new CurrencySubItem(instrument_position.OpenPL, true), // openPL new CurrencySubItem(instrument_position.ClosedPL, true), // closedPL new GTLSubItem(instrument_position.LongPosition.ToString(double_fmt)), // longPos new GTLSubItem(instrument_position.ShortPosition.ToString(double_fmt)), // shortPos new GTLSubItem(instrument_position.ClosedPosition.ToString(double_fmt)), // closedPos new GTLSubItem(instrument_position.OpenPrice.ToString( )), // avgOpenPrc new GTLSubItem(instrument[DatabaseObject.LAST_PRC]) // lastPrc }); instrument_node.Tag = instrument.Id; account_node.Nodes.Add(instrument_node); account_node.SubItems[0].Span = 2; notional_pl += instrument_position.NotionalPL; total_pl += instrument_position.TotalPL; open_pl += instrument_position.OpenPL; closed_pl += instrument_position.ClosedPL; } account_node.SubItems.AddRange(new GTLSubItem [] { new GTLSubItem(account[DatabaseObject.ACCOUNT_ID]), // account_id new GTLSubItem(position.InvestmentSystemId), // investment_system_id new GTLSubItem( ), // instrument_id new GTLSubItem( ), // instrument_name new PercentSubItem(notional_pl, true), // totalPctPL new CurrencySubItem(total_pl, true), // totalPL new CurrencySubItem(open_pl, true), // openPL new CurrencySubItem(closed_pl, true), // closedPL new GTLSubItem( ), // longPos new GTLSubItem( ), // shortPos new GTLSubItem( ), // closedPos new GTLSubItem( ), // avgOpenPrc new GTLSubItem( ) // lastPrc }); account_node.Tag = account[DatabaseObject.ACCOUNT_ID]; return(account_node); }
/// <summary> /// Notifies the client that a resource viewer has been opened. /// </summary> protected void ViewerOpened(int index, object value) { TabPage page = (TabPage)value; NWN2ConversationViewer viewer = page.Control as NWN2ConversationViewer; if (viewer == null) { return; } try { GlacialTreeList tree = (GlacialTreeList)viewer.Controls["panelResults"].Controls["treeListResults"]; if (tree == null) { throw new ApplicationException("Couldn't find GlacialTreeList."); } winforms.MenuItem addEditScript = new winforms.MenuItem("Add script"); winforms.MenuItem deleteScript = new winforms.MenuItem("Delete script"); winforms.MenuItem addEditCondition = new winforms.MenuItem("Add condition"); winforms.MenuItem deleteCondition = new winforms.MenuItem("Delete condition"); addEditScript.Click += delegate { if (tree.SelectedNodes.Count != 1) { MessageBox.Show("Select a single line of the conversation."); } else { try { GTLTreeNode node = (GTLTreeNode)tree.SelectedNodes[0]; NWN2ConversationConnector connector = node.Tag as NWN2ConversationConnector; if (connector != null) { addScriptToLine.Invoke(connector, viewer.Conversation); } } catch (Exception x) { MessageBox.Show("Something went wrong when adding/editing the script.\n\n" + x); } } }; addEditCondition.Click += delegate { if (tree.SelectedNodes.Count != 1) { MessageBox.Show("Select a single line of the conversation."); } else { try { GTLTreeNode node = (GTLTreeNode)tree.SelectedNodes[0]; NWN2ConversationConnector connector = node.Tag as NWN2ConversationConnector; if (connector != null) { addConditionToLine.Invoke(connector, viewer.Conversation); } } catch (Exception x) { MessageBox.Show("Something went wrong when adding/editing the script.\n\n" + x); } } }; deleteScript.Click += delegate { if (tree.SelectedNodes.Count != 1) { MessageBox.Show("Select a single line of the conversation."); } else { try { GTLTreeNode node = (GTLTreeNode)tree.SelectedNodes[0]; NWN2ConversationConnector connector = node.Tag as NWN2ConversationConnector; if (connector != null && connector.Actions.Count > 0) { MessageBoxResult result = MessageBox.Show("Delete the script on this line?", "Delete?", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { string scriptName = connector.Actions[0].Script.FullName; connector.Actions.Clear(); viewer.RefreshTreeItemForConnector(connector); Log.WriteAction(LogAction.deleted, "script", scriptName + " (was attached to line '" + connector.Line.Text.GetSafeString(OEIShared.Utils.BWLanguages.CurrentLanguage) + "')"); } } } catch (Exception x) { MessageBox.Show("Something went wrong when deleting the script.\n\n" + x); } } }; deleteCondition.Click += delegate { if (tree.SelectedNodes.Count != 1) { MessageBox.Show("Select a single line of the conversation."); } else { try { GTLTreeNode node = (GTLTreeNode)tree.SelectedNodes[0]; NWN2ConversationConnector connector = node.Tag as NWN2ConversationConnector; if (connector != null && connector.Conditions.Count > 0) { MessageBoxResult result = MessageBox.Show("Delete the condition on this line?", "Delete?", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { string scriptName = connector.Conditions[0].Script.FullName; connector.Conditions.Clear(); viewer.RefreshTreeItemForConnector(connector); Log.WriteAction(LogAction.deleted, "script", scriptName + " (was attached as condition to line '" + connector.Line.Text.GetSafeString(OEIShared.Utils.BWLanguages.CurrentLanguage) + "')"); } } } catch (Exception x) { MessageBox.Show("Something went wrong when deleting the condition.\n\n" + x); } } }; tree.ContextMenu.Popup += delegate { if (tree.SelectedNodes.Count != 1) { addEditScript.Enabled = false; addEditCondition.Enabled = false; deleteScript.Enabled = false; deleteCondition.Enabled = false; } else { GTLTreeNode node = (GTLTreeNode)tree.SelectedNodes[0]; NWN2ConversationConnector connector = node.Tag as NWN2ConversationConnector; if (connector == null) { addEditScript.Enabled = false; addEditCondition.Enabled = false; } else { addEditScript.Enabled = true; addEditCondition.Enabled = true; } if (connector != null && ScriptHelper.HasFlipScriptAttachedAsAction(connector)) { addEditScript.Text = "Edit script"; deleteScript.Enabled = true; } else { addEditScript.Text = "Add script"; deleteScript.Enabled = false; } if (connector != null && ScriptHelper.HasFlipScriptAttachedAsCondition(connector)) { addEditCondition.Text = "Edit condition"; deleteCondition.Enabled = true; } else { addEditCondition.Text = "Add condition"; deleteCondition.Enabled = false; } } }; tree.ContextMenu.MenuItems.Add("-"); tree.ContextMenu.MenuItems.Add(addEditScript); tree.ContextMenu.MenuItems.Add(deleteScript); tree.ContextMenu.MenuItems.Add("-"); tree.ContextMenu.MenuItems.Add(addEditCondition); tree.ContextMenu.MenuItems.Add(deleteCondition); } catch (Exception x) { MessageBox.Show("Error when trying to integrate Flip with conversation editor.", x.ToString()); } }