Using TWSLink with NinjaTrader

Discuss, post your questions about TWSLink here.

Users who just registered, please write an email to
with your username mentioned.
So we can distinguish you from bots.
Thank you
Post Reply
Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Using TWSLink with NinjaTrader

Post by Casey » Thu Sep 14, 2017 11:41 pm

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

Site Admin
Posts: 174
Joined: Mon Apr 24, 2017 3:24 pm

Re: Using TWSLink with NinjaTrader

Post by board_admin » Fri Sep 15, 2017 3:08 pm

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.

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.

Posts: 10
Joined: Thu Sep 14, 2017 8:19 pm

Re: Using TWSLink with NinjaTrader

Post by Casey » Sat Sep 16, 2017 12:47 am

I haven't tested thoroughly, but it appears that importing the DLL will work with NinjaTrader.

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);

Post Reply