示例#1
0
        public void LoadActiveSet()
        {
            ClientAdapterResponse response = SendRpc(new GetActiveSet( ));

            //
            //  Iterate through each overnight position
            //

            foreach (PositionOvernightData overnight_position in response.DealingResponse.PositionList)
            {
                positionManager.Add(new OvernightPosition(overnight_position));
            }

            //
            //  Iterate through each order message
            //

            foreach (OrderMessage order in response.DealingResponse.OrderList)
            {
                if (order.HasOrderData)
                {
                    Order o = new Order(order.OrderData);

                    foreach (AllocationData data in order.AllocationDataList)
                    {
                        o.AddAllocation(new Allocation(data));
                    }

                    //
                    //  Add the order to the active set
                    //

                    activeSet.Update(o);
                }

                //
                //  Get the releases...
                //

                foreach (ReleaseData data in order.ReleaseDataList)
                {
                    activeSet.Update(new Release(data));
                }

                //
                //  Get the executions...
                //

                foreach (ExecutionData data in order.ExecutionDataList)
                {
                    activeSet.Update(new Execution(data));
                }
            }
        }
示例#2
0
        private void FireSendToFixChanged(object o, EventArgs e)
        {
            if (!sendToFix.Checked)
            {
                //
                //  Display 'are you sure' message box...
                //

                DialogResult result = MessageBox.Show(
                    "Are you sure you want to FLATTEN ALL OPEN POSITIONS and stop sending releases to the FIX Engine?",
                    "Stop Sending to FIX Confirmation",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Exclamation);

                if (result == System.Windows.Forms.DialogResult.No)
                {
                    //
                    //  Cancel the event
                    //

                    sendToFix.Checked = true;
                }
                else
                {
                    //
                    //  Generate offsetting market orders for all accounts
                    //  with open positions.
                    //

                    foreach (AccountPosition account_position in controller.Position.AccountPositions)
                    {
                        CloseAccountPosition(account_position);
                    }
                }

                ClientAdapterResponse response = controller.SendRpc(
                    new UpdateDealingStatus("send_to_fix", "0"));
            }
            else
            {
                ClientAdapterResponse response = controller.SendRpc(
                    new UpdateDealingStatus("send_to_fix", "1"));
            }

            splitButton.Enabled = sendToFix.Checked;
        }
示例#3
0
        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;
        }
示例#4
0
        private void LoadDealingStatus()
        {
            ClientAdapterResponse response = controller.SendRpc(new GetDealingStatus( ));

            //
            //  Find the send_to_fix parameter
            //

            DealingEngineResponse dealing_response = response.DealingResponse;

            foreach (SystemParameterData system_parameter in dealing_response.SystemParameterList)
            {
                if ("send_to_fix".Equals(system_parameter.Name))
                {
                    sendToFix.Checked   = "1".Equals(system_parameter.Value);
                    splitButton.Enabled = sendToFix.Checked;
                    return;
                }
            }
        }
示例#5
0
        public ClientAdapterResponse SendRpc(ClientMessage message, int timeout)
        {
            if (InvokeRequired)
            {
                log.Error("SendRpc must be called on client thread.");
                return(null);
            }
            else
            {
                sendMutex.WaitOne();

                //
                //  Set the RPC timer to fire in timeout seconds.
                //

                timer.Change(timeout, Timeout.Infinite);

                //
                //  Do the rpc -- Send / Recv
                //

                if (log.IsDebugEnabled)
                {
                    log.Debug(" <-s- " + message.ToMessage(session_id).ToString());
                }

                rpc.Send(message.ToMessage(session_id).ToByteArray());
                ClientAdapterResponse response = ClientAdapterResponse.ParseFrom(rpc.Recv( ));
                timer.Change(Timeout.Infinite, Timeout.Infinite);

                sendMutex.ReleaseMutex();

                if (log.IsDebugEnabled)
                {
                    log.Debug(" -r-> " + response.ToString());
                }

                return(response);
            }
        }
