Programming A CMS Forex Broker Adapter in Wealth Lab Developer 3.0 - Part 1
Posted in Forex Trading, Auto Execution on March 30th, 2006To say I’ve had fun over the last couple of days since my crazy expedition to create a Wealth Lab broker adapter fit for trading on CMS is an understatement.
It’s been nothing short of frustrating!
Especially since I’ve never done programming on this level before - just a little bit of VBA.
But… we all need to start somewhere, and I’m a firm believer that if you REALLY want to learn something you either teach it or do something with an intended goal in mind.
At the moment it’s the latter: building a WLD CMS broker adapter.
Okay, here’s what I’ve learnt if you’re interested in doing this yourself or just waiting for me to pass out. Either way by writing this out it in here it allows some of my sanity to return!
Firstly, I can’t get Visual Basic’s 2005 Express Edition to create a foundational WLD broker script. But creating a script in Visual C# 2005 Express Edition was a breeze, and I think it has to do with one small tweak you need to do in VC# that, for the life of me, I cannot find in VB.
But firstly, here are the testing scripts just to make sure we’ve laid the correct foundation:
To create a project in either of them you just click on File > New Project > Class Library > Enter a class name such as VTAPI and then hit OK.
Copy all of the following code into the VB script that opens (copy it over everything).
Now what you’ll need to do is import the WLD COM object and this is done by clicking on Project > Add Reference > COM > select WealthLab Library 1.0 > click OK.
Lastly you’ll need to click on Project > VTAPI Properties… > Assembly Information > select “Make assembly COM-Visible > click OK.
Click on the Save All button (which is the button with three floppy disks - to the right of the normal save button) and save it as “VTAPI”. After when that is done click on Build > Build VTAPI and a dll file has now been created.
Was that easy or what?
Well… not so fast, if you can remember I said that the VB script doesn’t work. We can check that in WLD now, but first we need to create a file so that WLD knows where to look for our dll file.
We do this by simply creating the following file:
(change the path to wherever you stored the dll file, most people using Windows XP will only need to change the “@@@@@@” section in that file to their Windows XP username)
Save this file in the root directory of your Wealth-Lab Developer folder, for most people this will be c:\Program Files\Wealth-Lab, Inc\Wealth-Lab Developer 3.0\ and save it as BrokerAdapter_CMS.txt (this is important).
Crank up Wealth-Lab click on Order Manager make sure CMS Forex is selected and then click on Broker Login.
Hopefully (or should that be unfortunately?) you’ll come across an error message box that says:
System error. Code: 203.
The system could not find the environment option that was entered
(If you get an error message that says something to the effect of “The specified module could not be found…” it means that you’ll need to open the BrokerAdapter_CMS.txt file up and check that the path you’ve entered is indeed the path that leads to the dll file in the VTAPI/Release folder, if not change it accordingly.)
I have no idea what that error box means, but it’s not good because our adapter didn’t work. After trying a million different things such as regasm (etc) I still couldn’t get it to work.
Thankfully I had VC# installed… and it is here where we DO get the broker adapter to work.
Here’s the process:
Firstly, crank up the program, click on File > New Project > Class Library > Enter a name such as CMSAPI and then hit OK.
Copy all of the following code into the script window that opens - copy it over everything.
As we did for the VB script we’ll need to change some of the settings.
Click on Project > Add Reference… > COM > select WealthLab Library 1.0 > click OK.
Click on Project (again) > CMSAPI Properties > Assembly Information… > select “Make assembly COM-Visible” > click OK
After when you’ve clicked OK click on Build (underneath Application with the active window) then select Register for COM Interop.
Click on the Save All button and save it as CMSAPI and lastly click on the Build menu selection (up the top) > Build Solution.
Still with me?
Alright, we now need to create that file for Wealth-Lab. Which you can find one here, but again you’ll need to change it so that it points to the dll file you just created and make sure you save it as BrokerAdapter_CMSVC.txt (this is important).
Now for the test.
Open up Wealth-Lab, click on Order Manager, change the selection so that it points to CMS VC# and hit the Broker Login button.
Hopefully you should see the words “Connected” in the lower left hand panel with the balances of Cash $1,000.00 and Buying Power $999.00.
Woohoo!
In the next post we’ll connect to the Visual Trading API and get this thing really cooking!
(PS - does anybody know why the VB script won’t work? If anybody can get it to work I’d love to know how.)