Page 1 of 1

Using TWSLink with NinjaTrader

Posted: Thu Sep 14, 2017 11:41 pm
by Casey
I added TWSLink2.dll as a reference in the NinjaTrader code editor and it gave me the following error:

NinjaScript File Error Code Line Column
<None> Metadata file 'c:\Windows\SysWOW64\twslink2.dll' could not be opened -- 'An attempt was made to load a program with an incorrect format. ' CS0009 0 0

Re: Using TWSLink with NinjaTrader

Posted: Fri Sep 15, 2017 3:08 pm
by board_admin
Hello,
i am not familar with NinjaTrader. From what i read on NinjaTrader website, it is based on .NET.
So they expect a .Net assembly DLL not a win32 DLL.

.Net is so called managed code and promoted by Microsoft and intended to make applications more safe and robust.
.Net finally make calls into the win32 API.

TWSLink is a classic win32 API DLL and unmanaged code. In some .Net environments it is possible to call unmanaged code.
We have some C#, VB.Net examples for TWSLink.

https://trade-commander.com/public-downloads/

One project is a .NET assembly which finally uses TWSLink. Perhaps it works when you add this assembly as reference.
(You can build and run all with the Free MS Visual Studio (2017) community edition.)

But it all depends on the possibility by NT to make calls into unmanaged code at all. I can't say this, but may MT support or a guru in their forum.

Re: Using TWSLink with NinjaTrader

Posted: Sat Sep 16, 2017 12:47 am
by Casey
I haven't tested thoroughly, but it appears that importing the DLL will work with NinjaTrader.

e.g.
[DllImport("twslink2.dll")]
public static extern int REGISTER_CONTRACT(string underlying, string sectype, string currency, string exchange, string primexchange, string expiry, string right, double strike, string multiplier, int expired, double mintick);