示例#6
0
        private void FireUpdateButton(object sender, EventArgs args)
        {
            if (account != null)
            {
                ClientAdapterResponse response =
                    controller.SendRpc(new UpdateAccount(
                                           account[DatabaseObject.ACCOUNT_ID],
                                           account[DatabaseObject.NAME],
                                           accountData.MarketAccountName,
                                           accountData.AccountId,
                                           accountData.GiveUpAccount,
                                           accountData.GiveUpFirm,
                                           account[DatabaseObject.NOTIONAL_VAL],
                                           account[DatabaseObject.PROFIT_TARGET],
                                           account[DatabaseObject.STOP_LOSS],
                                           account[DatabaseObject.SIGNAL_WEIGHT],
                                           account[DatabaseObject.IS_SUPPRESSED],
                                           accountData.IsActive));

                if (response.Type == ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                {
                    account.SetAttribute(DatabaseObject.MARKET_ACCOUNT_ID, accountData.MarketAccountName);
                    account.SetAttribute(DatabaseObject.CUSTODY_ACCOUNT_ID, accountData.AccountId);
                    account.SetAttribute(DatabaseObject.GIVEUP_ACCOUNT_ID, accountData.GiveUpAccount);
                    account.SetAttribute(DatabaseObject.GIVEUP_FIRM_ID, accountData.GiveUpFirm);
                    account.SetAttribute(DatabaseObject.IS_ACTIVE, accountData.IsActive);

                    controller.Cache.Update(account);

                    //response = controller.SendRpc( new UpdateAccountLimitSessionIds(
                    //    account[ DatabaseObject.ACCOUNT_ID ], fixSessionIdTextBox.Text ) );

                    response = controller.SendRpc(new ReloadStaticData( ));

                    MessageBox.Show("Account: " + account[DatabaseObject.NAME] + " updated successfully.");
                }
            }
        }
示例#7
0
        private void CreateAccount(AccountDataPanel accountData)
        {
            //
            //  Create the account
            //

            ClientAdapterResponse response = controller.SendRpc(
                new CreateAccount(
                    accountData.AccountName,
                    accountData.MarketAccountName,
                    accountData.AccountId,
                    "0",
                    "0",
                    "0",
                    "0",
                    accountData.IsActive));


            if (response.Type == ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
            {
                MessageBox.Show("Account: " + accountData.AccountName + " created successfully.");
            }
        }
示例#8
0
        private void FireLoginReady(object sender, System.EventArgs e)
        {
            LoginControl login = (LoginControl)sender;

            //
            //  Create a new login client request
            //

            ClientAdapterResponse response = controller.SendRpc(
                new Login(login.Username, login.Password));

            if (response.Type != ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Invalid username / password.",
                    "Login Error", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                login.Reset();
                login.Invalidate();
                return;
            }

            if (!response.HasDatabaseResponse ||
                response.DatabaseResponse.ResultSetCount != 1 ||
                response.DatabaseResponse.GetResultSet(0).RowCount != 1)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Invalid username / password.",
                    "Login Error", MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);

                login.Reset();
                login.Invalidate();
                return;
            }

            User userData = new User(
                response.DatabaseResponse.
                GetResultSet(0).GetRow(0));

            //
            //  Get the user's applications
            //

            response = controller.SendRpc(
                new GetUserApplications(userData.Id));

            foreach (DatabaseEngineResponse.Types.ResultSet rs in response.DatabaseResponse.ResultSetList)
            {
                foreach (DatabaseEngineResponse.Types.ResultSet.Types.Row row in rs.RowList)
                {
                    userData.AddApplication(row);
                }
            }

            //
            //  Set the user
            //

            controller.ApplicationUser = userData;

            //
            //  Load the active set data
            //

            login.labelHeader = "Loading Static Data...";
            Application.DoEvents();

            controller.LoadStaticData();

            login.labelHeader = "Loading Dealing Collection...";
            Application.DoEvents();

            controller.LoadActiveSet();

            //
            //  Create the main GUI
            //

            this.SuspendLayout();

            //
            //  Menu
            //

            MainMenu menu = new MainMenu();
            MenuItem file = new MenuItem("File");
            MenuItem edit = new MenuItem("Edit");
            MenuItem help = new MenuItem("Help");

            menu.MenuItems.Add(file);
            menu.MenuItems.Add(edit);
            menu.MenuItems.Add(help);

            file.MenuItems.Add(new MenuItem("Exit", new EventHandler(FireExit)));

            //
            //  Status Strip
            //

            ToolStripStatusLabel toolStripStatusLabel = new ToolStripStatusLabel();

            toolStripStatusLabel.Name = "toolStripStatusLabel";
            toolStripStatusLabel.Size = new System.Drawing.Size(38, 17);
            toolStripStatusLabel.Text =
                (string)ConfigurationManager.AppSettings["fcm_id"] + " : " +
                (string)ConfigurationManager.AppSettings["rpc"];

            System.Windows.Forms.StatusStrip statusStrip = new System.Windows.Forms.StatusStrip();
            statusStrip.Location = new System.Drawing.Point(0, 248);
            statusStrip.Name     = "statusStrip";
            statusStrip.Size     = new System.Drawing.Size(292, 25);
            statusStrip.TabIndex = 0;
            statusStrip.Text     = "statusStrip";
            statusStrip.Items.AddRange(new ToolStripItem[] { toolStripStatusLabel });

            //
            //  Split Container
            //

            splitContainer.SuspendLayout();
            splitContainer.BackColor         = System.Drawing.Color.LightSteelBlue;
            splitContainer.Dock              = System.Windows.Forms.DockStyle.Fill;
            splitContainer.Size              = new System.Drawing.Size(550, 550);
            splitContainer.Location          = new System.Drawing.Point(0, 0);
            splitContainer.Name              = "splitContainer";
            splitContainer.SplitterIncrement = 10;
            splitContainer.SplitterWidth     = 6;
            splitContainer.SplitterDistance  = 220;
            splitContainer.Panel1MinSize     = 200;
            splitContainer.FixedPanel        = System.Windows.Forms.FixedPanel.Panel1;
            splitContainer.Panel1.Padding    = new System.Windows.Forms.Padding(4, 4, 0, 4);
            splitContainer.Panel2.Padding    = new System.Windows.Forms.Padding(0, 4, 4, 4);

            if (userData.IsComplianceUser)
            {
                splitContainer.Panel2.Controls.AddRange(new Control[]
                {
                    new DealingViewer(controller),
                    new AccountComplianceViewer(controller)
                });

                splitContainer.Panel1.Controls.Add(new ClientNavigation(controller));
            }
            else if (userData.IsClientUser)
            {
                splitContainer.Panel2.Controls.AddRange(new Control[]
                {
                    new DealingViewer(controller)
                });

                splitContainer.Panel1.Controls.Add(new ClientNavigation(controller));
            }

            //
            //  (this) Form variables
            //

            this.Menu            = menu;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
            this.MaximizeBox     = true;
            this.MinimizeBox     = true;
            this.FormBorderStyle = FormBorderStyle.Sizable;
            this.SizeGripStyle   = SizeGripStyle.Show;
            this.Size            = new System.Drawing.Size(1200, 880);
            this.CenterToScreen();
            //this.WindowState = FormWindowState.Maximized;

            this.Controls.Clear();
            this.Controls.AddRange(new Control [] { splitContainer, statusStrip });

            splitContainer.ResumeLayout(false);
            this.ResumeLayout(true);
            this.PerformLayout();
        }
