Announcement

Collapse
No announcement yet.

How do I code "wait" for eSignal_OnQuoteChanged

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I code "wait" for eSignal_OnQuoteChanged

    In another thread,

    ( http://forum.esignalcentral.com/show...threadid=12467 )

    I asked how to code a "wait" for eSignal_OnQuoteChanged.

    I know how to do a sleep loop for an arbitrary amount of time, but I'd like to use something that is synchronous.

    Your help is greatly appreciated...

    Sam

  • #2
    Using a "wait"

    I use a wait in my mainline code which is posted in my event handler.

    Here is an example of the type of code I use:
    (1) In mainline code ask for information:
    bStockRequested = True ' tells event handler we are interested in handling data interrupt
    esignal.RequestSymbol(strStockSymbol, False) ' start stock and options data retrieval sequence
    If wStock.WaitOne(New TimeSpan(0, 0, 4), False) Then ' wait on event handler to finish processing RequestSymbol requests we just issued
    wStock.Reset() 'clear wait resources
    ProcessESignal() ' my routine to process data received in event handler
    Else ' did we timeout? if we did, clear wait and restart esignal
    wStock.Reset() 'clear wait
    UsernameTextBox = "your esignal logon name"
    esignal.SetApplication(UsernameTextBox)
    esignal.ReleaseSymbol(strStockSymbol) ' tell DataManager to release stock symbol storage
    End If

    (2) Receive information in event handler
    Public Sub esignal_OnQuoteUpdate(ByVal sSymbol As String) Handles esignal.OnQuoteChanged
    Dim symbolbeinghandled As String
    Dim mystep As String
    Dim index As Integer

    Dim quotes As IESignal.BasicQuote

    ' the data collected is stored in an array. The array is accessed in the mainline after we finish processing here
    InsertStock(sSymbol, index) 'returns index into array
    symbolbeinghandled = sSymbol
    laststockhandled = sSymbol

    If bStockRequested = True Then 'switch is set in mainline resquest - tells us we care about event

    quotes = esignal.GetBasicQuote(sSymbol)

    StockSingleDataFields(index, xiBid) = quotes.dBid 'stores data in an array
    StockSingleDataFields(index, xiAsk) = quotes.dAsk
    StockSingleDataFields(index, xiLast) = quotes.dLast

    ' now I go and process XML data request
    iXMLforStock(sSymbol, index) ' handle XML stock request
    esignal.ReleaseSymbol(sSymbol) ' tell DataManager to release stock symbol storage
    bStockRequested = False 'we will discard subsequent events for this stock
    wStock.Set() ' post wait which will allow mainline to continue processing
    End If

    End Sub

    Comment


    • #3
      If you would rather not put your main thread to sleep waiting for the data to come back, there are at least two other options. I use both of these in my code.

      1. Write a "QuoteManager"-type class that receives requests from the rest of your code. This class accepts an optional callback/delegate method that is called when the requested data arrives. This is the only class that actually requests data from eSignal.

      2. "Fire and Check Back Later" - make the request, and check back for the data some time later. If it's available, go ahead and do whatever you wanted to do with it. If it's not available yet, check back again later. You have to write your code in such a way that it can handle the data not being available, and know to check back later. I have code that is triggered by various timers; e.g., a every N seconds, a timer triggers execution of certain code, which checks to see if new data is available, and if so, consumes it. This code also has optional callbacks/delegate methods that can be called when the data finally arrives and is processed.

      If you're writing in C# or Java, it's easy to specify and invoke callbacks via delegates (C#) or interfaces (Java). Function pointers in C/C++ serve the same purpose. I'm sure it's also do-able in VB, but I don't know how off the top of my head.

      Here's a snippet of my C# delegate code:

      Code:
      // Definitions
      public delegate void QuoteDataHandler(object quoteManager, QuoteEventArgs eventArgs);
      public event QuoteDataHandler OnQuoteData;
      Here's another class signing up to receive events:
      Code:
      QuoteManager.getInstance().OnQuoteData += new QuoteManager.QuoteDataHandler(OnQuote);
      Back in the QuoteManager class, in code that receives data; e.g., eSignal_OnBarsChanged

      Code:
      // Let listeners know we got a new quote
      if (OnQuoteData != null) {
          quoteEventArgs.dOpen = barData.dOpen;
          quoteEventArgs.dClose = barData.dClose;
          ...
          OnQuoteData(this, quoteEventArgs);
      }

      Comment

      Working...
      X