Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 rtwave, Today, 01:49 PM
    0 responses
    8 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Started by papaoutai, Today, 08:56 AM
    0 responses
    22 views
    0 likes
    Last Post papaoutai  
    Started by jdspwe, Today, 05:22 AM
    0 responses
    13 views
    0 likes
    Last Post jdspwe
    by jdspwe
     
    Started by JeremuFemstu, Today, 04:49 AM
    0 responses
    16 views
    0 likes
    Last Post JeremuFemstu  
    Started by pjsmith, Today, 04:11 AM
    1 response
    22 views
    0 likes
    Last Post Green Lobster CBD  
    Working...
    X