Trading Articles
Article Categories
Article Tools
С++ API using NtDirect.dll doesn`t work
Updated June 18, 2018
trending_up
668 views
thumb_up
1 thanks given
group
2 followers
forum
2 posts
attach_file
2 attachments
Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free and simple.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
С++ API using NtDirect.dll doesn`t work
(login for full post details)
#1 (permalink )
Moscow
Posts: 1 since Jun 2018
Thanks: 0 given,
0
received
Good day!
I`m trying to make an application in C++ something like API, working with Ninja Trader 8, using NtDirect.dll, where all c++ functions are realised.
I wrote code, which is very similar with code of API in C#.
To work with functions from NtDirect.dll i explicit link it and get all functions i need.
But something isn`t working.
For example, i made a function, which is called MarketData (it`s supposed to get the last price of the instrument). But when i try to use it, it returns 0 but not the prize.
Everything is fine, everything compile, no it doesn`t throw any exception, but the program still doesn`t give me right numbers.
Please, help me to make this code work (return right numbers).
Code
/* Fields in my class:
typedef int(*command_func)(string command, string account, string instrument, string action, int quantity, string orderType, double limitPrice, double stopPrice,
string timeInForce, string oco, string orderId, string strategy, string strategyId);
typedef int(*connected_func)(int showMessage);
typedef int(*subscribe_market_data_func)(string instrument);
typedef int(*unsubscribe_market_data_func)(string instrument);
typedef double(*market_data_func)(string instrument, int zero);
typedef int(*tear_down_func)();
tear_down_func TearDown;
connected_func Connected;
command_func Command;
subscribe_market_data_func SubscribeMarketData;
unsubscribe_market_data_func UnsubscribeMarketData;
market_data_func MarketData;
*/
void ClientClass::LoadDLL()
{
HMODULE nt_lib;
nt_lib = LoadLibrary(L"NtDirect.dll");
if (nt_lib == NULL)
{
throw exception("Couldn`t load dll. Error code : ");
}
Command = (command_func)GetProcAddress(nt_lib, "Command");
if (!Command)
{
throw exception("Couldn`t load dll`s function (Command). Error code :");
}
Connected = (connected_func)GetProcAddress(nt_lib, "Connected");
if (!Connected)
{
throw exception("Couldn`t load dll`s function (Connected). Error code : ");
}
SubscribeMarketData = (subscribe_market_data_func)GetProcAddress(nt_lib, "SubscribeMarketData");
if (!SubscribeMarketData)
{
throw exception("Couldn`t load dll`s function (SubscribeMarketData). Error code : ");
}
MarketData = (market_data_func)GetProcAddress(nt_lib, "MarketData");
if (!MarketData)
{
throw exception("Couldn`t load dll`s function (MarketData). Error code : ");
}
UnsubscribeMarketData = (unsubscribe_market_data_func)GetProcAddress(nt_lib, "UnsubscribeMarketData");
if (!SubscribeMarketData)
{
throw exception("Couldn`t load dll`s function (UnSubscribeMarketData). Error code : ");
}
TearDown = (tear_down_func)GetProcAddress(nt_lib, "TearDown");
if (!TearDown)
{
throw exception("Couldn`t load dll`s function (TearDown). Error code : ");
}
int connected = Connected(1);
if (connected)
throw exception("Error with function Connected. Error code :");
}
.....
//This function must return the last prize
double ClientClass::GetInstrument(string instrument)
{
int connect = Connected(1);
if(connect)
throw exception("Error with function Connected. Error code :");
int subscribe = SubscribeMarketData(instrument);
if (subscribe)
throw exception("Error with function SubscribeMarketData. Error code :");
/* Отладочная печать, она не нужна.
printf("Connected %d \n", connected);
printf("Subscribe %d \n", subscribe);
printf("Unsubscribe %d \n", unsubscribe);
*/
double lastPrice = MarketData(instrument, 0);
int unsubscribe = UnsubscribeMarketData(instrument);
if (unsubscribe)
throw exception("Error with function UnsubscribeMarketData. Error code :");
return lastPrice;
}
Best Threads (Most Thanked) in the last 7 days on futures io
(login for full post details)
#3 (permalink )
Birmingham UK
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,651 since Dec 2012
Thanks: 17,422 given,
8,403
received
BadWood17
But something isn`t working.
Check that the ATI interface is enabled as well:
The following user says Thank You to ratfink for this post:
Last Updated on June 18, 2018
Right now
Ongoing
Right now
April
Register to Attend
Elite only