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).
/* 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; }
Comment