EventHandler for closing Wealth-Lab
Author: mkbryan
Creation Date: 4/7/2016 9:26 PM
profile picture

mkbryan

#1
Gents,
I want my data provider, which is periodically called by a streaming strategy, to finish updating its datasource before WealthLab closes. Otherwise, if WealthLab closes/exits/shuts down while the update thread is running, the data source will become corrupted. Please note that the data provider relies on the Fidelity static provider to update the WL files using a "virtual" dataset so there's no "hook" to finish the update and release the file resources. Subsequent data source updates reveal a "key not in dictionary" exception and the appearance of a complete data source update (i.e. no information about corrupted files). The evidence of corrupted WL files is abbreviated file sizes (presumably the files were abruptly closed when WealthLab exited while the files were being written). The very time consuming fix (for a 1m dataset) is to delete the WL files and then update the dataset in the Data Manager.

From what I've learned so far, Windows.Forms issues a Form.FormClosing Event when the application exits. I want to register an event handler for the FormsClosing event when doing the datasource update. The handler will simply wait for the data source update to complete. At least that's the theory.

I believe what I now need is the delegate and event for the WealthLab/Forms closing event so I can register an event handler.

Hopefully, this is sufficient to explain the goal and motivation. I'll answer any questions you may have towards a solution.

Thanks for the help.

~Marc

profile picture

Eugene

#2
QUOTE:
Please note that the data provider relies on the Fidelity static provider to update the WL files using a "virtual" dataset

I wonder what is the point of that?
profile picture

mkbryan

#3
Hi Eugene,

The following is a brief outline.

The custom data provider creates a "proxy" from a few symbols, such that missing data (which happens with Fidelity from time to time on the S&P 500 index) can be "filled in" by the proxy. Fidelity is aware of missing data - I've dug deep with them. FYI they source their data from IDC. Fidelity has made a few fixes to historical index data, but the risk of missing index data with positions open during a trading session is very real. A few 3rd party providers have confirmed multiple minute data glitches in the S&P500 in the past two years.

The custom streaming provider, will, if it detects a missing bar, update the data source to get the most recent static data from Fidelity, and then build the proxy bars using the most recent static or streaming bars of each component of the proxy. If there's no missing bar, then the proxy is built entirely from streaming bars (via the GOP).

So, while the streaming strategy is in Execute(), the proxy provider may perform an UpdateDataSource() - in a separate thread to avoid thread abort. And this works well so far.

The remaining issue is exiting WealthLab before the UpdateDataSource() has finished.

Let me know if you want any further clarification. I look forward to your suggestion(s) of a solution.

Thanks.

~Marc

profile picture

Eugene

#4
Hi Marc,

Thank you for explaining it to me. For Wealth-Lab close/exit/shut down I'd use Application.ApplicationExit.
profile picture

mkbryan

#5
Hi Eugene,

A simple event handler for Application.ApplicationExit seems to do the trick - at least with some test code. Thanks for the help.

~Marc
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).