Exemple #1
0
        private void ProcessEvent(Event evt, List <String> fields)
        {
            Invoke(new Action(() => richTextBox1.AppendText("ProcessEvent(Event, List<String>)\n")));
            const bool excludeNullElements = true;

            foreach (Bloomberglp.Blpapi.Message message in evt.GetMessages())
            {
                string security = message.TopicName;
                Invoke(new Action(() =>
                                  richTextBox1.AppendText
                                      (string.Format("GOT SECURITY: {0}",
                                                     security))));
                foreach (var field in fields)
                {
                    //This ignores the extraneous fields in the response
                    if (message.HasElement(field, excludeNullElements)) //be careful, excludeNullElements is false by default
                    {
                        Element elmField = message[field];

                        string retval = "";
                        if (security.Contains("Curncy"))
                        {
                            Invoke(new Action(() =>
                                              richTextBox1.AppendText
                                                  (string.Format("GOT CURNCY FIELD {0}\n",
                                                                 field))));

                            if (field.Equals("LAST_PRICE"))
                            {
                                Invoke(new Action(() =>
                                                  richTextBox1.AppendText
                                                      ("\nGOT CURNCY LAST_PRICE\n")));
                                retval =
                                    tc.updateCurrencyRate
                                        (security.Substring(0, 3), elmField.GetValueAsFloat64());
                            }
                        }
                        else if (field.Equals("BEST_ASK1"))
                        {
                            retval = tc.updateAsk(security, elmField.GetValueAsFloat64());
                        }
                        else if (field.Equals("BEST_BID1"))
                        {
                            retval = tc.updateBid(security, elmField.GetValueAsFloat64());
                        }
                        else if (field.Equals("BEST_ASK1_SZ"))
                        {
                            retval = tc.updateAskSize(security, elmField.GetValueAsFloat64());
                        }
                        else if (field.Equals("BEST_BID1_SZ"))
                        {
                            retval = tc.updateBidSize(security, elmField.GetValueAsFloat64());
                        }
                        Invoke(new Action(() =>
                                          richTextBox1.AppendText
                                              (string.Format("{0}",
                                                             retval))));

                        if (security.Contains("Curncy"))
                        {
                            continue;
                        }

                        Transaction transaction = tc.computeTransaction(security);
                        if (sendTransactions)
                        {
                            Invoke(new Action(() =>
                                              richTextBox1.AppendText("\nsendTransactions=true\n")));
                            if (transaction.isFeasible())
                            {
                                Invoke(new Action(() =>
                                                  richTextBox1.AppendText("\nFEASIBLE TRANSACTION!\n")));
                                sendTransaction(transaction);
                            }
                            else
                            {
                                Invoke(new Action(() =>
                                                  richTextBox1.AppendText("\nno feasible transaction\n")));
                            }
                        }
                        else
                        {
                            Invoke(new Action(() =>
                                              richTextBox1.AppendText("\nsendTransactions=false\n")));
                            Invoke(new Action(() =>
                                              richTextBox1.AppendText
                                                  (string.Format
                                                      ("-\n{0:HH:mm:ss}\nTRANSACTION\n{1}\nELEMENT FIELD (FROM API):\n{2}\n-\n",
                                                      DateTime.Now,
                                                      transaction.description,
                                                      elmField.ToString().Trim()))));
                        }
                    }
                }
            }
            Invoke(new Action(() => richTextBox1.AppendText("\n")));
        }
Exemple #2
0
 private void handleTransaction(Transaction transaction, string elmFields)
 {
     Lgr.Log("INFO", "Got element fields " + elmFields + " from API.");
     if (sendTransactions)
     {
         Invoke(new Action(() =>
           richTextBox1.AppendText("\nsendTransactions=true\n")));
         if (transaction.isFeasible())
         {
             Lgr.Log("INFO", "SEND TRANSACTIONS = TRUE, FEASIBLE TRANSACTION!!!");
             Lgr.Log("INFO", transaction.toString());
             Invoke(new Action(() =>
                 richTextBox1.AppendText("\nFEASIBLE TRANSACTION!\n")));
             sendTransaction(transaction);
         }
         else
         {
             Invoke(new Action(() =>
                 richTextBox1.AppendText("\nno feasible transaction\n")));
         }
     }
     else
     {
         if (transaction.isFeasible())
         {
             Lgr.Log("INFO", "SEND TRANSACTIONS = FALSE, FEASIBLE TRANSACTION");
             Lgr.Log("INFO", transaction.toString());
         }
         Invoke(new Action(() =>
             richTextBox1.AppendText("\nsendTransactions=false\n")));
     }
 }