VB.net programming error

Discussion in 'Automated Trading' started by WhiteOut56, May 10, 2011.

  1. Program VB.net

    OnQuoteUpdate()
    {

    line1
    line2
    line3
    line4

    }

    ---- what I've noticed that happens is that the program will sometimes overlap calls.

    Normally when you receive an update from the quote, it will go through all 4 lines of code before another update is called. But every once in a while I will get the calls to overlap, where...

    I get a call in OnQuoteUpdate, and before it finishes executing line4 for that current call, it'll execute line1 from another call in OnQuoteUpdate()

    Is there a way to prevent this?

    I'm using VB.net 2005, sterling.
     
  2. that's classic synchronization issue, as streaming tickers will call onQuoteUpdate() as soon as they come in even if the previous ticker thread hasnt finished yet.

    I am not familiar with microsoft crap but believe the syntax are as follows to make the function thread safe in vb.

    OnQuoteUpdate()
    {
    SyncLock locker
    line1
    line2
    line3
    line4
    End SyncLock
    }

    http://www.java2s.com/Code/VB/Thread/TwothreadswithSyncLock.htm

    Keep in mind if OnQuoteUpdate() performance is slow, the tickers will then get queued up waiting for the previous to finish, and over time your system will be using stale price quotes = death. You probably want to have some logic in place to discard the previous prices that are waiting in queue when the newest one comes in.
     
  3. Wow!!!!
    If this works, I owe you the world

    I never knew of this functionalitiy

    Thank you!!!!!
     
  4. nielsb

    nielsb

    I believe the syntax in VB.NET would be the same as in C#, the locker is just an object you have declared in class scope:


    OnQuoteUpdate()
    {
    lock(locker)
    {
    line1
    line2
    line3
    line4
    }
    }

    Hope this helps
    Niels
     
  5. I'm thinking about moving a lot of things to Sterling and I did not know about this problem. How exactly does Sterling's threading model work where this is even a possibility that you can get events like the OP is talking about?
     
  6. nielsb

    nielsb

    This has nothing to do with Sterling's threading model. It is how we are handling data coming into our app.

    Niels
     
  7. The problem has nothing to do with
    - programming language
    - API used


    It is a basic problem that arises when a program processes realtime data.
    When data is arriving in a fast sequence and the quote event did not exit in time (which it is supposed to do) this leads to the overlap.

    Probably your program does some time intensive computations or other actions (like disk or screen i/o, calling external programs) within the quote event.

    In the quote event there should be done only something like saving the data to an array for further processing elsewhere (in a not time critical part of the program).


    The approach that was suggested (using SyncLock) might lead to
    - data loss
    - crash of the program
     
  8. LeeD

    LeeD

  9. Give me a break, there is nothing wrong with processing your logic directly in the quote(or a function call within the quote) instead of creating additional overhead by saving it to some in-memory data structure then having another process read from there. The precursor obviously is the processing needs to be fast (on par with the streaming quotes) and a mechanism to be in place to catch up if falling behind, which i already mentioned to the OP. A lot of it depends on how your strategy uses the data, whether you action based on tick or min price movements etc..

    Nothing wrong with data loss, it's a standard part of exception handling.

    And if it leads to program crash, that just means you are a crappy programmer.
     
  10. No comment needed.

    To OP: Please build your own opinion based on this statement.


    Leaving this thread.
     
    #10     May 12, 2011