• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

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

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

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

    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
    Last edited by badwood; 06-18-2018, 02:25 PM.

    #2
    Hello badwood,

    Thank you for the post and welcome to the NinjaTrader forum.

    We are unable to support any external applications, but you may read this post that gives an overview of how to use the DLL interface. The examples are written in C# but it should help nonetheless.

    https://ninjatrader.com/support/foru...442#post514442

    If we may be of any further assistance, please let us know.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by xsgex, Yesterday, 09:46 PM
    0 responses
    2 views
    0 likes
    Last Post xsgex
    by xsgex
     
    Started by Steve L, Yesterday, 09:36 PM
    0 responses
    1 view
    0 likes
    Last Post Steve L
    by Steve L
     
    Started by krugman25, Yesterday, 09:34 PM
    0 responses
    4 views
    0 likes
    Last Post krugman25  
    Started by indy73, Yesterday, 04:42 PM
    0 responses
    15 views
    0 likes
    Last Post indy73
    by indy73
     
    Started by Italianforex, Yesterday, 06:20 AM
    2 responses
    13 views
    0 likes
    Last Post gplatis
    by gplatis
     
    Working...
    X