ANVIL API (Assent) Developer Thread

Quote from RedRat:

There is a function
void WINAPI InitializeAnvilExtension()

and I call here:
if ( !g_pMainDlg )
{
Observable* account = B_GetCurrentAccount();
const char* accountName = B_GetAccountName(account);
CWnd* mainWnd = AfxGetMainWnd();

g_pMainDlg = new TraderDlg( account, mainWnd );
g_pMainDlg->Create(IDD_TRADER, mainWnd);
}


So I think I am creating my dialog from Anvil thread. And as it is modeless dialog then it has its own thread.


Anvil example does not have my error because it does not process timer in child dialog. They process message OnOK() and then place orders. It seems OnOK() is running in a separate thread, don't know why there is no problem. I have to spend more time studying Anvil examples :(.

Everybody thank you a lot for help!

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.
 
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.
 
Quote from caementarius:

Is there a bridge between OpenQuant or any of the retail strategy development platforms and the Anvil API?

I never worked with openquant but I am sure one can be built if there is none.
 
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>
 
Quote from ctarmor-et:

I never worked with openquant but I am sure one can be built if there is none.

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.
 
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?
 
Quote from tfjield:
Nope, not me.

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.
 
Back
Top