NexusFi: Find Your Edge


Home Menu

 





С++ API using NtDirect.dll doesn`t work


Discussion in NinjaTrader

Updated
    1. trending_up 1,930 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 2 attachments




 
Search this Thread
  #1 (permalink)
BadWood17
Moscow
 
Posts: 1 since Jun 2018
Thanks Given: 0
Thanks Received: 0

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


Attached Files
Elite Membership required to download: Test.zip
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Day 96 Missiles Hit Kuwait and Bahrain: June 15 Peace at …
Prediction Markets & Event Contracts
Kalshi Sets $4.13B All-Time Weekly Record as Polymarket …
Prediction Markets & Event Contracts
Victory Day Delivers: Russia-Ukraine Ceasefire Market Cl …
Prediction Markets & Event Contracts
The Confluence Meter: A Multi-Layered Signal Framework B …
The Elite Circle
Orban Crashes to 21pct on Record Turnout -- McIlroy Drop …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
24 thanks
2026 Jlab journal
10 thanks
Lady Vols Primer: Trading Volatility Journal
7 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,550 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,430



BadWood17 View Post
But something isn`t working.

Check that the ATI interface is enabled as well:


Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:




Last Updated on June 18, 2018


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts