Exemplo n.º 1
0
        private void buttonDeleteBook_Click(object sender, EventArgs e)
        {
            if (buttonDeleteBook.Text == ButtonDeleteBook_Normal)
            {   // We are in the normal state.
                buttonDeleteBook.Text = ButtonDeleteBook_Confirm;
            }
            else if (buttonDeleteBook.Text == ButtonDeleteBook_Confirm)
            {   // User has just confirmed the delete request.
                // Submit the delete request

                if (Log != null)
                {
                    if (m_FillHub == null)
                    {
                        Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major, "FormAddFill.buttonDeleteBook_Click: FillHub is null!");
                        buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                        return;
                    }
                    else if (m_CurrentInstrument == null || m_CurrentInstrument == m_EmptyInstrument)
                    {
                        Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major, "FormAddFill.buttonDeleteBook_Click: CurrentInsrument is null!");
                        buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                        return;
                    }
                    //else if (m_CurrentInstrument.ForeignKey == null)
                    //{
                    //    Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major,"FormAddFill.buttonDeleteBook_Click: CurrentInsrument.ForeignKey is null!");
                    //    buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                    //    return;
                    //}
                    Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major, "FormAddFill.buttonDeleteBook_Click: Request delete for {0} in FillHub {1}.", m_CurrentInstrument, m_FillHub.Name);
                }
                Misty.Lib.OrderHubs.OrderHubRequest request = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestDeleteBook);
                //TradingTechnologies.TTAPI.InstrumentKey instrKey = (TradingTechnologies.TTAPI.InstrumentKey)m_CurrentInstrument.ForeignKey;
                //request.Data = new object[1] { instrKey };
                request.Data = new object[1] {
                    m_CurrentInstrument
                };
                m_FillHub.Request(request);
                buttonDeleteBook.Text = ButtonDeleteBook_Normal;
            }
        }//
