I'm getting closer and closer to having my application working in a threaded environment. I am however getting stumped on a few things. 1. For the main thread, are you creating it using AfxBeginThread or are you considering the hook into Anvil as being your main thread? The reason I'm asking this is because I was thinking of creating a thread after I hooked into Anvil so that I could control how many messages could be put on the stack. I'm not sure if this will work though. 2. After my worker thread decides that an order needs to be placed it posts a message to the main thread to place the order. Then I am trying to identify how I can notify the worker thread once a position has been obtained. The way I used to do this is by processing the heartbeat message and everytime I received the heartbeat message I made a call to see if I had obtained a position yet. Do you know if there is any other way to be notified that the order has been filled and a position has been obtained? Thanks for all the help!!
Hi, I am getting error while debugging. I have one dialog and single thread so I am completely confused about this error. Is anybody experienced the same? RR
There are multiple ways of addressing it. 1) I use _beginthread() and the crt fucntions. 2) Here is where it gets hard to explain. This is how I did it ... Account has a messags POSITON_NEW (or somethign like it). This get received with a Position*. Once I get this message, the Position* is mainly static. Meaning that ANVIL use this same object to manage the status for the equity. I take that pointer and keep it in the my stock obsearvable. Now, it all depends how much performance you want. For example, lets say you need each print to be processed to maintain avgs, signal, engine , etc... You do all this work on the worker thread. Lets say you ahve a class called CPrintUpdate: CPrintUpdate { Money m_Bid; Money m_Ask; Money m_Last; int m_Size; }; On the m_LAST_SHORT_TRADE (I thisn this is the name) you populate this class and send it off to your worker thread. You will get the current position from Position*->GetSize() (I think thats the name). Your worker thread does the avgs, etc. Now it needs to decide if it can send a trade signal. You can say "If m_Size == 0 then send signal". You may have small gap in time where your positon may be already be liquidated while your worker thread processed the update. It all depends on your model. Alternatibly you can let the worker thread produce it signals and send them to the main thread. On your main thread, you can check for the position before placing the order. If already in a position, or there are any pending orders, then ignore the signal. Again, it all depends on your model and how many signals you are producing. I would staty away form the heartbeat in this case. It can cause you be out of sync and place multiple orders to increase your position ... I hope this helps ...
I am running my debug version DLL. In my previous version I did not expect such an error. Unfortunately I do not remember all my changes. But for example I added 1 sec timer within my dialog InitDialog() and on each timeout I call functions B_GetLastTrade() B_GetClosePrice() If I remove these calls then I receive the same error a bit later, may be on 2 min timer - have to check myself.
I want to make sure that we're talking about the same thing. The thread that makes all of the B_ calls needs to be the hook into Anvil. You can create another thread for order management, housekeeping, whatever, but you need to post into Anvil's GUI thread for making all B_ calls, or you will run into problems.
You are right, I copied my functionality from Anvil example void WINAPI InitializeAnvilExtension() { // g_pMainDlg = new TraderDlg( account, mainWnd ); g_pMainDlg->Create(IDD_TRADER, mainWnd); // } I thought I am creating Modal dialog, but it is modeless indeed . I will think on how to restructure my application. Thank you a lot!