示例#9
0
        private void FireExecuteButton(object sender, EventArgs args)
        {
            int    signal_qty = 0;
            double limit_prc = 0.0, stop_prc = 0.0;
            string side_code, order_type;

            DraftOrderData.Types.SideCode  side_code_type;
            DraftOrderData.Types.OrderType draft_order_type;

            if (sender == buyButton)
            {
                side_code      = "BUY";
                side_code_type = DraftOrderData.Types.SideCode.BUY;
            }
            else
            {
                side_code      = "SELL";
                side_code_type = DraftOrderData.Types.SideCode.SELL;
            }

            if (orderTypeComboBox.Text == "LIMIT")
            {
                order_type       = "LIMIT";
                draft_order_type = DraftOrderData.Types.OrderType.LIMIT;

                if ("".Equals(limitPriceTextBox.Text))
                {
                    MessageBox.Show("LIMIT order type requires limit price.");
                    return;
                }
                else
                {
                    try
                    {
                        limit_prc = Convert.ToDouble(limitPriceTextBox.Text);

                        if (limit_prc <= 0.0)
                        {
                            MessageBox.Show("Invalid limit price: " + limitPriceTextBox.Text);
                            return;
                        }
                    }
                    catch (Exception limitError)
                    {
                        log.Error("Signal qty error.", limitError);
                        MessageBox.Show("Invalid limit price: " +
                                        limitPriceTextBox.Text);
                        return;
                    }
                }
            }
            else if (orderTypeComboBox.Text == "STOP")
            {
                order_type       = "STOP";
                draft_order_type = DraftOrderData.Types.OrderType.STOP;

                if ("".Equals(stopPriceTextBox.Text))
                {
                    MessageBox.Show("STOP order type requires stop price.");
                    return;
                }
                else
                {
                    try
                    {
                        stop_prc = Convert.ToDouble(stopPriceTextBox.Text);

                        if (stop_prc <= 0.0)
                        {
                            MessageBox.Show("Invalid stop price: " + stopPriceTextBox.Text);
                            return;
                        }
                    }
                    catch (Exception stopError)
                    {
                        log.Error("Signal qty error.", stopError);
                        MessageBox.Show("Invalid stop price: '" +
                                        stopPriceTextBox.Text + "'");
                        return;
                    }
                }
            }
            else if (orderTypeComboBox.Text == "STOP LIMIT")
            {
                order_type       = "STOP_LIMIT";
                draft_order_type = DraftOrderData.Types.OrderType.STOP_LIMIT;

                if ("".Equals(limitPriceTextBox.Text))
                {
                    MessageBox.Show("STOP LIMIT order type requires limit price.");
                    return;
                }
                else
                {
                    try
                    {
                        limit_prc = Convert.ToDouble(limitPriceTextBox.Text);

                        if (limit_prc <= 0.0)
                        {
                            MessageBox.Show("Invalid limit price: " + limitPriceTextBox.Text);
                            return;
                        }
                    }
                    catch (Exception limitError)
                    {
                        log.Error("Signal qty error.", limitError);
                        MessageBox.Show("Invalid limit price: " + limitPriceTextBox.Text);
                        return;
                    }
                }

                if ("".Equals(stopPriceTextBox.Text))
                {
                    MessageBox.Show("STOP LIMIT order type requires stop price.");
                    return;
                }
                else
                {
                    try
                    {
                        stop_prc = Convert.ToDouble(stopPriceTextBox.Text);

                        if (stop_prc <= 0.0)
                        {
                            MessageBox.Show("Invalid stop price: " + stopPriceTextBox.Text);
                            return;
                        }
                    }
                    catch (Exception stopError)
                    {
                        log.Error("Signal qty error.", stopError);
                        MessageBox.Show("Invalid stop price: '" +
                                        stopPriceTextBox.Text + "'");
                        return;
                    }
                }
            }
            else if (orderTypeComboBox.Text == "MKT ON CLOSE")
            {
                order_type       = "MARKET_ON_CLOSE";
                draft_order_type = DraftOrderData.Types.OrderType.MARKET_ON_CLOSE;
            }
            else
            {
                order_type       = "MARKET";
                draft_order_type = DraftOrderData.Types.OrderType.MARKET;
            }

            if (tabControl.SelectedIndex == 0)
            {
                //
                //  Validate all strategy quantities
                //

                foreach (GTLTreeNode strategy in strategies.Nodes)
                {
                    try
                    {
                        signal_qty = Convert.ToInt32(strategy.SubItems[1].Text);
                    }
                    catch (Exception qtyError)
                    {
                        log.Error("Signal qty error.", qtyError);
                        MessageBox.Show("Invalid signal size: " +
                                        strategy.SubItems[1].Text);
                        return;
                    }

                    if (signal_qty < 0)
                    {
                        MessageBox.Show(strategy.SubItems[0].Text +
                                        " has invalid signal size: " +
                                        strategy.SubItems[1].Text);
                        return;
                    }
                }

                //
                //  All imputs are ok, create the signals
                //

                foreach (GTLTreeNode strategy in strategies.Nodes)
                {
                    signal_qty = Convert.ToInt32(strategy.SubItems[1].Text);

                    if (signal_qty > 0)
                    {
                        SignalData signalData = SignalData.CreateBuilder()
                                                .SetInvestmentSystemId(selectedInvestmentSystem.Id)
                                                .SetSignalId((string)strategy.Tag)
                                                .SetInstrumentId(selectedInstrument.Id)
                                                .SetSideCode(side_code)
                                                .SetSignalQty(strategy.SubItems[1].Text)
                                                .SetOrderType(order_type)
                                                .SetLimitPrc(Convert.ToString(limit_prc))
                                                .SetStopPrc(Convert.ToString(stop_prc))
                                                .Build();

                        if (releaseToFixCheckBox.Checked)
                        {
                            ClientAdapterResponse response = controller.SendRpc(
                                new com.quantmodel.common.network.message.ExecuteSignal(signalData));
                        }
                        else
                        {
                            ClientAdapterResponse response = controller.SendRpc(
                                new com.quantmodel.common.network.message.CreateDraftOrder(signalData));

                            if (response.Type == ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                            {
                                DealingEngineResponse dealing_response = response.DealingResponse;

                                if (dealing_response.Type == DealingEngineResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                                {
                                    foreach (DraftOrderMessage draft_order_msg in dealing_response.DraftOrderList)
                                    {
                                        ClientAdapterResponse create_order_response = controller.SendRpc(
                                            new com.quantmodel.common.network.message.CreateOrder(draft_order_msg));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                //
                //  Validate all account quantities
                //

                foreach (GTLTreeNode account in accounts.Nodes)
                {
                    try
                    {
                        signal_qty = Convert.ToInt32(account.SubItems[1].Text);
                    }
                    catch (Exception qtyError)
                    {
                        log.Error("Allocation qty error.", qtyError);
                        MessageBox.Show("Invalid allocation quantity: " +
                                        account.SubItems[1].Text);
                        return;
                    }

                    if (signal_qty < 0)
                    {
                        MessageBox.Show(account.SubItems[0].Text +
                                        " has invalid allocation quantity: " +
                                        account.SubItems[1].Text);
                        return;
                    }
                }

                //
                //  All imputs are ok, create the draft orders
                //

                foreach (GTLTreeNode account in accounts.Nodes)
                {
                    signal_qty = Convert.ToInt32(account.SubItems[1].Text);

                    if (signal_qty > 0)
                    {
                        DraftOrderData draftOrder = DraftOrderData.CreateBuilder()
                                                    .SetInvestmentSystemId("CLIENT")
                                                    .SetInstrumentId(selectedInstrument.Id)
                                                    .SetSideCode(side_code_type)
                                                    .SetTif(DraftOrderData.Types.TimeInForce.DAY)
                                                    .SetOrderType(draft_order_type)
                                                    .SetOrderQty(Convert.ToString(signal_qty))
                                                    .SetLimitPrc(Convert.ToString(limit_prc))
                                                    .SetStopPrc(Convert.ToString(stop_prc))
                                                    .Build();

                        DraftAllocationData draftAllocation = DraftAllocationData.CreateBuilder()
                                                              .SetAccountId((string)account.Tag)
                                                              .SetAllocationQty(Convert.ToString(signal_qty))
                                                              .Build();

                        ClientAdapterResponse create_order_response = controller.SendRpc(
                            new com.quantmodel.common.network.message.CreateOrder(draftOrder, draftAllocation));

                        if (create_order_response.Type == ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                        {
                            DealingEngineResponse dealing_order_response = create_order_response.DealingResponse;

                            if (dealing_order_response.Type == DealingEngineResponse.Types.ResponseType.ACKNOWLEDGEMENT &&
                                releaseToFixCheckBox.Checked)
                            {
                                //
                                //  Release the order
                                //

                                foreach (OrderMessage order_msg in dealing_order_response.OrderList)
                                {
                                    ClientAdapterResponse release_order_response = controller.SendRpc(
                                        new com.quantmodel.common.network.message.ReleaseOrder(order_msg.OrderData.OrderId));

                                    if (release_order_response.Type == ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                                    {
                                        DealingEngineResponse dealing_release_response = release_order_response.DealingResponse;

                                        if (dealing_release_response.Type != DealingEngineResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#10
0
        private void CloseAccountPosition(AccountPosition account_position)
        {
            foreach (InstrumentPosition instrument_position in account_position.InstrumentPositions)
            {
                DraftOrderData.Types.SideCode sideCode;

                if (instrument_position.Exposure == InstrumentPosition.PositionExposure.LONG)
                {
                    sideCode = DraftOrderData.Types.SideCode.SELL;
                }
                else if (instrument_position.Exposure == InstrumentPosition.PositionExposure.SHORT)
                {
                    sideCode = DraftOrderData.Types.SideCode.BUY;
                }
                else
                {
                    //
                    //  No need to close a flat position.
                    //

                    continue;
                }

                DraftOrderData draftOrder = DraftOrderData.CreateBuilder()
                                            .SetInvestmentSystemId(instrument_position.InvestmentSystemId)
                                            .SetInstrumentId(instrument_position.InstrumentId)
                                            .SetSideCode(sideCode)
                                            .SetTif(DraftOrderData.Types.TimeInForce.DAY)
                                            .SetOrderType(DraftOrderData.Types.OrderType.MARKET)
                                            .SetOrderQty(Convert.ToString(instrument_position.OpenPosition))
                                            .SetLimitPrc("0")
                                            .SetStopPrc("0")
                                            .Build();

                DraftAllocationData draftAllocation = DraftAllocationData.CreateBuilder()
                                                      .SetAccountId(account_position.AccountId)
                                                      .SetAllocationQty(Convert.ToString(instrument_position.OpenPosition))
                                                      .Build();

                ClientAdapterResponse create_order_response = controller.SendRpc(new CreateOrder(draftOrder, draftAllocation));

                if (create_order_response.Type == ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                {
                    DealingEngineResponse dealing_order_response = create_order_response.DealingResponse;

                    if (dealing_order_response.Type == DealingEngineResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                    {
                        //
                        //  Release the market order
                        //

                        foreach (OrderMessage order_msg in dealing_order_response.OrderList)
                        {
                            ClientAdapterResponse release_order_response = controller.SendRpc(new ReleaseOrder(order_msg.OrderData.OrderId));

                            if (release_order_response.Type == ClientAdapterResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                            {
                                DealingEngineResponse dealing_release_response = release_order_response.DealingResponse;

                                if (dealing_release_response.Type != DealingEngineResponse.Types.ResponseType.ACKNOWLEDGEMENT)
                                {
                                }
                            }
                        }
                    }
                }
            }
        }
示例#11
0
        private void FireCancelRelease(object o, EventArgs e)
        {
            string message = null;

            if (data.SelectedNodes.Count > 1)
            {
                message = "Are you sure you want to CANCEL these releases?";
            }
            else
            {
                message = "Are you sure you want to CANCEL this release?";
            }

            DialogResult result = MessageBox.Show(
                message,
                "CANCEL Release Confirmation",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Exclamation);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                //
                //  Get the selected release(s)
                //

                foreach (GTLTreeNode releaseNode in data.SelectedNodes)
                {
                    if (controller.Cache.HasRelease(releaseNode.Tag))
                    {
                        Release release = controller.Cache.GetRelease(releaseNode.Tag);

                        if ("NEW".Equals(release.ReleaseStatus()) ||
                            "PARTIALLY_FILLED".Equals(release.ReleaseStatus()) ||
                            "PENDING_REPLACE".Equals(release.ReleaseStatus()) ||
                            "REPLACED".Equals(release.ReleaseStatus()))
                        {
                            ClientAdapterResponse response =
                                controller.SendRpc(new CancelRelease(release.Id));
                        }
                        else
                        {
                            MessageBox.Show(
                                release.Id + " Invalid Release Status: " +
                                release.ReleaseStatus(),
                                "CANCEL Release Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                            data.ClearSelection();
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show(
                            " Unknown Release: '" + releaseNode.Tag + "'",
                            "CANCEL Release Error",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Exclamation);

                        data.ClearSelection();
                        return;
                    }
                }

                data.ClearSelection();
            }
        }
示例#12
0
        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();
            }
        }
示例#13
0
        private void FireExecuteButton(object sender, EventArgs args)
        {
            ArrayList rows  = new ArrayList();
            DateTime  EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            rows.Add("Record Type,Investment,Portfolio,Strategy,Client Executing Broker,Prime Broker A/c Number,Transaction Type,Client Transaction ID,Client Asset Type,Trade Date,Contractual Settlement Date,Trade Execution Date,Broker Clearing Date,Price,Settlement Currency,Quantity,Commission Amount,Trader,Manager");

            ClientAdapterResponse response = controller.SendRpc(
                new CreateTradeBlotter(dateTimePicker.Value));

            foreach (DatabaseEngineResponse.Types.ResultSet rs in response.DatabaseResponse.ResultSetList)
            {
                foreach (DatabaseEngineResponse.Types.ResultSet.Types.Row row in rs.RowList)
                {
                    if (controller.Cache.HasInstrument(row.ColumnList[1].Value) == false)
                    {
                        MessageBox.Show("Unknown instrument_id: " + row.ColumnList[1].Value);
                        return;
                    }

                    Instrument instrument    = controller.Cache.GetInstrument(row.ColumnList[1].Value);
                    TimeSpan   ts            = TimeSpan.FromSeconds(Convert.ToDouble(row.ColumnList[6].Value));
                    DateTime   executionDate = EPOCH + ts;

                    rows.Add("N," + instrument[DatabaseObject.NAME].Substring(10) +
                             " Index,GCCG5,CCK-FT-S1,DORM,2000CAS2," +
                             com.quantmodel.common.data.DatabaseObject.SideCode(row.ColumnList[3].Value) +
                             ",CCKFT-" + row.ColumnList[0].Value +
                             ",FUT," + dateTimePicker.Value.ToString("yyyyMMdd") +
                             "," + dateTimePicker.Value.ToString("yyyyMMdd") +
                             "," + executionDate.ToString("yyyy-MM-ddTHH:mm:ss") +
                             "," + dateTimePicker.Value.ToString("yyyyMMdd") +
                             "," + row.ColumnList[4].Value +
                             ",USD," + row.ColumnList[5].Value +
                             ",1,Mark,CCK");
                }
            }

            if (rows.Count == 1)
            {
                MessageBox.Show("No records found for trade date: " + dateTimePicker.Value.ToShortDateString());
            }
            else
            {
                Stream         myStream;
                SaveFileDialog safeFileDialog = new SaveFileDialog();

                safeFileDialog.Filter           = "csv files (*.csv)|*.csv|All files (*.*)|*.*";
                safeFileDialog.FilterIndex      = 2;
                safeFileDialog.RestoreDirectory = true;

                if (safeFileDialog.ShowDialog() == DialogResult.OK)
                {
                    if ((myStream = safeFileDialog.OpenFile()) != null)
                    {
                        StreamWriter writer = new StreamWriter(myStream);

                        foreach (string row in rows)
                        {
                            writer.Write(row + "\n");
                        }

                        writer.Close();
                    }

                    this.Hide();
                    MessageBox.Show("Blotter created for trade date: " + dateTimePicker.Value.ToShortDateString());
                }
            }
        }