Exemplo n.º 2
0
        private void buttonDeleteBook_Click(object sender, EventArgs e)
        {
            if (buttonDeleteBook.Text == ButtonDeleteBook_Normal)
            {   // We are in the normal state.
                buttonDeleteBook.Text = ButtonDeleteBook_Confirm;
            }
            else if (buttonDeleteBook.Text == ButtonDeleteBook_Confirm)
            {   // User has just confirmed the delete request.
                // Submit the delete request

                if (Log != null)
                {
                    if (m_FillHub == null)
                    {
                        Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major, "FormAddFill.buttonDeleteBook_Click: FillHub is null!");
                        buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                        return;
                    }
                    else if (m_CurrentInstrument == null || m_CurrentInstrument == m_EmptyInstrument)
                    {
                        Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major, "FormAddFill.buttonDeleteBook_Click: CurrentInsrument is null!");
                        buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                        return;
                    }
                    //else if (m_CurrentInstrument.ForeignKey == null)
                    //{
                    //    Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major,"FormAddFill.buttonDeleteBook_Click: CurrentInsrument.ForeignKey is null!");
                    //    buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                    //    return;
                    //}
                    Log.NewEntry(Misty.Lib.Hubs.LogLevel.Major, "FormAddFill.buttonDeleteBook_Click: Request delete for {0} in FillHub {1}.", m_CurrentInstrument, m_FillHub.Name);
                }

                // Try to read the required values like realized PnL, average cost, net position.
                IFillBook book;
                if (m_FillHub.TryEnterReadBook(m_CurrentInstrument, out book))
                {
                    Log.NewEntry(LogLevel.Major, "The deleted book contains net pos:{0}, real PnL:{1}, start real PnL:{2}, avg price:{3}, currency name:{4}, currency rate:{5}.",
                                 book.NetPosition, book.RealizedDollarGains, book.RealizedStartingDollarGains, book.AveragePrice, book.CurrencyName, book.CurrencyRate);

                    double netPosition      = book.NetPosition;
                    double realizedPnL      = book.RealizedDollarGains;
                    double startRealizedPnL = book.RealizedStartingDollarGains;
                    double avgPrice         = book.AveragePrice;
                    string currencyName     = book.CurrencyName;
                    double currencyRate     = book.CurrencyRate;
                    m_FillHub.ExitReadBook(m_CurrentInstrument);
                    double settlementValue = double.NaN;

                    // Find the instrument detail for this instrument and load the cash book accordingly.
                    //TradingTechnologies.TTAPI.InstrumentDetails instrDetail;
                    //if (!m_Market.TryLookupInstrumentDetails(m_CurrentInstrument, out instrDetail))
                    //{
                    //    Log.NewEntry(LogLevel.Warning, "No instrument detail is found for {0}", m_CurrentInstrument);
                    //    return;
                    //}

                    if (netPosition != 0)
                    {
                        // Request the user to input a settlement value to calculate the PnL.
                        string input = string.Empty;
                        while (!double.TryParse(input, out settlementValue) && settlementValue != double.NaN)
                        {
                            input = Microsoft.VisualBasic.Interaction.InputBox("Please input the settlement price. Input nothing to exit.",
                                                                               "Request settlement price", avgPrice.ToString(), 450, 450);

                            if (string.IsNullOrEmpty(input))
                            {
                                return;
                            }
                        }

                        // Calculate the PnL by the settlement price.
                        realizedPnL += (settlementValue - avgPrice) * netPosition * book.DollarPerPoint;
                    }

                    // Ask the user whether he likes to transfer the PnL to the corresponding cash instrument.
                    DialogResult result = MessageBox.Show(string.Format("I am going to transfer {0} ammount of PnL in currency {1} to the cash instrument",
                                                                        startRealizedPnL + realizedPnL, currencyName), "PnL transfer to cash instrument", MessageBoxButtons.YesNo);

                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        // Get the cash book according to the instrument detail.
                        Product        product      = new Product("Cash", currencyName, ProductTypes.Cash, "");
                        InstrumentName newCashInstr = new InstrumentName(product, "");

                        Log.NewEntry(LogLevel.Minor, "Send request to create/update cash book.");
                        Misty.Lib.OrderHubs.OrderHubRequest cashBookCreateRequest = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestCreateUpdateCashBook);
                        cashBookCreateRequest.Data = new object[5] {
                            newCashInstr,
                            currencyName,
                            currencyRate,
                            realizedPnL,
                            startRealizedPnL
                        };
                        m_FillHub.Request(cashBookCreateRequest);

                        Misty.Lib.OrderHubs.OrderHubRequest instrumentDeleteRequest = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestDeleteBook);
                        //TradingTechnologies.TTAPI.InstrumentKey instrKey = (TradingTechnologies.TTAPI.InstrumentKey)m_CurrentInstrument.ForeignKey;
                        //request.Data = new object[1] { instrKey };
                        Log.NewEntry(LogLevel.Minor, "Send request to delete fill book.");
                        instrumentDeleteRequest.Data = new object[1] {
                            m_CurrentInstrument
                        };
                        m_FillHub.Request(instrumentDeleteRequest);
                        buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                    }
                    else
                    {
                        buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                    }
                }
                else
                {
                    Log.NewEntry(LogLevel.Warning, "FormAddFill.buttonDeleteBook_Click:No instrument key found for {0}", m_CurrentInstrument);
                    buttonDeleteBook.Text = ButtonDeleteBook_Normal;
                }

                //Misty.Lib.OrderHubs.OrderHubRequest request = new Misty.Lib.OrderHubs.OrderHubRequest(Misty.Lib.OrderHubs.OrderHubRequest.RequestType.RequestDeleteBook);
                ////TradingTechnologies.TTAPI.InstrumentKey instrKey = (TradingTechnologies.TTAPI.InstrumentKey)m_CurrentInstrument.ForeignKey;
                ////request.Data = new object[1] { instrKey };
                //request.Data = new object[1] { m_CurrentInstrument };
                //m_FillHub.Request(request);
                //buttonDeleteBook.Text = ButtonDeleteBook_Normal;
            }
        }//