ANVIL API (Assent) Developer Thread

Discussion in 'Trading Software' started by ctarmor-et, Dec 10, 2007.

  1. I can see the MFC timer coming from a diff thread.

    But the dlg msg pump is the same as the ANVIL main GUI thread. Debug the ::GetCurrentThreadID() on the OnOK() call. See if it is the same. Im my codebase is the same thread.
     
    #151     Jul 1, 2008
  2. tfjield

    tfjield

    Using the code you provided, the dialog thread should be the same as the parent, even though it's non-modal. Create does not create a new thread. Don't get the MFC Create confused with the API call.

    Now the timer callback could be coming from another thread... I'm not 100% sure in this case.
     
    #152     Jul 1, 2008
  3. Is there a bridge between OpenQuant or any of the retail strategy development platforms and the Anvil API?
     
    #153     Jul 2, 2008
  4. I never worked with openquant but I am sure one can be built if there is none.
     
    #154     Jul 2, 2008
  5. I seen many post about having a timer on ANVIL. Here is a simple way of having a timer

    in Anvil without having to worry about multi-threading.

    You need to add an observable to <I>B_GetAdminObservable()</I>. On the <i>Process()</i>

    handle monitor the M_HEARTBEAT message. Check some timer object for interval and

    perform your operationat the specified time.

    Here is some sample code.&nbsp;&nbsp;&nbsp;&nbsp;

    <i>
    void CObserver::process(const Message* message, Observable* from, const Message* additionalInfo)
    {
    &nbsp;&nbsp;&nbsp;&nbsp;static CTimer _Timer(60000);

    &nbsp;&nbsp;&nbsp;&nbsp;switch(message->GetType())
    &nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;case M_HEARTBEAT:
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Timer Check
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( _Timer.TimeToRun() )
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Do your thing here
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
    &nbsp;&nbsp;&nbsp;&nbsp;}
    }
    </i>



    The Timer class here:


    <i>
    class CTimer
    {
    public:
    &nbsp;&nbsp;&nbsp;&nbsp;CTimer(DWORD dIntervalMs, DWORD dLastTriggeredMs = 0)
    &nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_IntervalMs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= dIntervalMs;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_LastTriggeredMs = dLastTriggeredMs;
    &nbsp;&nbsp;&nbsp;&nbsp;}

    &nbsp;&nbsp;&nbsp;&nbsp;bool TimeToRun()
    &nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( :):GetTickCount() - m_LastTriggeredMs) > m_IntervalMs )
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_LastTriggeredMs = ::GetTickCount();
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_bDidItRun = true;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;
    &nbsp;&nbsp;&nbsp;&nbsp;}


    private:
    &nbsp;&nbsp;&nbsp;&nbsp;DWORD m_IntervalMs;
    &nbsp;&nbsp;&nbsp;&nbsp;DWORD m_LastTriggeredMs;
    };
    </i>
     
    #155     Jul 6, 2008
  6. FYI I learned that OpenQuant uses QuickFIX to connect to a trading technologies FIX adapter and others have been able to use that as an example to make their own FIX implementation. So, I believe it's doable but will require some elbow grease on my part.
     
    #156     Jul 6, 2008
  7. ootbt08

    ootbt08

    One thing I learned with using the M_HEARTBEAT message is that if you are running a black box over the internet then this message usually arrives but there are times when a heartbeat message is missed. I had to add special coding into my app to account for times when this message was missed.

    Does anyone know what the purpose of the IdleObserver is?
     
    #157     Jul 9, 2008
  8. tfjield

    tfjield

    Nope, not me.
     
    #158     Jul 9, 2008
  9. Never used it ... sorry
     
    #159     Jul 9, 2008
  10. ootbt08

    ootbt08

    Okay, thanks! I saw that it was being used in the Trader example and included it into my app. It was sending lots of messages and I think that is why my app kept choking.

    Now I have finally got my threaded app working and I removed this observer and it is working much better. It still doesn't process as many symbols as I would like but I'm also running the black box over the internet which is not a good setup. Hopefully once I get a machine setup at Assent I'll be able to process much more.

    Thanks to all of you for your help with this! I couldn't have done it without you!!

    When I get a free moment I will remove all of the logic from my program and post it so that others have a threaded example to look at.
     
    #160     Jul 9, 2008